diff options
Diffstat (limited to 'plugins/check_ping.c')
| -rw-r--r-- | plugins/check_ping.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 074519d3..260e1b65 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
| @@ -14,6 +14,8 @@ | |||
| 14 | along with this program; if not, write to the Free Software | 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 16 | 16 | ||
| 17 | $Id$ | ||
| 18 | |||
| 17 | ******************************************************************************/ | 19 | ******************************************************************************/ |
| 18 | 20 | ||
| 19 | const char *progname = "check_ping"; | 21 | const char *progname = "check_ping"; |
| @@ -60,8 +62,6 @@ char *warn_text; | |||
| 60 | 62 | ||
| 61 | 63 | ||
| 62 | 64 | ||
| 63 | |||
| 64 | |||
| 65 | int | 65 | int |
| 66 | main (int argc, char **argv) | 66 | main (int argc, char **argv) |
| 67 | { | 67 | { |
| @@ -79,7 +79,7 @@ main (int argc, char **argv) | |||
| 79 | addresses[0] = NULL; | 79 | addresses[0] = NULL; |
| 80 | 80 | ||
| 81 | if (process_arguments (argc, argv) == ERROR) | 81 | if (process_arguments (argc, argv) == ERROR) |
| 82 | usage (_("Could not parse arguments")); | 82 | usage (_("check_ping: could not parse arguments\n")); |
| 83 | 83 | ||
| 84 | /* Set signal handling and alarm */ | 84 | /* Set signal handling and alarm */ |
| 85 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { | 85 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { |
| @@ -159,9 +159,6 @@ main (int argc, char **argv) | |||
| 159 | 159 | ||
| 160 | 160 | ||
| 161 | 161 | ||
| 162 | |||
| 163 | |||
| 164 | |||
| 165 | /* process command-line arguments */ | 162 | /* process command-line arguments */ |
| 166 | int | 163 | int |
| 167 | process_arguments (int argc, char **argv) | 164 | process_arguments (int argc, char **argv) |
| @@ -198,8 +195,9 @@ process_arguments (int argc, char **argv) | |||
| 198 | 195 | ||
| 199 | switch (c) { | 196 | switch (c) { |
| 200 | case '?': /* usage */ | 197 | case '?': /* usage */ |
| 201 | usage3 (_("Unknown argument"), optopt); | 198 | printf (_("%s: Unknown argument: %s\n\n"), progname, optarg); |
| 202 | break; | 199 | print_usage (); |
| 200 | exit (STATE_UNKNOWN); | ||
| 203 | case 'h': /* help */ | 201 | case 'h': /* help */ |
| 204 | print_help (); | 202 | print_help (); |
| 205 | exit (STATE_OK); | 203 | exit (STATE_OK); |
| @@ -270,7 +268,7 @@ process_arguments (int argc, char **argv) | |||
| 270 | 268 | ||
| 271 | if (addresses[0] == NULL) { | 269 | if (addresses[0] == NULL) { |
| 272 | if (is_host (argv[c]) == FALSE) { | 270 | if (is_host (argv[c]) == FALSE) { |
| 273 | usage2 (_("Invalid host name/address"), argv[c]); | 271 | usage2 (_("Invalid hostname/address"), argv[c]); |
| 274 | } else { | 272 | } else { |
| 275 | addresses[0] = argv[c++]; | 273 | addresses[0] = argv[c++]; |
| 276 | n_addresses++; | 274 | n_addresses++; |
| @@ -335,6 +333,8 @@ process_arguments (int argc, char **argv) | |||
| 335 | return validate_arguments (); | 333 | return validate_arguments (); |
| 336 | } | 334 | } |
| 337 | 335 | ||
| 336 | |||
| 337 | |||
| 338 | int | 338 | int |
| 339 | get_threshold (char *arg, float *trta, int *tpl) | 339 | get_threshold (char *arg, float *trta, int *tpl) |
| 340 | { | 340 | { |
| @@ -349,6 +349,8 @@ get_threshold (char *arg, float *trta, int *tpl) | |||
| 349 | return STATE_UNKNOWN; | 349 | return STATE_UNKNOWN; |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | |||
| 353 | |||
| 352 | int | 354 | int |
| 353 | validate_arguments () | 355 | validate_arguments () |
| 354 | { | 356 | { |
| @@ -389,7 +391,7 @@ validate_arguments () | |||
| 389 | 391 | ||
| 390 | for (i=0; i<n_addresses; i++) { | 392 | for (i=0; i<n_addresses; i++) { |
| 391 | if (is_host(addresses[i]) == FALSE) | 393 | if (is_host(addresses[i]) == FALSE) |
| 392 | usage2 (_("Invalid host name/address"), addresses[i]); | 394 | usage2 (_("Invalid hostname/address"), addresses[i]); |
| 393 | } | 395 | } |
| 394 | 396 | ||
| 395 | return OK; | 397 | return OK; |
| @@ -397,9 +399,6 @@ validate_arguments () | |||
| 397 | 399 | ||
| 398 | 400 | ||
| 399 | 401 | ||
| 400 | |||
| 401 | |||
| 402 | |||
| 403 | int | 402 | int |
| 404 | run_ping (const char *cmd, const char *addr) | 403 | run_ping (const char *cmd, const char *addr) |
| 405 | { | 404 | { |
| @@ -444,7 +443,7 @@ run_ping (const char *cmd, const char *addr) | |||
| 444 | 443 | ||
| 445 | /* check stderr, setting at least WARNING if there is output here */ | 444 | /* check stderr, setting at least WARNING if there is output here */ |
| 446 | while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) | 445 | while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) |
| 447 | if (! strstr(buf,"Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP")) | 446 | if (! strstr(buf,"WARNING - no SO_TIMESTAMP support, falling back to SIOCGSTAMP")) |
| 448 | result = max_state (STATE_WARNING, error_scan (buf, addr)); | 447 | result = max_state (STATE_WARNING, error_scan (buf, addr)); |
| 449 | 448 | ||
| 450 | (void) fclose (child_stderr); | 449 | (void) fclose (child_stderr); |
| @@ -462,17 +461,15 @@ run_ping (const char *cmd, const char *addr) | |||
| 462 | 461 | ||
| 463 | 462 | ||
| 464 | 463 | ||
| 465 | |||
| 466 | |||
| 467 | int | 464 | int |
| 468 | error_scan (char buf[MAX_INPUT_BUFFER], const char *addr) | 465 | error_scan (char buf[MAX_INPUT_BUFFER], const char *addr) |
| 469 | { | 466 | { |
| 470 | if (strstr (buf, "Network is unreachable")) | 467 | if (strstr (buf, "Network is unreachable")) |
| 471 | die (STATE_CRITICAL, _("PING CRITICAL - Network unreachable (%s)"), addr); | 468 | die (STATE_CRITICAL, _("CRITICAL - Network unreachable (%s)"), addr); |
| 472 | else if (strstr (buf, "Destination Host Unreachable")) | 469 | else if (strstr (buf, "Destination Host Unreachable")) |
| 473 | die (STATE_CRITICAL, _("PING CRITICAL - Host Unreachable (%s)"), addr); | 470 | die (STATE_CRITICAL, _("CRITICAL - Host Unreachable (%s)"), addr); |
| 474 | else if (strstr (buf, "unknown host" )) | 471 | else if (strstr (buf, "unknown host" )) |
| 475 | die (STATE_CRITICAL, _("PING CRITICAL - Host not found (%s)"), addr); | 472 | die (STATE_CRITICAL, _("CRITICAL - Host not found (%s)"), addr); |
| 476 | 473 | ||
| 477 | if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) { | 474 | if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) { |
| 478 | if (warn_text == NULL) | 475 | if (warn_text == NULL) |
| @@ -488,9 +485,6 @@ error_scan (char buf[MAX_INPUT_BUFFER], const char *addr) | |||
| 488 | 485 | ||
| 489 | 486 | ||
| 490 | 487 | ||
| 491 | |||
| 492 | |||
| 493 | |||
| 494 | void | 488 | void |
| 495 | print_usage (void) | 489 | print_usage (void) |
| 496 | { | 490 | { |
| @@ -500,6 +494,8 @@ print_usage (void) | |||
| 500 | printf (_(UT_HLP_VRS), progname, progname); | 494 | printf (_(UT_HLP_VRS), progname, progname); |
| 501 | } | 495 | } |
| 502 | 496 | ||
| 497 | |||
| 498 | |||
| 503 | void | 499 | void |
| 504 | print_help (void) | 500 | print_help (void) |
| 505 | { | 501 | { |
