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.c72
1 files changed, 37 insertions, 35 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index ecdd618..eef2195 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -121,12 +121,12 @@ main (int argc, char **argv)
121 /* does the host address of number of packets argument come first? */ 121 /* does the host address of number of packets argument come first? */
122#ifdef PING_PACKETS_FIRST 122#ifdef PING_PACKETS_FIRST
123# ifdef PING_HAS_TIMEOUT 123# ifdef PING_HAS_TIMEOUT
124 asprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]); 124 xasprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]);
125# else 125# else
126 asprintf (&cmd, rawcmd, max_packets, addresses[i]); 126 xasprintf (&cmd, rawcmd, max_packets, addresses[i]);
127# endif 127# endif
128#else 128#else
129 asprintf (&cmd, rawcmd, addresses[i], max_packets); 129 xasprintf (&cmd, rawcmd, addresses[i], max_packets);
130#endif 130#endif
131 131
132 if (verbose >= 2) 132 if (verbose >= 2)
@@ -432,6 +432,7 @@ run_ping (const char *cmd, const char *addr)
432{ 432{
433 char buf[MAX_INPUT_BUFFER]; 433 char buf[MAX_INPUT_BUFFER];
434 int result = STATE_UNKNOWN; 434 int result = STATE_UNKNOWN;
435 int match;
435 436
436 if ((child_process = spopen (cmd)) == NULL) 437 if ((child_process = spopen (cmd)) == NULL)
437 die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd); 438 die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd);
@@ -448,28 +449,29 @@ run_ping (const char *cmd, const char *addr)
448 result = max_state (result, error_scan (buf, addr)); 449 result = max_state (result, error_scan (buf, addr));
449 450
450 /* get the percent loss statistics */ 451 /* get the percent loss statistics */
451 if(sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss",&pl)==1 || 452 match = 0;
452 sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss", &pl) == 1 || 453 if((sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n",&pl,&match) && match) ||
453 sscanf(buf,"%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss", &pl) == 1 || 454 (sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss%n",&pl,&match) && match) ||
454 sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss",&pl)==1 || 455 (sscanf(buf,"%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n",&pl,&match) && match) ||
455 sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% loss, time",&pl)==1 || 456 (sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss%n",&pl,&match) && match) ||
456 sscanf(buf,"%*d packets transmitted, %*d received, %d%% loss, time", &pl)==1 || 457 (sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% loss, time%n",&pl,&match) && match) ||
457 sscanf(buf,"%*d packets transmitted, %*d received, %d%% packet loss, time", &pl)==1 || 458 (sscanf(buf,"%*d packets transmitted, %*d received, %d%% loss, time%n",&pl,&match) && match) ||
458 sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss", &pl) == 1 || 459 (sscanf(buf,"%*d packets transmitted, %*d received, %d%% packet loss, time%n",&pl,&match) && match) ||
459 sscanf(buf,"%*d packets transmitted %*d received, +%*d errors, %d%% packet loss", &pl) == 1 460 (sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n",&pl,&match) && match) ||
461 (sscanf(buf,"%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n",&pl,&match) && match)
460 ) 462 )
461 continue; 463 continue;
462 464
463 /* get the round trip average */ 465 /* get the round trip average */
464 else 466 else
465 if(sscanf(buf,"round-trip min/avg/max = %*f/%f/%*f",&rta)==1 || 467 if((sscanf(buf,"round-trip min/avg/max = %*f/%f/%*f%n",&rta,&match) && match) ||
466 sscanf(buf,"round-trip min/avg/max/mdev = %*f/%f/%*f/%*f",&rta)==1 || 468 (sscanf(buf,"round-trip min/avg/max/mdev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
467 sscanf(buf,"round-trip min/avg/max/sdev = %*f/%f/%*f/%*f",&rta)==1 || 469 (sscanf(buf,"round-trip min/avg/max/sdev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
468 sscanf(buf,"round-trip min/avg/max/stddev = %*f/%f/%*f/%*f",&rta)==1 || 470 (sscanf(buf,"round-trip min/avg/max/stddev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
469 sscanf(buf,"round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f",&rta)==1 || 471 (sscanf(buf,"round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
470 sscanf(buf,"round-trip (ms) min/avg/max = %*f/%f/%*f",&rta)==1 || 472 (sscanf(buf,"round-trip (ms) min/avg/max = %*f/%f/%*f%n",&rta,&match) && match) ||
471 sscanf(buf,"round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f",&rta)==1 || 473 (sscanf(buf,"round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
472 sscanf(buf,"rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms",&rta)==1) 474 (sscanf(buf,"rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms%n",&rta,&match) && match))
473 continue; 475 continue;
474 } 476 }
475 477
@@ -489,7 +491,7 @@ run_ping (const char *cmd, const char *addr)
489 if (warn_text == NULL) { 491 if (warn_text == NULL) {
490 warn_text = strdup(_("System call sent warnings to stderr ")); 492 warn_text = strdup(_("System call sent warnings to stderr "));
491 } else { 493 } else {
492 asprintf(&warn_text, "%s %s", warn_text, _("System call sent warnings to stderr ")); 494 xasprintf(&warn_text, "%s %s", warn_text, _("System call sent warnings to stderr "));
493 } 495 }
494 } 496 }
495 } 497 }
@@ -498,9 +500,7 @@ run_ping (const char *cmd, const char *addr)
498 (void) fclose (child_stderr); 500 (void) fclose (child_stderr);
499 501
500 502
501 /* close the pipe - WARNING if status is set */ 503 spclose (child_process);
502 if (spclose (child_process))
503 result = max_state (result, STATE_WARNING);
504 504
505 if (warn_text == NULL) 505 if (warn_text == NULL)
506 warn_text = strdup(""); 506 warn_text = strdup("");
@@ -516,30 +516,32 @@ error_scan (char buf[MAX_INPUT_BUFFER], const char *addr)
516 if (strstr (buf, "Network is unreachable") || 516 if (strstr (buf, "Network is unreachable") ||
517 strstr (buf, "Destination Net Unreachable") 517 strstr (buf, "Destination Net Unreachable")
518 ) 518 )
519 die (STATE_CRITICAL, _("CRITICAL - Network Unreachable (%s)"), addr); 519 die (STATE_CRITICAL, _("CRITICAL - Network Unreachable (%s)\n"), addr);
520 else if (strstr (buf, "Destination Host Unreachable")) 520 else if (strstr (buf, "Destination Host Unreachable"))
521 die (STATE_CRITICAL, _("CRITICAL - Host Unreachable (%s)"), addr); 521 die (STATE_CRITICAL, _("CRITICAL - Host Unreachable (%s)\n"), addr);
522 else if (strstr (buf, "Destination Port Unreachable")) 522 else if (strstr (buf, "Destination Port Unreachable"))
523 die (STATE_CRITICAL, _("CRITICAL - Bogus ICMP: Port Unreachable (%s)"), addr); 523 die (STATE_CRITICAL, _("CRITICAL - Bogus ICMP: Port Unreachable (%s)\n"), addr);
524 else if (strstr (buf, "Destination Protocol Unreachable")) 524 else if (strstr (buf, "Destination Protocol Unreachable"))
525 die (STATE_CRITICAL, _("CRITICAL - Bogus ICMP: Protocol Unreachable (%s)"), addr); 525 die (STATE_CRITICAL, _("CRITICAL - Bogus ICMP: Protocol Unreachable (%s)\n"), addr);
526 else if (strstr (buf, "Destination Net Prohibited")) 526 else if (strstr (buf, "Destination Net Prohibited"))
527 die (STATE_CRITICAL, _("CRITICAL - Network Prohibited (%s)"), addr); 527 die (STATE_CRITICAL, _("CRITICAL - Network Prohibited (%s)\n"), addr);
528 else if (strstr (buf, "Destination Host Prohibited")) 528 else if (strstr (buf, "Destination Host Prohibited"))
529 die (STATE_CRITICAL, _("CRITICAL - Host Prohibited (%s)"), addr); 529 die (STATE_CRITICAL, _("CRITICAL - Host Prohibited (%s)\n"), addr);
530 else if (strstr (buf, "Packet filtered")) 530 else if (strstr (buf, "Packet filtered"))
531 die (STATE_CRITICAL, _("CRITICAL - Packet Filtered (%s)"), addr); 531 die (STATE_CRITICAL, _("CRITICAL - Packet Filtered (%s)\n"), addr);
532 else if (strstr (buf, "unknown host" )) 532 else if (strstr (buf, "unknown host" ))
533 die (STATE_CRITICAL, _("CRITICAL - Host not found (%s)"), addr); 533 die (STATE_CRITICAL, _("CRITICAL - Host not found (%s)\n"), addr);
534 else if (strstr (buf, "Time to live exceeded")) 534 else if (strstr (buf, "Time to live exceeded"))
535 die (STATE_CRITICAL, _("CRITICAL - Time to live exceeded (%s)"), addr); 535 die (STATE_CRITICAL, _("CRITICAL - Time to live exceeded (%s)\n"), addr);
536 else if (strstr (buf, "Destination unreachable: "))
537 die (STATE_CRITICAL, _("CRITICAL - Destination Unreachable (%s)\n"), addr);
536 538
537 if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) { 539 if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) {
538 if (warn_text == NULL) 540 if (warn_text == NULL)
539 warn_text = strdup (_(WARN_DUPLICATES)); 541 warn_text = strdup (_(WARN_DUPLICATES));
540 else if (! strstr (warn_text, _(WARN_DUPLICATES)) && 542 else if (! strstr (warn_text, _(WARN_DUPLICATES)) &&
541 asprintf (&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1) 543 xasprintf (&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1)
542 die (STATE_UNKNOWN, _("Unable to realloc warn_text")); 544 die (STATE_UNKNOWN, _("Unable to realloc warn_text\n"));
543 return (STATE_WARNING); 545 return (STATE_WARNING);
544 } 546 }
545 547