summaryrefslogtreecommitdiffstats
path: root/plugins/check_ping.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_ping.c')
-rw-r--r--plugins/check_ping.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index 87f9db01..7d9dd3bf 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -37,7 +37,8 @@ enum {
37int process_arguments (int, char **); 37int process_arguments (int, char **);
38int get_threshold (char *, float *, int *); 38int get_threshold (char *, float *, int *);
39int validate_arguments (void); 39int validate_arguments (void);
40int run_ping (char *, char *); 40int run_ping (const char *cmd, const char *addr);
41int error_scan (char buf[MAX_INPUT_BUFFER], const char *addr);
41void print_usage (void); 42void print_usage (void);
42void print_help (void); 43void print_help (void);
43 44
@@ -394,7 +395,7 @@ validate_arguments ()
394 395
395 396
396int 397int
397run_ping (char *cmd, char *server_address) 398run_ping (const char *cmd, const char *addr)
398{ 399{
399 char buf[MAX_INPUT_BUFFER]; 400 char buf[MAX_INPUT_BUFFER];
400 int result = STATE_UNKNOWN; 401 int result = STATE_UNKNOWN;
@@ -408,12 +409,7 @@ run_ping (char *cmd, char *server_address)
408 409
409 while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) { 410 while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
410 411
411 if (strstr (buf, _("(DUP!)"))) { 412 result = max_state (result, error_scan (buf, addr));
412 result = max_state (result, STATE_WARNING);
413 warn_text = strdup (WARN_DUPLICATES);
414 if (!warn_text)
415 die (STATE_UNKNOWN, _("unable to realloc warn_text"));
416 }
417 413
418 /* get the percent loss statistics */ 414 /* get the percent loss statistics */
419 if(sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss",&pl)==1 || 415 if(sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss",&pl)==1 ||
@@ -438,34 +434,11 @@ run_ping (char *cmd, char *server_address)
438 if (pl == 100) 434 if (pl == 100)
439 rta = crta; 435 rta = crta;
440 436
441 /* check stderr */ 437 /* check stderr, setting at least WARNING if there is output here */
442 while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) { 438 while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
443 if (strstr(buf,"Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP")) 439 if (! strstr(buf,"Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP"))
444 continue; 440 result = max_state (STATE_WARNING, error_scan (buf, addr));
445
446 if (strstr (buf, "Network is unreachable"))
447 die (STATE_CRITICAL,
448 _("PING CRITICAL - Network unreachable (%s)"),
449 server_address);
450 else if (strstr (buf, "Destination Host Unreachable"))
451 die (STATE_CRITICAL,
452 _("PING CRITICAL - Host Unreachable (%s)"),
453 server_address);
454 else if (strstr (buf, "unknown host" ))
455 die (STATE_CRITICAL,
456 _("PING CRITICAL - Host not found (%s)"),
457 server_address);
458 441
459 if (warn_text == NULL)
460 warn_text = strdup (buf);
461 else if (asprintf (&warn_text, "%s %s", warn_text, buf) == -1)
462 die (STATE_UNKNOWN, _("unable to realloc warn_text"));
463
464 if (strstr (buf, "DUPLICATES FOUND"))
465 result = max_state (result, STATE_WARNING);
466 else
467 result = STATE_CRITICAL ;
468 }
469 (void) fclose (child_stderr); 442 (void) fclose (child_stderr);
470 443
471 444
@@ -483,6 +456,32 @@ run_ping (char *cmd, char *server_address)
483 456
484 457
485 458
459int
460error_scan (char buf[MAX_INPUT_BUFFER], const char *addr)
461{
462 if (strstr (buf, "Network is unreachable"))
463 die (STATE_CRITICAL, _("PING CRITICAL - Network unreachable (%s)"), addr);
464 else if (strstr (buf, "Destination Host Unreachable"))
465 die (STATE_CRITICAL, _("PING CRITICAL - Host Unreachable (%s)"), addr);
466 else if (strstr (buf, "unknown host" ))
467 die (STATE_CRITICAL, _("PING CRITICAL - Host not found (%s)"), addr);
468
469 if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) {
470 if (warn_text == NULL)
471 warn_text = strdup (_(WARN_DUPLICATES));
472 else if (! strstr (warn_text, _(WARN_DUPLICATES)) &&
473 asprintf (&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1)
474 die (STATE_UNKNOWN, _("unable to realloc warn_text"));
475 return (STATE_WARNING);
476 }
477
478 return (STATE_OK);
479}
480
481
482
483
484
486 485
487void 486void
488print_usage (void) 487print_usage (void)