diff options
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_cluster.c b/plugins/check_cluster.c index e1ede9f..aa55528 100644 --- a/plugins/check_cluster.c +++ b/plugins/check_cluster.c | |||
@@ -1,26 +1,26 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * check_cluster.c - Host and Service Cluster Plugin for Monitoring | 3 | * check_cluster.c - Host and Service Cluster Plugin for Monitoring |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org) | 6 | * Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org) |
7 | * Copyright (c) 2007 Monitoring Plugins Development Team | 7 | * Copyright (c) 2007 Monitoring Plugins Development Team |
8 | * | 8 | * |
9 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 11 | * the Free Software Foundation, either version 3 of the License, or |
12 | * (at your option) any later version. | 12 | * (at your option) any later version. |
13 | * | 13 | * |
14 | * This program is distributed in the hope that it will be useful, | 14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. | 17 | * GNU General Public License for more details. |
18 | * | 18 | * |
19 | * You should have received a copy of the GNU General Public License | 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/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | * | 21 | * |
22 | * | 22 | * |
23 | *****************************************************************************/ | 23 | *****************************************************************************/ |
24 | 24 | ||
25 | const char *progname = "check_cluster"; | 25 | const char *progname = "check_cluster"; |
26 | const char *copyright = "2000-2007"; | 26 | const char *copyright = "2000-2007"; |
@@ -30,63 +30,61 @@ const char *email = "devel@monitoring-plugins.org"; | |||
30 | #include "utils.h" | 30 | #include "utils.h" |
31 | #include "utils_base.h" | 31 | #include "utils_base.h" |
32 | 32 | ||
33 | #define CHECK_SERVICES 1 | 33 | #define CHECK_SERVICES 1 |
34 | #define CHECK_HOSTS 2 | 34 | #define CHECK_HOSTS 2 |
35 | 35 | ||
36 | void print_help (void); | 36 | void print_help(void); |
37 | void print_usage (void); | 37 | void print_usage(void); |
38 | 38 | ||
39 | int total_services_ok=0; | 39 | int total_services_ok = 0; |
40 | int total_services_warning=0; | 40 | int total_services_warning = 0; |
41 | int total_services_unknown=0; | 41 | int total_services_unknown = 0; |
42 | int total_services_critical=0; | 42 | int total_services_critical = 0; |
43 | 43 | ||
44 | int total_hosts_up=0; | 44 | int total_hosts_up = 0; |
45 | int total_hosts_down=0; | 45 | int total_hosts_down = 0; |
46 | int total_hosts_unreachable=0; | 46 | int total_hosts_unreachable = 0; |
47 | 47 | ||
48 | char *warn_threshold; | 48 | char *warn_threshold; |
49 | char *crit_threshold; | 49 | char *crit_threshold; |
50 | 50 | ||
51 | int check_type=CHECK_SERVICES; | 51 | int check_type = CHECK_SERVICES; |
52 | 52 | ||
53 | char *data_vals=NULL; | 53 | char *data_vals = NULL; |
54 | char *label=NULL; | 54 | char *label = NULL; |
55 | 55 | ||
56 | int verbose=0; | 56 | int verbose = 0; |
57 | 57 | ||
58 | int process_arguments(int,char **); | 58 | int process_arguments(int, char **); |
59 | 59 | ||
60 | 60 | int main(int argc, char **argv) { | |
61 | |||
62 | int main(int argc, char **argv){ | ||
63 | char *ptr; | 61 | char *ptr; |
64 | int data_val; | 62 | int data_val; |
65 | int return_code=STATE_OK; | 63 | int return_code = STATE_OK; |
66 | thresholds *thresholds = NULL; | 64 | thresholds *thresholds = NULL; |
67 | 65 | ||
68 | setlocale (LC_ALL, ""); | 66 | setlocale(LC_ALL, ""); |
69 | bindtextdomain (PACKAGE, LOCALEDIR); | 67 | bindtextdomain(PACKAGE, LOCALEDIR); |
70 | textdomain (PACKAGE); | 68 | textdomain(PACKAGE); |
71 | 69 | ||
72 | /* Parse extra opts if any */ | 70 | /* Parse extra opts if any */ |
73 | argv=np_extra_opts(&argc, argv, progname); | 71 | argv = np_extra_opts(&argc, argv, progname); |
74 | 72 | ||
75 | if(process_arguments(argc,argv)==ERROR) | 73 | if (process_arguments(argc, argv) == ERROR) |
76 | usage(_("Could not parse arguments")); | 74 | usage(_("Could not parse arguments")); |
77 | 75 | ||
78 | /* Initialize the thresholds */ | 76 | /* Initialize the thresholds */ |
79 | set_thresholds(&thresholds, warn_threshold, crit_threshold); | 77 | set_thresholds(&thresholds, warn_threshold, crit_threshold); |
80 | if(verbose) | 78 | if (verbose) |
81 | print_thresholds("check_cluster", thresholds); | 79 | print_thresholds("check_cluster", thresholds); |
82 | 80 | ||
83 | /* check the data values */ | 81 | /* check the data values */ |
84 | for(ptr=strtok(data_vals,",");ptr!=NULL;ptr=strtok(NULL,",")){ | 82 | for (ptr = strtok(data_vals, ","); ptr != NULL; ptr = strtok(NULL, ",")) { |
85 | 83 | ||
86 | data_val=atoi(ptr); | 84 | data_val = atoi(ptr); |
87 | 85 | ||
88 | if(check_type==CHECK_SERVICES){ | 86 | if (check_type == CHECK_SERVICES) { |
89 | switch(data_val){ | 87 | switch (data_val) { |
90 | case 0: | 88 | case 0: |
91 | total_services_ok++; | 89 | total_services_ok++; |
92 | break; | 90 | break; |
@@ -101,10 +99,9 @@ int main(int argc, char **argv){ | |||
101 | break; | 99 | break; |
102 | default: | 100 | default: |
103 | break; | 101 | break; |
104 | } | 102 | } |
105 | } | 103 | } else { |
106 | else{ | 104 | switch (data_val) { |
107 | switch(data_val){ | ||
108 | case 0: | 105 | case 0: |
109 | total_hosts_up++; | 106 | total_hosts_up++; |
110 | break; | 107 | break; |
@@ -116,67 +113,54 @@ int main(int argc, char **argv){ | |||
116 | break; | 113 | break; |
117 | default: | 114 | default: |
118 | break; | 115 | break; |
119 | } | 116 | } |
120 | } | 117 | } |
121 | } | 118 | } |
122 | |||
123 | 119 | ||
124 | /* return the status of the cluster */ | 120 | /* return the status of the cluster */ |
125 | if(check_type==CHECK_SERVICES){ | 121 | if (check_type == CHECK_SERVICES) { |
126 | return_code=get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds); | 122 | 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", | 123 | printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n", state_text(return_code), |
128 | state_text(return_code), (label==NULL)?"Service cluster":label, | 124 | (label == NULL) ? "Service cluster" : label, total_services_ok, total_services_warning, total_services_unknown, |
129 | total_services_ok,total_services_warning, | 125 | total_services_critical); |
130 | total_services_unknown,total_services_critical); | 126 | } else { |
131 | } | 127 | return_code = get_status(total_hosts_down + total_hosts_unreachable, thresholds); |
132 | else{ | 128 | printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n", state_text(return_code), (label == NULL) ? "Host cluster" : label, |
133 | return_code=get_status(total_hosts_down+total_hosts_unreachable, thresholds); | 129 | total_hosts_up, total_hosts_down, total_hosts_unreachable); |
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); | ||
137 | } | 130 | } |
138 | 131 | ||
139 | return return_code; | 132 | return return_code; |
140 | } | 133 | } |
141 | 134 | ||
142 | 135 | int process_arguments(int argc, char **argv) { | |
143 | |||
144 | int process_arguments(int argc, char **argv){ | ||
145 | int c; | 136 | int c; |
146 | char *ptr; | 137 | char *ptr; |
147 | int option=0; | 138 | int option = 0; |
148 | static struct option longopts[]={ | 139 | static struct option longopts[] = {{"data", required_argument, 0, 'd'}, {"warning", required_argument, 0, 'w'}, |
149 | {"data", required_argument,0,'d'}, | 140 | {"critical", required_argument, 0, 'c'}, {"label", required_argument, 0, 'l'}, |
150 | {"warning", required_argument,0,'w'}, | 141 | {"host", no_argument, 0, 'h'}, {"service", no_argument, 0, 's'}, |
151 | {"critical", required_argument,0,'c'}, | 142 | {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, |
152 | {"label", required_argument,0,'l'}, | 143 | {"help", no_argument, 0, 'H'}, {0, 0, 0, 0}}; |
153 | {"host", no_argument, 0,'h'}, | ||
154 | {"service", no_argument, 0,'s'}, | ||
155 | {"verbose", no_argument, 0,'v'}, | ||
156 | {"version", no_argument, 0,'V'}, | ||
157 | {"help", no_argument, 0,'H'}, | ||
158 | {0,0,0,0} | ||
159 | }; | ||
160 | 144 | ||
161 | /* no options were supplied */ | 145 | /* no options were supplied */ |
162 | if(argc<2) | 146 | if (argc < 2) |
163 | return ERROR; | 147 | return ERROR; |
164 | 148 | ||
165 | while(1){ | 149 | while (1) { |
166 | 150 | ||
167 | c=getopt_long(argc,argv,"hHsvVw:c:d:l:",longopts,&option); | 151 | c = getopt_long(argc, argv, "hHsvVw:c:d:l:", longopts, &option); |
168 | 152 | ||
169 | if(c==-1 || c==EOF || c==1) | 153 | if (c == -1 || c == EOF || c == 1) |
170 | break; | 154 | break; |
171 | 155 | ||
172 | switch(c){ | 156 | switch (c) { |
173 | 157 | ||
174 | case 'h': /* host cluster */ | 158 | case 'h': /* host cluster */ |
175 | check_type=CHECK_HOSTS; | 159 | check_type = CHECK_HOSTS; |
176 | break; | 160 | break; |
177 | 161 | ||
178 | case 's': /* service cluster */ | 162 | case 's': /* service cluster */ |
179 | check_type=CHECK_SERVICES; | 163 | check_type = CHECK_SERVICES; |
180 | break; | 164 | break; |
181 | 165 | ||
182 | case 'w': /* warning threshold */ | 166 | case 'w': /* warning threshold */ |
@@ -188,20 +172,20 @@ int process_arguments(int argc, char **argv){ | |||
188 | break; | 172 | break; |
189 | 173 | ||
190 | case 'd': /* data values */ | 174 | case 'd': /* data values */ |
191 | data_vals=(char *)strdup(optarg); | 175 | data_vals = (char *)strdup(optarg); |
192 | /* validate data */ | 176 | /* validate data */ |
193 | for (ptr=data_vals;ptr!=NULL;ptr+=2){ | 177 | for (ptr = data_vals; ptr != NULL; ptr += 2) { |
194 | if (ptr[0]<'0' || ptr[0]>'3') | 178 | if (ptr[0] < '0' || ptr[0] > '3') |
195 | return ERROR; | 179 | return ERROR; |
196 | if (ptr[1]=='\0') | 180 | if (ptr[1] == '\0') |
197 | break; | 181 | break; |
198 | if (ptr[1]!=',') | 182 | if (ptr[1] != ',') |
199 | return ERROR; | 183 | return ERROR; |
200 | } | 184 | } |
201 | break; | 185 | break; |
202 | 186 | ||
203 | case 'l': /* text label */ | 187 | case 'l': /* text label */ |
204 | label=(char *)strdup(optarg); | 188 | label = (char *)strdup(optarg); |
205 | break; | 189 | break; |
206 | 190 | ||
207 | case 'v': /* verbose */ | 191 | case 'v': /* verbose */ |
@@ -209,8 +193,8 @@ int process_arguments(int argc, char **argv){ | |||
209 | break; | 193 | break; |
210 | 194 | ||
211 | case 'V': /* version */ | 195 | case 'V': /* version */ |
212 | print_revision (progname, NP_VERSION); | 196 | print_revision(progname, NP_VERSION); |
213 | exit (STATE_UNKNOWN); | 197 | exit(STATE_UNKNOWN); |
214 | break; | 198 | break; |
215 | 199 | ||
216 | case 'H': /* help */ | 200 | case 'H': /* help */ |
@@ -221,20 +205,18 @@ int process_arguments(int argc, char **argv){ | |||
221 | default: | 205 | default: |
222 | return ERROR; | 206 | return ERROR; |
223 | break; | 207 | break; |
224 | } | 208 | } |
225 | } | 209 | } |
226 | 210 | ||
227 | if(data_vals==NULL) | 211 | if (data_vals == NULL) |
228 | return ERROR; | 212 | return ERROR; |
229 | 213 | ||
230 | return OK; | 214 | return OK; |
231 | } | 215 | } |
232 | 216 | ||
233 | void | 217 | void print_help(void) { |
234 | print_help(void) | ||
235 | { | ||
236 | print_revision(progname, NP_VERSION); | 218 | print_revision(progname, NP_VERSION); |
237 | printf ("Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)\n"); | 219 | printf("Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)\n"); |
238 | printf(COPYRIGHT, copyright, email); | 220 | printf(COPYRIGHT, copyright, email); |
239 | 221 | ||
240 | printf(_("Host/Service Cluster Plugin for Monitoring")); | 222 | printf(_("Host/Service Cluster Plugin for Monitoring")); |
@@ -245,21 +227,21 @@ print_help(void) | |||
245 | printf("\n"); | 227 | printf("\n"); |
246 | printf("%s\n", _("Options:")); | 228 | printf("%s\n", _("Options:")); |
247 | printf(UT_EXTRA_OPTS); | 229 | printf(UT_EXTRA_OPTS); |
248 | printf (" %s\n", "-s, --service"); | 230 | printf(" %s\n", "-s, --service"); |
249 | printf (" %s\n", _("Check service cluster status")); | 231 | printf(" %s\n", _("Check service cluster status")); |
250 | printf (" %s\n", "-h, --host"); | 232 | printf(" %s\n", "-h, --host"); |
251 | printf (" %s\n", _("Check host cluster status")); | 233 | printf(" %s\n", _("Check host cluster status")); |
252 | printf (" %s\n", "-l, --label=STRING"); | 234 | printf(" %s\n", "-l, --label=STRING"); |
253 | printf (" %s\n", _("Optional prepended text output (i.e. \"Host cluster\")")); | 235 | printf(" %s\n", _("Optional prepended text output (i.e. \"Host cluster\")")); |
254 | printf (" %s\n", "-w, --warning=THRESHOLD"); | 236 | printf(" %s\n", "-w, --warning=THRESHOLD"); |
255 | printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a")); | 237 | printf(" %s\n", _("Specifies the range of hosts or services in cluster that must be in a")); |
256 | printf (" %s\n", _("non-OK state in order to return a WARNING status level")); | 238 | printf(" %s\n", _("non-OK state in order to return a WARNING status level")); |
257 | printf (" %s\n", "-c, --critical=THRESHOLD"); | 239 | printf(" %s\n", "-c, --critical=THRESHOLD"); |
258 | printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a")); | 240 | printf(" %s\n", _("Specifies the range of hosts or services in cluster that must be in a")); |
259 | printf (" %s\n", _("non-OK state in order to return a CRITICAL status level")); | 241 | printf(" %s\n", _("non-OK state in order to return a CRITICAL status level")); |
260 | printf (" %s\n", "-d, --data=LIST"); | 242 | printf(" %s\n", "-d, --data=LIST"); |
261 | printf (" %s\n", _("The status codes of the hosts or services in the cluster, separated by")); | 243 | printf(" %s\n", _("The status codes of the hosts or services in the cluster, separated by")); |
262 | printf (" %s\n", _("commas")); | 244 | printf(" %s\n", _("commas")); |
263 | 245 | ||
264 | printf(UT_VERBOSE); | 246 | printf(UT_VERBOSE); |
265 | 247 | ||
@@ -267,23 +249,18 @@ print_help(void) | |||
267 | printf("%s\n", _("Notes:")); | 249 | printf("%s\n", _("Notes:")); |
268 | printf(UT_THRESHOLDS_NOTES); | 250 | printf(UT_THRESHOLDS_NOTES); |
269 | 251 | ||
270 | printf ("\n"); | 252 | printf("\n"); |
271 | printf ("%s\n", _("Examples:")); | 253 | printf("%s\n", _("Examples:")); |
272 | printf (" %s\n", "check_cluster -s -d 2,0,2,0 -c @3:"); | 254 | printf(" %s\n", "check_cluster -s -d 2,0,2,0 -c @3:"); |
273 | printf (" %s\n", _("Will alert critical if there are 3 or more service data points in a non-OK") ); | 255 | printf(" %s\n", _("Will alert critical if there are 3 or more service data points in a non-OK")); |
274 | printf (" %s\n", _("state.") ); | 256 | printf(" %s\n", _("state.")); |
275 | 257 | ||
276 | printf(UT_SUPPORT); | 258 | printf(UT_SUPPORT); |
277 | } | 259 | } |
278 | 260 | ||
279 | 261 | void print_usage(void) { | |
280 | void | ||
281 | print_usage(void) | ||
282 | { | ||
283 | 262 | ||
284 | printf("%s\n", _("Usage:")); | 263 | printf("%s\n", _("Usage:")); |
285 | printf(" %s (-s | -h) -d val1[,val2,...,valn] [-l label]\n", progname); | 264 | printf(" %s (-s | -h) -d val1[,val2,...,valn] [-l label]\n", progname); |
286 | printf("[-w threshold] [-c threshold] [-v] [--help]\n"); | 265 | printf("[-w threshold] [-c threshold] [-v] [--help]\n"); |
287 | |||
288 | } | 266 | } |
289 | |||