diff options
Diffstat (limited to 'plugins/check_nt.c')
-rw-r--r-- | plugins/check_nt.c | 201 |
1 files changed, 118 insertions, 83 deletions
diff --git a/plugins/check_nt.c b/plugins/check_nt.c index dec0b668..fb9a7b94 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c | |||
@@ -122,8 +122,9 @@ int main(int argc, char **argv) { | |||
122 | /* Parse extra opts if any */ | 122 | /* Parse extra opts if any */ |
123 | argv = np_extra_opts(&argc, argv, progname); | 123 | argv = np_extra_opts(&argc, argv, progname); |
124 | 124 | ||
125 | if (process_arguments(argc, argv) == ERROR) | 125 | if (process_arguments(argc, argv) == ERROR) { |
126 | usage4(_("Could not parse arguments")); | 126 | usage4(_("Could not parse arguments")); |
127 | } | ||
127 | 128 | ||
128 | /* initialize alarm signal handling */ | 129 | /* initialize alarm signal handling */ |
129 | signal(SIGALRM, socket_timeout_alarm_handler); | 130 | signal(SIGALRM, socket_timeout_alarm_handler); |
@@ -148,11 +149,11 @@ int main(int argc, char **argv) { | |||
148 | 149 | ||
149 | case CHECK_CPULOAD: | 150 | case CHECK_CPULOAD: |
150 | 151 | ||
151 | if (value_list == NULL) | 152 | if (value_list == NULL) { |
152 | output_message = strdup(_("missing -l parameters")); | 153 | output_message = strdup(_("missing -l parameters")); |
153 | else if (!strtoularray(lvalue_list, value_list, ",")) | 154 | } else if (!strtoularray(lvalue_list, value_list, ",")) { |
154 | output_message = strdup(_("wrong -l parameter.")); | 155 | output_message = strdup(_("wrong -l parameter.")); |
155 | else { | 156 | } else { |
156 | /* -l parameters is present with only integers */ | 157 | /* -l parameters is present with only integers */ |
157 | return_code = STATE_OK; | 158 | return_code = STATE_OK; |
158 | temp_string = strdup(_("CPU Load")); | 159 | temp_string = strdup(_("CPU Load")); |
@@ -170,10 +171,11 @@ int main(int argc, char **argv) { | |||
170 | utilization = strtoul(recv_buffer, NULL, 10); | 171 | utilization = strtoul(recv_buffer, NULL, 10); |
171 | 172 | ||
172 | /* Check if any of the request is in a warning or critical state */ | 173 | /* Check if any of the request is in a warning or critical state */ |
173 | if (utilization >= lvalue_list[2 + offset]) | 174 | if (utilization >= lvalue_list[2 + offset]) { |
174 | return_code = STATE_CRITICAL; | 175 | return_code = STATE_CRITICAL; |
175 | else if (utilization >= lvalue_list[1 + offset] && return_code < STATE_WARNING) | 176 | } else if (utilization >= lvalue_list[1 + offset] && return_code < STATE_WARNING) { |
176 | return_code = STATE_WARNING; | 177 | return_code = STATE_WARNING; |
178 | } | ||
177 | 179 | ||
178 | xasprintf(&output_message, _(" %lu%% (%lu min average)"), utilization, lvalue_list[0 + offset]); | 180 | xasprintf(&output_message, _(" %lu%% (%lu min average)"), utilization, lvalue_list[0 + offset]); |
179 | xasprintf(&temp_string, "%s%s", temp_string, output_message); | 181 | xasprintf(&temp_string, "%s%s", temp_string, output_message); |
@@ -186,8 +188,9 @@ int main(int argc, char **argv) { | |||
186 | if (strlen(temp_string) > 10) { /* we had at least one loop */ | 188 | if (strlen(temp_string) > 10) { /* we had at least one loop */ |
187 | output_message = strdup(temp_string); | 189 | output_message = strdup(temp_string); |
188 | perfdata = temp_string_perf; | 190 | perfdata = temp_string_perf; |
189 | } else | 191 | } else { |
190 | output_message = strdup(_("not enough values for -l parameters")); | 192 | output_message = strdup(_("not enough values for -l parameters")); |
193 | } | ||
191 | } | 194 | } |
192 | break; | 195 | break; |
193 | 196 | ||
@@ -208,41 +211,45 @@ int main(int argc, char **argv) { | |||
208 | uphours = (uptime % 86400) / 3600; | 211 | uphours = (uptime % 86400) / 3600; |
209 | upminutes = ((uptime % 86400) % 3600) / 60; | 212 | upminutes = ((uptime % 86400) % 3600) / 60; |
210 | 213 | ||
211 | if (!strncmp(value_list, "minutes", strlen("minutes"))) | 214 | if (!strncmp(value_list, "minutes", strlen("minutes"))) { |
212 | uptime = uptime / 60; | 215 | uptime = uptime / 60; |
213 | else if (!strncmp(value_list, "hours", strlen("hours"))) | 216 | } else if (!strncmp(value_list, "hours", strlen("hours"))) { |
214 | uptime = uptime / 3600; | 217 | uptime = uptime / 3600; |
215 | else if (!strncmp(value_list, "days", strlen("days"))) | 218 | } else if (!strncmp(value_list, "days", strlen("days"))) { |
216 | uptime = uptime / 86400; | 219 | uptime = uptime / 86400; |
220 | } | ||
217 | /* else uptime in seconds, nothing to do */ | 221 | /* else uptime in seconds, nothing to do */ |
218 | 222 | ||
219 | xasprintf(&output_message, _("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"), updays, uphours, upminutes, | 223 | xasprintf(&output_message, _("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"), updays, uphours, upminutes, |
220 | uptime); | 224 | uptime); |
221 | 225 | ||
222 | if (check_critical_value && uptime <= critical_value) | 226 | if (check_critical_value && uptime <= critical_value) { |
223 | return_code = STATE_CRITICAL; | 227 | return_code = STATE_CRITICAL; |
224 | else if (check_warning_value && uptime <= warning_value) | 228 | } else if (check_warning_value && uptime <= warning_value) { |
225 | return_code = STATE_WARNING; | 229 | return_code = STATE_WARNING; |
226 | else | 230 | } else { |
227 | return_code = STATE_OK; | 231 | return_code = STATE_OK; |
232 | } | ||
228 | } | 233 | } |
229 | break; | 234 | break; |
230 | 235 | ||
231 | case CHECK_USEDDISKSPACE: | 236 | case CHECK_USEDDISKSPACE: |
232 | 237 | ||
233 | if (value_list == NULL) | 238 | if (value_list == NULL) { |
234 | output_message = strdup(_("missing -l parameters")); | 239 | output_message = strdup(_("missing -l parameters")); |
235 | else if (strlen(value_list) != 1) | 240 | } else if (strlen(value_list) != 1) { |
236 | output_message = strdup(_("wrong -l argument")); | 241 | output_message = strdup(_("wrong -l argument")); |
237 | else { | 242 | } else { |
238 | xasprintf(&send_buffer, "%s&4&%s", req_password, value_list); | 243 | xasprintf(&send_buffer, "%s&4&%s", req_password, value_list); |
239 | fetch_data(server_address, server_port, send_buffer); | 244 | fetch_data(server_address, server_port, send_buffer); |
240 | fds = strtok(recv_buffer, "&"); | 245 | fds = strtok(recv_buffer, "&"); |
241 | tds = strtok(NULL, "&"); | 246 | tds = strtok(NULL, "&"); |
242 | if (fds != NULL) | 247 | if (fds != NULL) { |
243 | free_disk_space = atof(fds); | 248 | free_disk_space = atof(fds); |
244 | if (tds != NULL) | 249 | } |
250 | if (tds != NULL) { | ||
245 | total_disk_space = atof(tds); | 251 | total_disk_space = atof(tds); |
252 | } | ||
246 | 253 | ||
247 | if (total_disk_space > 0 && free_disk_space >= 0) { | 254 | if (total_disk_space > 0 && free_disk_space >= 0) { |
248 | percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100; | 255 | percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100; |
@@ -256,12 +263,13 @@ int main(int argc, char **argv) { | |||
256 | (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824, | 263 | (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824, |
257 | critical_used_space / 1073741824, total_disk_space / 1073741824); | 264 | critical_used_space / 1073741824, total_disk_space / 1073741824); |
258 | 265 | ||
259 | if (check_critical_value && percent_used_space >= critical_value) | 266 | if (check_critical_value && percent_used_space >= critical_value) { |
260 | return_code = STATE_CRITICAL; | 267 | return_code = STATE_CRITICAL; |
261 | else if (check_warning_value && percent_used_space >= warning_value) | 268 | } else if (check_warning_value && percent_used_space >= warning_value) { |
262 | return_code = STATE_WARNING; | 269 | return_code = STATE_WARNING; |
263 | else | 270 | } else { |
264 | return_code = STATE_OK; | 271 | return_code = STATE_OK; |
272 | } | ||
265 | 273 | ||
266 | output_message = strdup(temp_string); | 274 | output_message = strdup(temp_string); |
267 | perfdata = temp_string_perf; | 275 | perfdata = temp_string_perf; |
@@ -275,16 +283,17 @@ int main(int argc, char **argv) { | |||
275 | case CHECK_SERVICESTATE: | 283 | case CHECK_SERVICESTATE: |
276 | case CHECK_PROCSTATE: | 284 | case CHECK_PROCSTATE: |
277 | 285 | ||
278 | if (value_list == NULL) | 286 | if (value_list == NULL) { |
279 | output_message = strdup(_("No service/process specified")); | 287 | output_message = strdup(_("No service/process specified")); |
280 | else { | 288 | } else { |
281 | preparelist(value_list); /* replace , between services with & to send the request */ | 289 | preparelist(value_list); /* replace , between services with & to send the request */ |
282 | xasprintf(&send_buffer, "%s&%u&%s&%s", req_password, (vars_to_check == CHECK_SERVICESTATE) ? 5 : 6, | 290 | xasprintf(&send_buffer, "%s&%u&%s&%s", req_password, (vars_to_check == CHECK_SERVICESTATE) ? 5 : 6, |
283 | (show_all) ? "ShowAll" : "ShowFail", value_list); | 291 | (show_all) ? "ShowAll" : "ShowFail", value_list); |
284 | fetch_data(server_address, server_port, send_buffer); | 292 | fetch_data(server_address, server_port, send_buffer); |
285 | numstr = strtok(recv_buffer, "&"); | 293 | numstr = strtok(recv_buffer, "&"); |
286 | if (numstr == NULL) | 294 | if (numstr == NULL) { |
287 | die(STATE_UNKNOWN, _("could not fetch information from server\n")); | 295 | die(STATE_UNKNOWN, _("could not fetch information from server\n")); |
296 | } | ||
288 | return_code = atoi(numstr); | 297 | return_code = atoi(numstr); |
289 | temp_string = strtok(NULL, "&"); | 298 | temp_string = strtok(NULL, "&"); |
290 | output_message = strdup(temp_string); | 299 | output_message = strdup(temp_string); |
@@ -296,12 +305,14 @@ int main(int argc, char **argv) { | |||
296 | xasprintf(&send_buffer, "%s&7", req_password); | 305 | xasprintf(&send_buffer, "%s&7", req_password); |
297 | fetch_data(server_address, server_port, send_buffer); | 306 | fetch_data(server_address, server_port, send_buffer); |
298 | numstr = strtok(recv_buffer, "&"); | 307 | numstr = strtok(recv_buffer, "&"); |
299 | if (numstr == NULL) | 308 | if (numstr == NULL) { |
300 | die(STATE_UNKNOWN, _("could not fetch information from server\n")); | 309 | die(STATE_UNKNOWN, _("could not fetch information from server\n")); |
310 | } | ||
301 | mem_commitLimit = atof(numstr); | 311 | mem_commitLimit = atof(numstr); |
302 | numstr = strtok(NULL, "&"); | 312 | numstr = strtok(NULL, "&"); |
303 | if (numstr == NULL) | 313 | if (numstr == NULL) { |
304 | die(STATE_UNKNOWN, _("could not fetch information from server\n")); | 314 | die(STATE_UNKNOWN, _("could not fetch information from server\n")); |
315 | } | ||
305 | mem_commitByte = atof(numstr); | 316 | mem_commitByte = atof(numstr); |
306 | percent_used_space = (mem_commitByte / mem_commitLimit) * 100; | 317 | percent_used_space = (mem_commitByte / mem_commitLimit) * 100; |
307 | warning_used_space = ((float)warning_value / 100) * mem_commitLimit; | 318 | warning_used_space = ((float)warning_value / 100) * mem_commitLimit; |
@@ -316,10 +327,11 @@ int main(int argc, char **argv) { | |||
316 | critical_used_space / 1048567, mem_commitLimit / 1048567); | 327 | critical_used_space / 1048567, mem_commitLimit / 1048567); |
317 | 328 | ||
318 | return_code = STATE_OK; | 329 | return_code = STATE_OK; |
319 | if (check_critical_value && percent_used_space >= critical_value) | 330 | if (check_critical_value && percent_used_space >= critical_value) { |
320 | return_code = STATE_CRITICAL; | 331 | return_code = STATE_CRITICAL; |
321 | else if (check_warning_value && percent_used_space >= warning_value) | 332 | } else if (check_warning_value && percent_used_space >= warning_value) { |
322 | return_code = STATE_WARNING; | 333 | return_code = STATE_WARNING; |
334 | } | ||
323 | 335 | ||
324 | break; | 336 | break; |
325 | 337 | ||
@@ -346,9 +358,9 @@ int main(int argc, char **argv) { | |||
346 | strange things will happen when you make graphs of your data. | 358 | strange things will happen when you make graphs of your data. |
347 | */ | 359 | */ |
348 | 360 | ||
349 | if (value_list == NULL) | 361 | if (value_list == NULL) { |
350 | output_message = strdup(_("No counter specified")); | 362 | output_message = strdup(_("No counter specified")); |
351 | else { | 363 | } else { |
352 | preparelist(value_list); /* replace , between services with & to send the request */ | 364 | preparelist(value_list); /* replace , between services with & to send the request */ |
353 | isPercent = (strchr(value_list, '%') != NULL); | 365 | isPercent = (strchr(value_list, '%') != NULL); |
354 | 366 | ||
@@ -359,9 +371,9 @@ int main(int argc, char **argv) { | |||
359 | fetch_data(server_address, server_port, send_buffer); | 371 | fetch_data(server_address, server_port, send_buffer); |
360 | counter_value = atof(recv_buffer); | 372 | counter_value = atof(recv_buffer); |
361 | 373 | ||
362 | if (description == NULL) | 374 | if (description == NULL) { |
363 | xasprintf(&output_message, "%.f", counter_value); | 375 | xasprintf(&output_message, "%.f", counter_value); |
364 | else if (isPercent) { | 376 | } else if (isPercent) { |
365 | counter_unit = strdup("%"); | 377 | counter_unit = strdup("%"); |
366 | allRight = true; | 378 | allRight = true; |
367 | } | 379 | } |
@@ -375,16 +387,18 @@ int main(int argc, char **argv) { | |||
375 | fminval = (minval != NULL) ? strtod(minval, &errcvt) : -1; | 387 | fminval = (minval != NULL) ? strtod(minval, &errcvt) : -1; |
376 | fmaxval = (minval != NULL) ? strtod(maxval, &errcvt) : -1; | 388 | fmaxval = (minval != NULL) ? strtod(maxval, &errcvt) : -1; |
377 | 389 | ||
378 | if ((fminval == 0) && (minval == errcvt)) | 390 | if ((fminval == 0) && (minval == errcvt)) { |
379 | output_message = strdup(_("Minimum value contains non-numbers")); | 391 | output_message = strdup(_("Minimum value contains non-numbers")); |
380 | else { | 392 | } else { |
381 | if ((fmaxval == 0) && (maxval == errcvt)) | 393 | if ((fmaxval == 0) && (maxval == errcvt)) { |
382 | output_message = strdup(_("Maximum value contains non-numbers")); | 394 | output_message = strdup(_("Maximum value contains non-numbers")); |
383 | else | 395 | } else { |
384 | allRight = true; /* Everything is OK. */ | 396 | allRight = true; /* Everything is OK. */ |
397 | } | ||
385 | } | 398 | } |
386 | } else if ((counter_unit == NULL) && (description != NULL)) | 399 | } else if ((counter_unit == NULL) && (description != NULL)) { |
387 | output_message = strdup(_("No unit counter specified")); | 400 | output_message = strdup(_("No unit counter specified")); |
401 | } | ||
388 | 402 | ||
389 | if (allRight) { | 403 | if (allRight) { |
390 | /* Let's format the output string, finally... */ | 404 | /* Let's format the output string, finally... */ |
@@ -402,26 +416,28 @@ int main(int argc, char **argv) { | |||
402 | } | 416 | } |
403 | 417 | ||
404 | if (critical_value > warning_value) { /* Normal thresholds */ | 418 | if (critical_value > warning_value) { /* Normal thresholds */ |
405 | if (check_critical_value && counter_value >= critical_value) | 419 | if (check_critical_value && counter_value >= critical_value) { |
406 | return_code = STATE_CRITICAL; | 420 | return_code = STATE_CRITICAL; |
407 | else if (check_warning_value && counter_value >= warning_value) | 421 | } else if (check_warning_value && counter_value >= warning_value) { |
408 | return_code = STATE_WARNING; | 422 | return_code = STATE_WARNING; |
409 | else | 423 | } else { |
410 | return_code = STATE_OK; | 424 | return_code = STATE_OK; |
425 | } | ||
411 | } else { /* inverse thresholds */ | 426 | } else { /* inverse thresholds */ |
412 | return_code = STATE_OK; | 427 | return_code = STATE_OK; |
413 | if (check_critical_value && counter_value <= critical_value) | 428 | if (check_critical_value && counter_value <= critical_value) { |
414 | return_code = STATE_CRITICAL; | 429 | return_code = STATE_CRITICAL; |
415 | else if (check_warning_value && counter_value <= warning_value) | 430 | } else if (check_warning_value && counter_value <= warning_value) { |
416 | return_code = STATE_WARNING; | 431 | return_code = STATE_WARNING; |
432 | } | ||
417 | } | 433 | } |
418 | break; | 434 | break; |
419 | 435 | ||
420 | case CHECK_FILEAGE: | 436 | case CHECK_FILEAGE: |
421 | 437 | ||
422 | if (value_list == NULL) | 438 | if (value_list == NULL) { |
423 | output_message = strdup(_("No counter specified")); | 439 | output_message = strdup(_("No counter specified")); |
424 | else { | 440 | } else { |
425 | preparelist(value_list); /* replace , between services with & to send the request */ | 441 | preparelist(value_list); /* replace , between services with & to send the request */ |
426 | xasprintf(&send_buffer, "%s&9&%s", req_password, value_list); | 442 | xasprintf(&send_buffer, "%s&9&%s", req_password, value_list); |
427 | fetch_data(server_address, server_port, send_buffer); | 443 | fetch_data(server_address, server_port, send_buffer); |
@@ -430,27 +446,29 @@ int main(int argc, char **argv) { | |||
430 | output_message = strdup(description); | 446 | output_message = strdup(description); |
431 | 447 | ||
432 | if (critical_value > warning_value) { /* Normal thresholds */ | 448 | if (critical_value > warning_value) { /* Normal thresholds */ |
433 | if (check_critical_value && age_in_minutes >= critical_value) | 449 | if (check_critical_value && age_in_minutes >= critical_value) { |
434 | return_code = STATE_CRITICAL; | 450 | return_code = STATE_CRITICAL; |
435 | else if (check_warning_value && age_in_minutes >= warning_value) | 451 | } else if (check_warning_value && age_in_minutes >= warning_value) { |
436 | return_code = STATE_WARNING; | 452 | return_code = STATE_WARNING; |
437 | else | 453 | } else { |
438 | return_code = STATE_OK; | 454 | return_code = STATE_OK; |
455 | } | ||
439 | } else { /* inverse thresholds */ | 456 | } else { /* inverse thresholds */ |
440 | if (check_critical_value && age_in_minutes <= critical_value) | 457 | if (check_critical_value && age_in_minutes <= critical_value) { |
441 | return_code = STATE_CRITICAL; | 458 | return_code = STATE_CRITICAL; |
442 | else if (check_warning_value && age_in_minutes <= warning_value) | 459 | } else if (check_warning_value && age_in_minutes <= warning_value) { |
443 | return_code = STATE_WARNING; | 460 | return_code = STATE_WARNING; |
444 | else | 461 | } else { |
445 | return_code = STATE_OK; | 462 | return_code = STATE_OK; |
463 | } | ||
446 | } | 464 | } |
447 | } | 465 | } |
448 | break; | 466 | break; |
449 | 467 | ||
450 | case CHECK_INSTANCES: | 468 | case CHECK_INSTANCES: |
451 | if (value_list == NULL) | 469 | if (value_list == NULL) { |
452 | output_message = strdup(_("No counter specified")); | 470 | output_message = strdup(_("No counter specified")); |
453 | else { | 471 | } else { |
454 | xasprintf(&send_buffer, "%s&10&%s", req_password, value_list); | 472 | xasprintf(&send_buffer, "%s&10&%s", req_password, value_list); |
455 | fetch_data(server_address, server_port, send_buffer); | 473 | fetch_data(server_address, server_port, send_buffer); |
456 | if (!strncmp(recv_buffer, "ERROR", 5)) { | 474 | if (!strncmp(recv_buffer, "ERROR", 5)) { |
@@ -471,10 +489,11 @@ int main(int argc, char **argv) { | |||
471 | /* reset timeout */ | 489 | /* reset timeout */ |
472 | alarm(0); | 490 | alarm(0); |
473 | 491 | ||
474 | if (perfdata == NULL) | 492 | if (perfdata == NULL) { |
475 | printf("%s\n", output_message); | 493 | printf("%s\n", output_message); |
476 | else | 494 | } else { |
477 | printf("%s | %s\n", output_message, perfdata); | 495 | printf("%s | %s\n", output_message, perfdata); |
496 | } | ||
478 | return return_code; | 497 | return return_code; |
479 | } | 498 | } |
480 | 499 | ||
@@ -498,8 +517,9 @@ int process_arguments(int argc, char **argv) { | |||
498 | {0, 0, 0, 0}}; | 517 | {0, 0, 0, 0}}; |
499 | 518 | ||
500 | /* no options were supplied */ | 519 | /* no options were supplied */ |
501 | if (argc < 2) | 520 | if (argc < 2) { |
502 | return ERROR; | 521 | return ERROR; |
522 | } | ||
503 | 523 | ||
504 | /* backwards compatibility */ | 524 | /* backwards compatibility */ |
505 | if (!is_option(argv[1])) { | 525 | if (!is_option(argv[1])) { |
@@ -510,19 +530,21 @@ int process_arguments(int argc, char **argv) { | |||
510 | } | 530 | } |
511 | 531 | ||
512 | for (c = 1; c < argc; c++) { | 532 | for (c = 1; c < argc; c++) { |
513 | if (strcmp("-to", argv[c]) == 0) | 533 | if (strcmp("-to", argv[c]) == 0) { |
514 | strcpy(argv[c], "-t"); | 534 | strcpy(argv[c], "-t"); |
515 | else if (strcmp("-wv", argv[c]) == 0) | 535 | } else if (strcmp("-wv", argv[c]) == 0) { |
516 | strcpy(argv[c], "-w"); | 536 | strcpy(argv[c], "-w"); |
517 | else if (strcmp("-cv", argv[c]) == 0) | 537 | } else if (strcmp("-cv", argv[c]) == 0) { |
518 | strcpy(argv[c], "-c"); | 538 | strcpy(argv[c], "-c"); |
539 | } | ||
519 | } | 540 | } |
520 | 541 | ||
521 | while (1) { | 542 | while (1) { |
522 | c = getopt_long(argc, argv, "+hVH:t:c:w:p:v:l:s:d:u", longopts, &option); | 543 | c = getopt_long(argc, argv, "+hVH:t:c:w:p:v:l:s:d:u", longopts, &option); |
523 | 544 | ||
524 | if (c == -1 || c == EOF || c == 1) | 545 | if (c == -1 || c == EOF || c == 1) { |
525 | break; | 546 | break; |
547 | } | ||
526 | 548 | ||
527 | switch (c) { | 549 | switch (c) { |
528 | case '?': /* print short usage statement if args not parsable */ | 550 | case '?': /* print short usage statement if args not parsable */ |
@@ -540,36 +562,39 @@ int process_arguments(int argc, char **argv) { | |||
540 | req_password = optarg; | 562 | req_password = optarg; |
541 | break; | 563 | break; |
542 | case 'p': /* port */ | 564 | case 'p': /* port */ |
543 | if (is_intnonneg(optarg)) | 565 | if (is_intnonneg(optarg)) { |
544 | server_port = atoi(optarg); | 566 | server_port = atoi(optarg); |
545 | else | 567 | } else { |
546 | die(STATE_UNKNOWN, _("Server port must be an integer\n")); | 568 | die(STATE_UNKNOWN, _("Server port must be an integer\n")); |
569 | } | ||
547 | break; | 570 | break; |
548 | case 'v': | 571 | case 'v': |
549 | if (strlen(optarg) < 4) | 572 | if (strlen(optarg) < 4) { |
550 | return ERROR; | 573 | return ERROR; |
551 | if (!strcmp(optarg, "CLIENTVERSION")) | 574 | } |
575 | if (!strcmp(optarg, "CLIENTVERSION")) { | ||
552 | vars_to_check = CHECK_CLIENTVERSION; | 576 | vars_to_check = CHECK_CLIENTVERSION; |
553 | else if (!strcmp(optarg, "CPULOAD")) | 577 | } else if (!strcmp(optarg, "CPULOAD")) { |
554 | vars_to_check = CHECK_CPULOAD; | 578 | vars_to_check = CHECK_CPULOAD; |
555 | else if (!strcmp(optarg, "UPTIME")) | 579 | } else if (!strcmp(optarg, "UPTIME")) { |
556 | vars_to_check = CHECK_UPTIME; | 580 | vars_to_check = CHECK_UPTIME; |
557 | else if (!strcmp(optarg, "USEDDISKSPACE")) | 581 | } else if (!strcmp(optarg, "USEDDISKSPACE")) { |
558 | vars_to_check = CHECK_USEDDISKSPACE; | 582 | vars_to_check = CHECK_USEDDISKSPACE; |
559 | else if (!strcmp(optarg, "SERVICESTATE")) | 583 | } else if (!strcmp(optarg, "SERVICESTATE")) { |
560 | vars_to_check = CHECK_SERVICESTATE; | 584 | vars_to_check = CHECK_SERVICESTATE; |
561 | else if (!strcmp(optarg, "PROCSTATE")) | 585 | } else if (!strcmp(optarg, "PROCSTATE")) { |
562 | vars_to_check = CHECK_PROCSTATE; | 586 | vars_to_check = CHECK_PROCSTATE; |
563 | else if (!strcmp(optarg, "MEMUSE")) | 587 | } else if (!strcmp(optarg, "MEMUSE")) { |
564 | vars_to_check = CHECK_MEMUSE; | 588 | vars_to_check = CHECK_MEMUSE; |
565 | else if (!strcmp(optarg, "COUNTER")) | 589 | } else if (!strcmp(optarg, "COUNTER")) { |
566 | vars_to_check = CHECK_COUNTER; | 590 | vars_to_check = CHECK_COUNTER; |
567 | else if (!strcmp(optarg, "FILEAGE")) | 591 | } else if (!strcmp(optarg, "FILEAGE")) { |
568 | vars_to_check = CHECK_FILEAGE; | 592 | vars_to_check = CHECK_FILEAGE; |
569 | else if (!strcmp(optarg, "INSTANCES")) | 593 | } else if (!strcmp(optarg, "INSTANCES")) { |
570 | vars_to_check = CHECK_INSTANCES; | 594 | vars_to_check = CHECK_INSTANCES; |
571 | else | 595 | } else { |
572 | return ERROR; | 596 | return ERROR; |
597 | } | ||
573 | break; | 598 | break; |
574 | case 'l': /* value list */ | 599 | case 'l': /* value list */ |
575 | value_list = optarg; | 600 | value_list = optarg; |
@@ -583,26 +608,31 @@ int process_arguments(int argc, char **argv) { | |||
583 | check_critical_value = true; | 608 | check_critical_value = true; |
584 | break; | 609 | break; |
585 | case 'd': /* Display select for services */ | 610 | case 'd': /* Display select for services */ |
586 | if (!strcmp(optarg, "SHOWALL")) | 611 | if (!strcmp(optarg, "SHOWALL")) { |
587 | show_all = true; | 612 | show_all = true; |
613 | } | ||
588 | break; | 614 | break; |
589 | case 'u': | 615 | case 'u': |
590 | socket_timeout_state = STATE_UNKNOWN; | 616 | socket_timeout_state = STATE_UNKNOWN; |
591 | break; | 617 | break; |
592 | case 't': /* timeout */ | 618 | case 't': /* timeout */ |
593 | socket_timeout = atoi(optarg); | 619 | socket_timeout = atoi(optarg); |
594 | if (socket_timeout <= 0) | 620 | if (socket_timeout <= 0) { |
595 | return ERROR; | 621 | return ERROR; |
622 | } | ||
596 | } | 623 | } |
597 | } | 624 | } |
598 | if (server_address == NULL) | 625 | if (server_address == NULL) { |
599 | usage4(_("You must provide a server address or host name")); | 626 | usage4(_("You must provide a server address or host name")); |
627 | } | ||
600 | 628 | ||
601 | if (vars_to_check == CHECK_NONE) | 629 | if (vars_to_check == CHECK_NONE) { |
602 | return ERROR; | 630 | return ERROR; |
631 | } | ||
603 | 632 | ||
604 | if (req_password == NULL) | 633 | if (req_password == NULL) { |
605 | req_password = strdup(_("None")); | 634 | req_password = strdup(_("None")); |
635 | } | ||
606 | 636 | ||
607 | return OK; | 637 | return OK; |
608 | } | 638 | } |
@@ -612,11 +642,13 @@ void fetch_data(const char *address, int port, const char *sendb) { | |||
612 | 642 | ||
613 | result = process_tcp_request(address, port, sendb, recv_buffer, sizeof(recv_buffer)); | 643 | result = process_tcp_request(address, port, sendb, recv_buffer, sizeof(recv_buffer)); |
614 | 644 | ||
615 | if (result != STATE_OK) | 645 | if (result != STATE_OK) { |
616 | die(result, _("could not fetch information from server\n")); | 646 | die(result, _("could not fetch information from server\n")); |
647 | } | ||
617 | 648 | ||
618 | if (!strncmp(recv_buffer, "ERROR", 5)) | 649 | if (!strncmp(recv_buffer, "ERROR", 5)) { |
619 | die(STATE_UNKNOWN, "NSClient - %s\n", recv_buffer); | 650 | die(STATE_UNKNOWN, "NSClient - %s\n", recv_buffer); |
651 | } | ||
620 | } | 652 | } |
621 | 653 | ||
622 | bool strtoularray(unsigned long *array, char *string, const char *delim) { | 654 | bool strtoularray(unsigned long *array, char *string, const char *delim) { |
@@ -624,16 +656,18 @@ bool strtoularray(unsigned long *array, char *string, const char *delim) { | |||
624 | int idx = 0; | 656 | int idx = 0; |
625 | char *t1; | 657 | char *t1; |
626 | 658 | ||
627 | for (idx = 0; idx < MAX_VALUE_LIST; idx++) | 659 | for (idx = 0; idx < MAX_VALUE_LIST; idx++) { |
628 | array[idx] = 0; | 660 | array[idx] = 0; |
661 | } | ||
629 | 662 | ||
630 | idx = 0; | 663 | idx = 0; |
631 | for (t1 = strtok(string, delim); t1 != NULL; t1 = strtok(NULL, delim)) { | 664 | for (t1 = strtok(string, delim); t1 != NULL; t1 = strtok(NULL, delim)) { |
632 | if (is_numeric(t1) && idx < MAX_VALUE_LIST) { | 665 | if (is_numeric(t1) && idx < MAX_VALUE_LIST) { |
633 | array[idx] = strtoul(t1, NULL, 10); | 666 | array[idx] = strtoul(t1, NULL, 10); |
634 | idx++; | 667 | idx++; |
635 | } else | 668 | } else { |
636 | return false; | 669 | return false; |
670 | } | ||
637 | } | 671 | } |
638 | return true; | 672 | return true; |
639 | } | 673 | } |
@@ -642,10 +676,11 @@ void preparelist(char *string) { | |||
642 | /* Replace all , with & which is the delimiter for the request */ | 676 | /* Replace all , with & which is the delimiter for the request */ |
643 | int i; | 677 | int i; |
644 | 678 | ||
645 | for (i = 0; (size_t)i < strlen(string); i++) | 679 | for (i = 0; (size_t)i < strlen(string); i++) { |
646 | if (string[i] == ',') { | 680 | if (string[i] == ',') { |
647 | string[i] = '&'; | 681 | string[i] = '&'; |
648 | } | 682 | } |
683 | } | ||
649 | } | 684 | } |
650 | 685 | ||
651 | void print_help(void) { | 686 | void print_help(void) { |