diff options
Diffstat (limited to 'plugins/check_fping.c')
-rw-r--r-- | plugins/check_fping.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 8018e06d..6160c2cb 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
@@ -46,8 +46,9 @@ enum { | |||
46 | RTA = 1 | 46 | RTA = 1 |
47 | }; | 47 | }; |
48 | 48 | ||
49 | static mp_state_enum textscan(char *buf, const char * /*server_name*/, bool /*crta_p*/, double /*crta*/, bool /*wrta_p*/, double /*wrta*/, | 49 | static mp_state_enum textscan(char *buf, const char * /*server_name*/, bool /*crta_p*/, |
50 | bool /*cpl_p*/, int /*cpl*/, bool /*wpl_p*/, int /*wpl*/, bool /*alive_p*/); | 50 | double /*crta*/, bool /*wrta_p*/, double /*wrta*/, bool /*cpl_p*/, |
51 | int /*cpl*/, bool /*wpl_p*/, int /*wpl*/, bool /*alive_p*/); | ||
51 | 52 | ||
52 | typedef struct { | 53 | typedef struct { |
53 | int errorcode; | 54 | int errorcode; |
@@ -133,9 +134,11 @@ int main(int argc, char **argv) { | |||
133 | 134 | ||
134 | if (config.icmp_timestamp) { | 135 | if (config.icmp_timestamp) { |
135 | // no packet size settable for ICMP timestamp | 136 | // no packet size settable for ICMP timestamp |
136 | xasprintf(&command_line, "%s %s -c %d %s", fping_prog, option_string, config.packet_count, server); | 137 | xasprintf(&command_line, "%s %s -c %d %s", fping_prog, option_string, config.packet_count, |
138 | server); | ||
137 | } else { | 139 | } else { |
138 | xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server); | 140 | xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, |
141 | config.packet_size, config.packet_count, server); | ||
139 | } | 142 | } |
140 | 143 | ||
141 | if (verbose) { | 144 | if (verbose) { |
@@ -160,8 +163,9 @@ int main(int argc, char **argv) { | |||
160 | if (verbose) { | 163 | if (verbose) { |
161 | printf("%s", input_buffer); | 164 | printf("%s", input_buffer); |
162 | } | 165 | } |
163 | status = max_state(status, textscan(input_buffer, config.server_name, config.crta_p, config.crta, config.wrta_p, config.wrta, | 166 | status = max_state(status, textscan(input_buffer, config.server_name, config.crta_p, |
164 | config.cpl_p, config.cpl, config.wpl_p, config.wpl, config.alive_p)); | 167 | config.crta, config.wrta_p, config.wrta, config.cpl_p, |
168 | config.cpl, config.wpl_p, config.wpl, config.alive_p)); | ||
165 | } | 169 | } |
166 | 170 | ||
167 | /* If we get anything on STDERR, at least set warning */ | 171 | /* If we get anything on STDERR, at least set warning */ |
@@ -170,8 +174,9 @@ int main(int argc, char **argv) { | |||
170 | if (verbose) { | 174 | if (verbose) { |
171 | printf("%s", input_buffer); | 175 | printf("%s", input_buffer); |
172 | } | 176 | } |
173 | status = max_state(status, textscan(input_buffer, config.server_name, config.crta_p, config.crta, config.wrta_p, config.wrta, | 177 | status = max_state(status, textscan(input_buffer, config.server_name, config.crta_p, |
174 | config.cpl_p, config.cpl, config.wpl_p, config.wpl, config.alive_p)); | 178 | config.crta, config.wrta_p, config.wrta, config.cpl_p, |
179 | config.cpl, config.wpl_p, config.wpl, config.alive_p)); | ||
175 | } | 180 | } |
176 | (void)fclose(child_stderr); | 181 | (void)fclose(child_stderr); |
177 | 182 | ||
@@ -200,8 +205,8 @@ int main(int argc, char **argv) { | |||
200 | return status; | 205 | return status; |
201 | } | 206 | } |
202 | 207 | ||
203 | mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double crta, bool wrta_p, double wrta, bool cpl_p, int cpl, | 208 | mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double crta, bool wrta_p, |
204 | bool wpl_p, int wpl, bool alive_p) { | 209 | double wrta, bool cpl_p, int cpl, bool wpl_p, int wpl, bool alive_p) { |
205 | /* stops testing after the first successful reply. */ | 210 | /* stops testing after the first successful reply. */ |
206 | double rta; | 211 | double rta; |
207 | double loss; | 212 | double loss; |
@@ -214,7 +219,8 @@ mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double c | |||
214 | die(STATE_OK, _("FPING %s - %s (rta=%f ms)|%s\n"), state_text(STATE_OK), server_name, rta, | 219 | die(STATE_OK, _("FPING %s - %s (rta=%f ms)|%s\n"), state_text(STATE_OK), server_name, rta, |
215 | /* No loss since we only waited for the first reply | 220 | /* No loss since we only waited for the first reply |
216 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, true, 0, true, 100), */ | 221 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, true, 0, true, 100), */ |
217 | fperfdata("rta", rta / 1.0e3, "s", wrta_p, wrta / 1.0e3, crta_p, crta / 1.0e3, true, 0, false, 0)); | 222 | fperfdata("rta", rta / 1.0e3, "s", wrta_p, wrta / 1.0e3, crta_p, crta / 1.0e3, true, 0, |
223 | false, 0)); | ||
218 | } | 224 | } |
219 | 225 | ||
220 | mp_state_enum status = STATE_UNKNOWN; | 226 | mp_state_enum status = STATE_UNKNOWN; |
@@ -255,9 +261,11 @@ mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double c | |||
255 | } else { | 261 | } else { |
256 | status = STATE_OK; | 262 | status = STATE_OK; |
257 | } | 263 | } |
258 | die(status, _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), state_text(status), server_name, loss, rta, | 264 | die(status, _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), state_text(status), |
265 | server_name, loss, rta, | ||
259 | perfdata("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, false, 0, false, 0), | 266 | perfdata("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, false, 0, false, 0), |
260 | fperfdata("rta", rta / 1.0e3, "s", wrta_p, wrta / 1.0e3, crta_p, crta / 1.0e3, true, 0, false, 0)); | 267 | fperfdata("rta", rta / 1.0e3, "s", wrta_p, wrta / 1.0e3, crta_p, crta / 1.0e3, true, 0, |
268 | false, 0)); | ||
261 | 269 | ||
262 | } else if (strstr(buf, "xmt/rcv/%loss")) { | 270 | } else if (strstr(buf, "xmt/rcv/%loss")) { |
263 | /* no min/max/avg if host was unreachable in fping v2.2.b1 */ | 271 | /* no min/max/avg if host was unreachable in fping v2.2.b1 */ |
@@ -350,7 +358,8 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { | |||
350 | } | 358 | } |
351 | 359 | ||
352 | while (true) { | 360 | while (true) { |
353 | int option_index = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option); | 361 | int option_index = |
362 | getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option); | ||
354 | 363 | ||
355 | if (option_index == -1 || option_index == EOF || option_index == 1) { | 364 | if (option_index == -1 || option_index == EOF || option_index == 1) { |
356 | break; | 365 | break; |
@@ -487,10 +496,12 @@ int get_threshold(char *arg, char *rv[2]) { | |||
487 | if (arg2) { | 496 | if (arg2) { |
488 | arg1[strcspn(arg1, ",:")] = 0; | 497 | arg1[strcspn(arg1, ",:")] = 0; |
489 | if (strstr(arg1, "%") && strstr(arg2, "%")) { | 498 | if (strstr(arg1, "%") && strstr(arg2, "%")) { |
490 | die(STATE_UNKNOWN, _("%s: Only one threshold may be packet loss (%s)\n"), progname, arg); | 499 | die(STATE_UNKNOWN, _("%s: Only one threshold may be packet loss (%s)\n"), progname, |
500 | arg); | ||
491 | } | 501 | } |
492 | if (!strstr(arg1, "%") && !strstr(arg2, "%")) { | 502 | if (!strstr(arg1, "%") && !strstr(arg2, "%")) { |
493 | die(STATE_UNKNOWN, _("%s: Only one threshold must be packet loss (%s)\n"), progname, arg); | 503 | die(STATE_UNKNOWN, _("%s: Only one threshold must be packet loss (%s)\n"), progname, |
504 | arg); | ||
494 | } | 505 | } |
495 | } | 506 | } |
496 | 507 | ||
@@ -516,7 +527,8 @@ void print_help(void) { | |||
516 | printf("Copyright (c) 1999 Didi Rieder <adrieder@sbox.tu-graz.ac.at>\n"); | 527 | printf("Copyright (c) 1999 Didi Rieder <adrieder@sbox.tu-graz.ac.at>\n"); |
517 | printf(COPYRIGHT, copyright, email); | 528 | printf(COPYRIGHT, copyright, email); |
518 | 529 | ||
519 | printf("%s\n", _("This plugin will use the fping command to ping the specified host for a fast check")); | 530 | printf("%s\n", |
531 | _("This plugin will use the fping command to ping the specified host for a fast check")); | ||
520 | 532 | ||
521 | printf("%s\n", _("Note that it is necessary to set the suid flag on fping.")); | 533 | printf("%s\n", _("Note that it is necessary to set the suid flag on fping.")); |
522 | 534 | ||
@@ -530,7 +542,8 @@ void print_help(void) { | |||
530 | printf(UT_IPv46); | 542 | printf(UT_IPv46); |
531 | 543 | ||
532 | printf(" %s\n", "-H, --hostname=HOST"); | 544 | printf(" %s\n", "-H, --hostname=HOST"); |
533 | printf(" %s\n", _("name or IP Address of host to ping (IP Address bypasses name lookup, reducing system load)")); | 545 | printf(" %s\n", _("name or IP Address of host to ping (IP Address bypasses name lookup, " |
546 | "reducing system load)")); | ||
534 | printf(" %s\n", "-w, --warning=THRESHOLD"); | 547 | printf(" %s\n", "-w, --warning=THRESHOLD"); |
535 | printf(" %s\n", _("warning threshold pair")); | 548 | printf(" %s\n", _("warning threshold pair")); |
536 | printf(" %s\n", "-c, --critical=THRESHOLD"); | 549 | printf(" %s\n", "-c, --critical=THRESHOLD"); |
@@ -544,7 +557,8 @@ void print_help(void) { | |||
544 | printf(" %s\n", "-T, --target-timeout=INTEGER"); | 557 | printf(" %s\n", "-T, --target-timeout=INTEGER"); |
545 | printf(" %s (default: fping's default for -t)\n", _("Target timeout (ms)")); | 558 | printf(" %s (default: fping's default for -t)\n", _("Target timeout (ms)")); |
546 | printf(" %s\n", "-i, --interval=INTEGER"); | 559 | printf(" %s\n", "-i, --interval=INTEGER"); |
547 | printf(" %s (default: fping's default for -p)\n", _("Interval (ms) between sending packets")); | 560 | printf(" %s (default: fping's default for -p)\n", |
561 | _("Interval (ms) between sending packets")); | ||
548 | printf(" %s\n", "-S, --sourceip=HOST"); | 562 | printf(" %s\n", "-S, --sourceip=HOST"); |
549 | printf(" %s\n", _("name or IP Address of sourceip")); | 563 | printf(" %s\n", _("name or IP Address of sourceip")); |
550 | printf(" %s\n", "-I, --sourceif=IF"); | 564 | printf(" %s\n", "-I, --sourceif=IF"); |
@@ -565,7 +579,8 @@ void print_help(void) { | |||
565 | #endif | 579 | #endif |
566 | printf(UT_VERBOSE); | 580 | printf(UT_VERBOSE); |
567 | printf("\n"); | 581 | printf("\n"); |
568 | printf(" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)")); | 582 | printf(" %s\n", |
583 | _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)")); | ||
569 | printf(" %s\n", _("which triggers a WARNING or CRITICAL state, and <pl> is the percentage of")); | 584 | printf(" %s\n", _("which triggers a WARNING or CRITICAL state, and <pl> is the percentage of")); |
570 | printf(" %s\n", _("packet loss to trigger an alarm state.")); | 585 | printf(" %s\n", _("packet loss to trigger an alarm state.")); |
571 | 586 | ||
@@ -577,5 +592,6 @@ void print_help(void) { | |||
577 | 592 | ||
578 | void print_usage(void) { | 593 | void print_usage(void) { |
579 | printf("%s\n", _("Usage:")); | 594 | printf("%s\n", _("Usage:")); |
580 | printf(" %s <host_address> -w limit -c limit [-b size] [-n number] [-T number] [-i number]\n", progname); | 595 | printf(" %s <host_address> -w limit -c limit [-b size] [-n number] [-T number] [-i number]\n", |
596 | progname); | ||
581 | } | 597 | } |