1 /*****************************************************************************
3 * check_cluster.c - Host and Service Cluster Plugin for Nagios 2.x
6 * Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)
7 * Copyright (c) 2007 Nagios Plugins Development Team
9 * Last Modified: $Date$
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 *****************************************************************************/
29 const char *progname
= "check_cluster";
30 const char *revision
= "$Revision$";
31 const char *copyright
= "2000-2007";
32 const char *email
= "nagiosplug-devel@lists.sourceforge.net";
36 #include "utils_base.h"
38 #define CHECK_SERVICES 1
41 void print_help (void);
42 void print_usage (void);
44 int total_services_ok
=0;
45 int total_services_warning
=0;
46 int total_services_unknown
=0;
47 int total_services_critical
=0;
50 int total_hosts_down
=0;
51 int total_hosts_unreachable
=0;
56 int check_type
=CHECK_SERVICES
;
63 int process_arguments(int,char **);
67 int main(int argc
, char **argv
){
70 int return_code
=STATE_OK
;
71 thresholds
*thresholds
= NULL
;
73 setlocale (LC_ALL
, "");
74 bindtextdomain (PACKAGE
, LOCALEDIR
);
77 if(process_arguments(argc
,argv
)==ERROR
)
78 usage(_("Could not parse arguments"));
80 /* Initialize the thresholds */
81 set_thresholds(&thresholds
, warn_threshold
, crit_threshold
);
83 print_thresholds("check_cluster", thresholds
);
85 /* check the data values */
86 for(ptr
=strtok(data_vals
,",");ptr
!=NULL
;ptr
=strtok(NULL
,",")){
90 if(check_type
==CHECK_SERVICES
){
96 total_services_warning
++;
99 total_services_critical
++;
102 total_services_unknown
++;
117 total_hosts_unreachable
++;
126 /* return the status of the cluster */
127 if(check_type
==CHECK_SERVICES
){
128 return_code
=get_status(total_services_warning
+total_services_unknown
+total_services_critical
, thresholds
);
129 printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n",
130 state_text(return_code
), (label
==NULL
)?"Service cluster":label
,
131 total_services_ok
,total_services_warning
,
132 total_services_unknown
,total_services_critical
);
135 return_code
=get_status(total_hosts_down
+total_hosts_unreachable
, thresholds
);
136 printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n",
137 state_text(return_code
), (label
==NULL
)?"Host cluster":label
,
138 total_hosts_up
,total_hosts_down
,total_hosts_unreachable
);
146 int process_arguments(int argc
, char **argv
){
149 static struct option longopts
[]={
150 {"data", required_argument
,0,'d'},
151 {"warning", required_argument
,0,'w'},
152 {"critical", required_argument
,0,'c'},
153 {"label", required_argument
,0,'l'},
154 {"host", no_argument
, 0,'h'},
155 {"service", no_argument
, 0,'s'},
156 {"verbose", no_argument
, 0,'v'},
157 {"version", no_argument
, 0,'V'},
158 {"help", no_argument
, 0,'H'},
162 /* no options were supplied */
168 c
=getopt_long(argc
,argv
,"hHsvVw:c:d:l:",longopts
,&option
);
170 if(c
==-1 || c
==EOF
|| c
==1)
175 case 'h': /* host cluster */
176 check_type
=CHECK_HOSTS
;
179 case 's': /* service cluster */
180 check_type
=CHECK_SERVICES
;
183 case 'w': /* warning threshold */
184 warn_threshold
= strdup(optarg
);
187 case 'c': /* warning threshold */
188 crit_threshold
= strdup(optarg
);
191 case 'd': /* data values */
192 data_vals
=(char *)strdup(optarg
);
195 case 'l': /* text label */
196 label
=(char *)strdup(optarg
);
199 case 'v': /* verbose */
203 case 'V': /* version */
204 print_revision (progname
, revision
);
228 print_revision(progname
, revision
);
229 printf ("Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)\n");
230 printf(COPYRIGHT
, copyright
, email
);
232 printf(_("Host/Service Cluster Plugin for Nagios 2"));
238 printf("%s\n", _("Options:"));
239 printf (" %s\n", "-s, --service");
240 printf (" %s\n", _("Check service cluster status"));
241 printf (" %s\n", "-h, --host");
242 printf (" %s\n", _("Check host cluster status"));
243 printf (" %s\n", "-l, --label=STRING");
244 printf (" %s\n", _("Optional prepended text output (i.e. \"Host cluster\")"));
245 printf (" %s\n", "-w, --warning=THRESHOLD");
246 printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
247 printf (" %s\n", _("non-OK state in order to return a WARNING status level"));
248 printf (" %s\n", "-c, --critical=THRESHOLD");
249 printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
250 printf (" %s\n", _("non-OK state in order to return a CRITICAL status level"));
251 printf (" %s\n", "-d, --data=LIST");
252 printf (" %s\n", _("The status codes of the hosts or services in the cluster, separated by"));
253 printf (" %s\n", _("commas"));
255 printf(_(UT_VERBOSE
));
258 printf("%s\n", _("Notes:"));
259 printf(" %s\n", _("See:"));
260 printf(" %s\n", ("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT"));
261 printf(" %s\n", _("for THRESHOLD format and examples."));
263 printf(_(UT_SUPPORT
));
273 printf(" %s (-s | -h) -d val1[,val2,...,valn] [-l label]\n", progname
);
274 printf("[-w threshold] [-c threshold] [-v] [--help]\n");