diff options
Diffstat (limited to 'plugins/check_fping.c')
| -rw-r--r-- | plugins/check_fping.c | 53 | 
1 files changed, 21 insertions, 32 deletions
| diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 4dc48b77..8114b36f 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
| @@ -60,7 +60,6 @@ void print_usage (void); | |||
| 60 | char *server_name = NULL; | 60 | char *server_name = NULL; | 
| 61 | int packet_size = PACKET_SIZE; | 61 | int packet_size = PACKET_SIZE; | 
| 62 | int packet_count = PACKET_COUNT; | 62 | int packet_count = PACKET_COUNT; | 
| 63 | int verbose = FALSE; | ||
| 64 | int cpl; | 63 | int cpl; | 
| 65 | int wpl; | 64 | int wpl; | 
| 66 | double crta; | 65 | double crta; | 
| @@ -81,6 +80,7 @@ main (int argc, char **argv) | |||
| 81 | char *input_buffer = NULL; | 80 | char *input_buffer = NULL; | 
| 82 | input_buffer = malloc (MAX_INPUT_BUFFER); | 81 | input_buffer = malloc (MAX_INPUT_BUFFER); | 
| 83 | 82 | ||
| 83 | np_set_mynames(argv[0], "FPING"); | ||
| 84 | setlocale (LC_ALL, ""); | 84 | setlocale (LC_ALL, ""); | 
| 85 | bindtextdomain (PACKAGE, LOCALEDIR); | 85 | bindtextdomain (PACKAGE, LOCALEDIR); | 
| 86 | textdomain (PACKAGE); | 86 | textdomain (PACKAGE); | 
| @@ -94,32 +94,26 @@ main (int argc, char **argv) | |||
| 94 | asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING, | 94 | asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING, | 
| 95 | packet_size, packet_count, server); | 95 | packet_size, packet_count, server); | 
| 96 | 96 | ||
| 97 | if (verbose) | 97 | np_verbatim(command_line); | 
| 98 | printf ("%s\n", command_line); | ||
| 99 | 98 | ||
| 100 | /* run the command */ | 99 | /* run the command */ | 
| 101 | child_process = spopen (command_line); | 100 | child_process = spopen (command_line); | 
| 102 | if (child_process == NULL) { | 101 | if (child_process == NULL) | 
| 103 | printf (_("Could not open pipe: %s\n"), command_line); | 102 | np_die(STATE_UNKNOWN, _("Could not open pipe: %s"), command_line); | 
| 104 | return STATE_UNKNOWN; | ||
| 105 | } | ||
| 106 | 103 | ||
| 107 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | 104 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | 
| 108 | if (child_stderr == NULL) { | 105 | if (child_stderr == NULL) | 
| 109 | printf (_("Could not open stderr for %s\n"), command_line); | 106 | printf (_("Could not open stderr for %s\n"), command_line); | 
| 110 | } | ||
| 111 | 107 | ||
| 112 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 108 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 
| 113 | if (verbose) | 109 | np_verbatim(input_buffer); | 
| 114 | printf ("%s", input_buffer); | ||
| 115 | status = max_state (status, textscan (input_buffer)); | 110 | status = max_state (status, textscan (input_buffer)); | 
| 116 | } | 111 | } | 
| 117 | 112 | ||
| 118 | /* If we get anything on STDERR, at least set warning */ | 113 | /* If we get anything on STDERR, at least set warning */ | 
| 119 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | 114 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | 
| 120 | status = max_state (status, STATE_WARNING); | 115 | status = max_state (status, STATE_WARNING); | 
| 121 | if (verbose) | 116 | np_verbatim(input_buffer); | 
| 122 | printf ("%s", input_buffer); | ||
| 123 | status = max_state (status, textscan (input_buffer)); | 117 | status = max_state (status, textscan (input_buffer)); | 
| 124 | } | 118 | } | 
| 125 | (void) fclose (child_stderr); | 119 | (void) fclose (child_stderr); | 
| @@ -129,9 +123,7 @@ main (int argc, char **argv) | |||
| 129 | /* need to use max_state not max */ | 123 | /* need to use max_state not max */ | 
| 130 | status = max_state (status, STATE_WARNING); | 124 | status = max_state (status, STATE_WARNING); | 
| 131 | 125 | ||
| 132 | printf ("FPING %s - %s\n", state_text (status), server_name); | 126 | np_die("%s", server_name); | 
| 133 | |||
| 134 | return status; | ||
| 135 | } | 127 | } | 
| 136 | 128 | ||
| 137 | 129 | ||
| @@ -146,16 +138,15 @@ textscan (char *buf) | |||
| 146 | int status = STATE_UNKNOWN; | 138 | int status = STATE_UNKNOWN; | 
| 147 | 139 | ||
| 148 | if (strstr (buf, "not found")) { | 140 | if (strstr (buf, "not found")) { | 
| 149 | die (STATE_CRITICAL, _("FPING UNKNOW - %s not found\n"), server_name); | 141 | np_die(STATE_UNKNOWN, _("%s not found"), server_name); | 
| 150 | 142 | ||
| 151 | } | 143 | } | 
| 152 | else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) { | 144 | else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) { | 
| 153 | die (STATE_CRITICAL, _("FPING CRITICAL - %s is unreachable\n"), | 145 | np_die(STATE_CRITICAL, _("%s is unreachable"), "host"); | 
| 154 | "host"); | ||
| 155 | 146 | ||
| 156 | } | 147 | } | 
| 157 | else if (strstr (buf, "is down")) { | 148 | else if (strstr (buf, "is down")) { | 
| 158 | die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name); | 149 | np_die(STATE_CRITICAL, _("%s is down"), server_name); | 
| 159 | 150 | ||
| 160 | } | 151 | } | 
| 161 | else if (strstr (buf, "is alive")) { | 152 | else if (strstr (buf, "is alive")) { | 
| @@ -181,9 +172,9 @@ textscan (char *buf) | |||
| 181 | status = STATE_WARNING; | 172 | status = STATE_WARNING; | 
| 182 | else | 173 | else | 
| 183 | status = STATE_OK; | 174 | status = STATE_OK; | 
| 184 | die (status, | 175 | np_die(status, | 
| 185 | _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), | 176 | _("- %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), | 
| 186 | state_text (status), server_name, loss, rta, | 177 | server_name, loss, rta, | 
| 187 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), | 178 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), | 
| 188 | fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); | 179 | fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); | 
| 189 | 180 | ||
| @@ -203,8 +194,8 @@ textscan (char *buf) | |||
| 203 | else | 194 | else | 
| 204 | status = STATE_OK; | 195 | status = STATE_OK; | 
| 205 | /* loss=%.0f%%;%d;%d;0;100 */ | 196 | /* loss=%.0f%%;%d;%d;0;100 */ | 
| 206 | die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"), | 197 | np_die(status, _("%s (loss=%.0f%% )|%s"), | 
| 207 | state_text (status), server_name, loss , | 198 | server_name, loss, | 
| 208 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100)); | 199 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100)); | 
| 209 | 200 | ||
| 210 | } | 201 | } | 
| @@ -266,7 +257,7 @@ process_arguments (int argc, char **argv) | |||
| 266 | print_revision (progname, revision); | 257 | print_revision (progname, revision); | 
| 267 | exit (STATE_OK); | 258 | exit (STATE_OK); | 
| 268 | case 'v': /* verbose mode */ | 259 | case 'v': /* verbose mode */ | 
| 269 | verbose = TRUE; | 260 | np_increase_verbosity(1); | 
| 270 | break; | 261 | break; | 
| 271 | case 'H': /* hostname */ | 262 | case 'H': /* hostname */ | 
| 272 | if (is_host (optarg) == FALSE) { | 263 | if (is_host (optarg) == FALSE) { | 
| @@ -335,13 +326,11 @@ get_threshold (char *arg, char *rv[2]) | |||
| 335 | if (arg2) { | 326 | if (arg2) { | 
| 336 | arg1[strcspn (arg1, ",:")] = 0; | 327 | arg1[strcspn (arg1, ",:")] = 0; | 
| 337 | if (strstr (arg1, "%") && strstr (arg2, "%")) | 328 | if (strstr (arg1, "%") && strstr (arg2, "%")) | 
| 338 | die (STATE_UNKNOWN, | 329 | np_die(STATE_UNKNOWN, | 
| 339 | _("%s: Only one threshold may be packet loss (%s)\n"), progname, | 330 | _("Only one threshold may be packet loss (%s)\n"), arg); | 
| 340 | arg); | ||
| 341 | if (!strstr (arg1, "%") && !strstr (arg2, "%")) | 331 | if (!strstr (arg1, "%") && !strstr (arg2, "%")) | 
| 342 | die (STATE_UNKNOWN, | 332 | np_die(STATE_UNKNOWN, | 
| 343 | _("%s: Only one threshold must be packet loss (%s)\n"), | 333 | _("Only one threshold must be packet loss (%s)\n"), arg); | 
| 344 | progname, arg); | ||
| 345 | } | 334 | } | 
| 346 | 335 | ||
| 347 | if (arg2 && strstr (arg2, "%")) { | 336 | if (arg2 && strstr (arg2, "%")) { | 
