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 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *****************************************************************************/
25 const char *progname
= "check_cluster";
26 const char *copyright
= "2000-2007";
27 const char *email
= "nagiosplug-devel@lists.sourceforge.net";
31 #include "utils_base.h"
33 #define CHECK_SERVICES 1
36 void print_help (void);
37 void print_usage (void);
39 int total_services_ok
=0;
40 int total_services_warning
=0;
41 int total_services_unknown
=0;
42 int total_services_critical
=0;
45 int total_hosts_down
=0;
46 int total_hosts_unreachable
=0;
51 int check_type
=CHECK_SERVICES
;
58 int process_arguments(int,char **);
62 int main(int argc
, char **argv
){
65 int return_code
=STATE_OK
;
66 thresholds
*thresholds
= NULL
;
68 setlocale (LC_ALL
, "");
69 bindtextdomain (PACKAGE
, LOCALEDIR
);
72 /* Parse extra opts if any */
73 argv
=np_extra_opts(&argc
, argv
, progname
);
75 if(process_arguments(argc
,argv
)==ERROR
)
76 usage(_("Could not parse arguments"));
78 /* Initialize the thresholds */
79 set_thresholds(&thresholds
, warn_threshold
, crit_threshold
);
81 print_thresholds("check_cluster", thresholds
);
83 /* check the data values */
84 for(ptr
=strtok(data_vals
,",");ptr
!=NULL
;ptr
=strtok(NULL
,",")){
88 if(check_type
==CHECK_SERVICES
){
94 total_services_warning
++;
97 total_services_critical
++;
100 total_services_unknown
++;
115 total_hosts_unreachable
++;
124 /* return the status of the cluster */
125 if(check_type
==CHECK_SERVICES
){
126 return_code
=get_status(total_services_warning
+total_services_unknown
+total_services_critical
, thresholds
);
127 printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n",
128 state_text(return_code
), (label
==NULL
)?"Service cluster":label
,
129 total_services_ok
,total_services_warning
,
130 total_services_unknown
,total_services_critical
);
133 return_code
=get_status(total_hosts_down
+total_hosts_unreachable
, thresholds
);
134 printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n",
135 state_text(return_code
), (label
==NULL
)?"Host cluster":label
,
136 total_hosts_up
,total_hosts_down
,total_hosts_unreachable
);
144 int process_arguments(int argc
, char **argv
){
147 static struct option longopts
[]={
148 {"data", required_argument
,0,'d'},
149 {"warning", required_argument
,0,'w'},
150 {"critical", required_argument
,0,'c'},
151 {"label", required_argument
,0,'l'},
152 {"host", no_argument
, 0,'h'},
153 {"service", no_argument
, 0,'s'},
154 {"verbose", no_argument
, 0,'v'},
155 {"version", no_argument
, 0,'V'},
156 {"help", no_argument
, 0,'H'},
160 /* no options were supplied */
166 c
=getopt_long(argc
,argv
,"hHsvVw:c:d:l:",longopts
,&option
);
168 if(c
==-1 || c
==EOF
|| c
==1)
173 case 'h': /* host cluster */
174 check_type
=CHECK_HOSTS
;
177 case 's': /* service cluster */
178 check_type
=CHECK_SERVICES
;
181 case 'w': /* warning threshold */
182 warn_threshold
= strdup(optarg
);
185 case 'c': /* warning threshold */
186 crit_threshold
= strdup(optarg
);
189 case 'd': /* data values */
190 data_vals
=(char *)strdup(optarg
);
193 case 'l': /* text label */
194 label
=(char *)strdup(optarg
);
197 case 'v': /* verbose */
201 case 'V': /* version */
202 print_revision (progname
, NP_VERSION
);
226 print_revision(progname
, NP_VERSION
);
227 printf ("Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)\n");
228 printf(COPYRIGHT
, copyright
, email
);
230 printf(_("Host/Service Cluster Plugin for Nagios 2"));
236 printf("%s\n", _("Options:"));
237 printf(_(UT_EXTRA_OPTS
));
238 printf (" %s\n", "-s, --service");
239 printf (" %s\n", _("Check service cluster status"));
240 printf (" %s\n", "-h, --host");
241 printf (" %s\n", _("Check host cluster status"));
242 printf (" %s\n", "-l, --label=STRING");
243 printf (" %s\n", _("Optional prepended text output (i.e. \"Host cluster\")"));
244 printf (" %s\n", "-w, --warning=THRESHOLD");
245 printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
246 printf (" %s\n", _("non-OK state in order to return a WARNING status level"));
247 printf (" %s\n", "-c, --critical=THRESHOLD");
248 printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
249 printf (" %s\n", _("non-OK state in order to return a CRITICAL status level"));
250 printf (" %s\n", "-d, --data=LIST");
251 printf (" %s\n", _("The status codes of the hosts or services in the cluster, separated by"));
252 printf (" %s\n", _("commas"));
254 printf(_(UT_VERBOSE
));
257 printf("%s\n", _("Notes:"));
258 printf(_(UT_THRESHOLDS_NOTES
));
261 printf (_(UT_EXTRA_OPTS_NOTES
));
265 printf ("%s\n", _("Examples:"));
266 printf (" %s\n", "check_cluster -s -d 2,0,2,0 -c @3:");
267 printf (" %s\n", _("Will alert critical if there are 3 or more service data points in a non-OK state") );
269 printf(_(UT_SUPPORT
));
278 printf(" %s (-s | -h) -d val1[,val2,...,valn] [-l label]\n", progname
);
279 printf("[-w threshold] [-c threshold] [-v] [--help]\n");