X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fcheck_ping.c;h=6b566608961059c90c8206a8ee94fdcdca347cf9;hb=20d0154211fa46028383ed3a88b558731313c389;hp=132453d26ed64e2b778324a7387592b883aff51a;hpb=83df67099daebd7189ad0417089040f3b2de27c1;p=nagiosplug.git diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 132453d..6b56660 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c @@ -53,7 +53,7 @@ char **addresses = NULL; int n_addresses; int max_addr = 1; int max_packets = -1; -int verbose = FALSE; +int verbose = 0; float rta = UNKNOWN_TRIP_TIME; int pl = UNKNOWN_PACKET_LOSS; @@ -72,13 +72,14 @@ main (int argc, char **argv) int i; setlocale (LC_ALL, ""); + setlocale (LC_NUMERIC, "C"); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); addresses = malloc (sizeof(char*) * max_addr); addresses[0] = NULL; - if (process_arguments (argc, argv) != TRUE) + if (process_arguments (argc, argv) == ERROR) usage4 (_("Could not parse arguments")); /* Set signal handling and alarm */ @@ -111,8 +112,8 @@ main (int argc, char **argv) asprintf (&cmd, rawcmd, addresses[i], max_packets); #endif - if (verbose) - printf ("%s ==> ", cmd); + if (verbose >= 2) + printf ("CMD: %s\n", cmd); /* run the command */ this_result = run_ping (cmd, addresses[i]); @@ -145,7 +146,7 @@ main (int argc, char **argv) printf (""); printf ("\n"); - if (verbose) + if (verbose >= 2) printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl); result = max_state (result, this_result); @@ -194,9 +195,7 @@ process_arguments (int argc, char **argv) switch (c) { case '?': /* usage */ - printf (_("%s: Unknown argument: %s\n\n"), progname, optarg); - print_usage (); - exit (STATE_UNKNOWN); + usage2 (_("Unknown argument"), optarg); case 'h': /* help */ print_help (); exit (STATE_OK); @@ -209,7 +208,7 @@ process_arguments (int argc, char **argv) timeout_interval = atoi (optarg); break; case 'v': /* verbose mode */ - verbose = TRUE; + verbose++; break; case '4': /* IPv4 only */ address_family = AF_INET; @@ -405,7 +404,7 @@ run_ping (const char *cmd, const char *addr) int result = STATE_UNKNOWN; if ((child_process = spopen (cmd)) == NULL) - die (STATE_UNKNOWN, _("Cannot open pipe: %s"), cmd); + die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd); child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); if (child_stderr == NULL) @@ -413,15 +412,22 @@ run_ping (const char *cmd, const char *addr) while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) { + if (verbose >= 3) + printf("Output: %s", buf); + result = max_state (result, error_scan (buf, addr)); /* get the percent loss statistics */ if(sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss",&pl)==1 || - sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss",&pl)==1 || + sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss", &pl) == 1 || + sscanf(buf,"%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss", &pl) == 1 || + sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss",&pl)==1 || sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% loss, time",&pl)==1 || sscanf(buf,"%*d packets transmitted, %*d received, %d%% loss, time", &pl)==1 || sscanf(buf,"%*d packets transmitted, %*d received, %d%% packet loss, time", &pl)==1 || - sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss", &pl) == 1) + sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss", &pl) == 1 || + sscanf(buf,"%*d packets transmitted %*d received, +%*d errors, %d%% packet loss", &pl) == 1 + ) continue; /* get the round trip average */ @@ -432,6 +438,7 @@ run_ping (const char *cmd, const char *addr) sscanf(buf,"round-trip min/avg/max/stddev = %*f/%f/%*f/%*f",&rta)==1 || sscanf(buf,"round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f",&rta)==1 || sscanf(buf,"round-trip (ms) min/avg/max = %*f/%f/%*f",&rta)==1 || + sscanf(buf,"round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f",&rta)==1 || sscanf(buf,"rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms",&rta)==1) continue; } @@ -469,6 +476,8 @@ error_scan (char buf[MAX_INPUT_BUFFER], const char *addr) die (STATE_CRITICAL, _("CRITICAL - Host Unreachable (%s)"), addr); else if (strstr (buf, "unknown host" )) die (STATE_CRITICAL, _("CRITICAL - Host not found (%s)"), addr); + else if (strstr (buf, "Time to live exceeded")) + die (STATE_CRITICAL, _("CRITICAL - Time to live exceeded (%s)"), addr); if (strstr (buf, "(DUP!)") || strstr (buf, "DUPLICATES FOUND")) { if (warn_text == NULL) @@ -484,17 +493,6 @@ error_scan (char buf[MAX_INPUT_BUFFER], const char *addr) -void -print_usage (void) -{ - printf (\ -"Usage: %s -H -w ,%% -c ,%%\n\ - [-p packets] [-t timeout] [-L] [-4|-6]\n", progname); - printf (_(UT_HLP_VRS), progname, progname); -} - - - void print_help (void) { @@ -539,3 +537,10 @@ the contrib area of the downloads section at http://www.nagios.org\n\n")); printf (_(UT_SUPPORT)); } + +void +print_usage (void) +{ + printf ("Usage: %s -H -w ,%% -c ,%%\n\ + [-p packets] [-t timeout] [-L] [-4|-6]\n", progname); +}