diff options
Diffstat (limited to 'plugins/check_fping.c')
| -rw-r--r-- | plugins/check_fping.c | 139 |
1 files changed, 111 insertions, 28 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index e05056b2..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; |
| @@ -117,8 +118,28 @@ int main(int argc, char **argv) { | |||
| 117 | xasprintf(&option_string, "%s-R ", option_string); | 118 | xasprintf(&option_string, "%s-R ", option_string); |
| 118 | } | 119 | } |
| 119 | 120 | ||
| 121 | if (config.fwmark_set) { | ||
| 122 | xasprintf(&option_string, "%s--fwmark %u ", option_string, config.fwmark); | ||
| 123 | } | ||
| 124 | |||
| 125 | if (config.icmp_timestamp) { | ||
| 126 | xasprintf(&option_string, "%s--icmp-timestamp ", option_string); | ||
| 127 | } | ||
| 128 | |||
| 129 | if (config.check_source) { | ||
| 130 | xasprintf(&option_string, "%s--check-source ", option_string); | ||
| 131 | } | ||
| 132 | |||
| 120 | char *command_line = NULL; | 133 | char *command_line = NULL; |
| 121 | xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server); | 134 | |
| 135 | if (config.icmp_timestamp) { | ||
| 136 | // no packet size settable for ICMP timestamp | ||
| 137 | xasprintf(&command_line, "%s %s -c %d %s", fping_prog, option_string, config.packet_count, | ||
| 138 | server); | ||
| 139 | } else { | ||
| 140 | xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, | ||
| 141 | config.packet_size, config.packet_count, server); | ||
| 142 | } | ||
| 122 | 143 | ||
| 123 | if (verbose) { | 144 | if (verbose) { |
| 124 | printf("%s\n", command_line); | 145 | printf("%s\n", command_line); |
| @@ -142,8 +163,9 @@ int main(int argc, char **argv) { | |||
| 142 | if (verbose) { | 163 | if (verbose) { |
| 143 | printf("%s", input_buffer); | 164 | printf("%s", input_buffer); |
| 144 | } | 165 | } |
| 145 | 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, |
| 146 | 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)); | ||
| 147 | } | 169 | } |
| 148 | 170 | ||
| 149 | /* If we get anything on STDERR, at least set warning */ | 171 | /* If we get anything on STDERR, at least set warning */ |
| @@ -152,8 +174,9 @@ int main(int argc, char **argv) { | |||
| 152 | if (verbose) { | 174 | if (verbose) { |
| 153 | printf("%s", input_buffer); | 175 | printf("%s", input_buffer); |
| 154 | } | 176 | } |
| 155 | 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, |
| 156 | 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)); | ||
| 157 | } | 180 | } |
| 158 | (void)fclose(child_stderr); | 181 | (void)fclose(child_stderr); |
| 159 | 182 | ||
| @@ -182,8 +205,8 @@ int main(int argc, char **argv) { | |||
| 182 | return status; | 205 | return status; |
| 183 | } | 206 | } |
| 184 | 207 | ||
| 185 | 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, |
| 186 | bool wpl_p, int wpl, bool alive_p) { | 209 | double wrta, bool cpl_p, int cpl, bool wpl_p, int wpl, bool alive_p) { |
| 187 | /* stops testing after the first successful reply. */ | 210 | /* stops testing after the first successful reply. */ |
| 188 | double rta; | 211 | double rta; |
| 189 | double loss; | 212 | double loss; |
| @@ -196,7 +219,8 @@ mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double c | |||
| 196 | 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, |
| 197 | /* No loss since we only waited for the first reply | 220 | /* No loss since we only waited for the first reply |
| 198 | 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), */ |
| 199 | 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)); | ||
| 200 | } | 224 | } |
| 201 | 225 | ||
| 202 | mp_state_enum status = STATE_UNKNOWN; | 226 | mp_state_enum status = STATE_UNKNOWN; |
| @@ -237,9 +261,11 @@ mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double c | |||
| 237 | } else { | 261 | } else { |
| 238 | status = STATE_OK; | 262 | status = STATE_OK; |
| 239 | } | 263 | } |
| 240 | 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, | ||
| 241 | 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), |
| 242 | 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)); | ||
| 243 | 269 | ||
| 244 | } else if (strstr(buf, "xmt/rcv/%loss")) { | 270 | } else if (strstr(buf, "xmt/rcv/%loss")) { |
| 245 | /* 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 */ |
| @@ -275,13 +301,38 @@ mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double c | |||
| 275 | 301 | ||
| 276 | /* process command-line arguments */ | 302 | /* process command-line arguments */ |
| 277 | check_fping_config_wrapper process_arguments(int argc, char **argv) { | 303 | check_fping_config_wrapper process_arguments(int argc, char **argv) { |
| 278 | static struct option longopts[] = { | 304 | enum { |
| 279 | {"hostname", required_argument, 0, 'H'}, {"sourceip", required_argument, 0, 'S'}, {"sourceif", required_argument, 0, 'I'}, | 305 | FWMARK_OPT = CHAR_MAX + 1, |
| 280 | {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, {"alive", no_argument, 0, 'a'}, | 306 | ICMP_TIMESTAMP_OPT, |
| 281 | {"bytes", required_argument, 0, 'b'}, {"number", required_argument, 0, 'n'}, {"target-timeout", required_argument, 0, 'T'}, | 307 | CHECK_SOURCE_OPT, |
| 282 | {"interval", required_argument, 0, 'i'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, | 308 | }; |
| 283 | {"help", no_argument, 0, 'h'}, {"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, | 309 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, |
| 284 | {"dontfrag", no_argument, 0, 'M'}, {"random", no_argument, 0, 'R'}, {0, 0, 0, 0}}; | 310 | {"sourceip", required_argument, 0, 'S'}, |
| 311 | {"sourceif", required_argument, 0, 'I'}, | ||
| 312 | {"critical", required_argument, 0, 'c'}, | ||
| 313 | {"warning", required_argument, 0, 'w'}, | ||
| 314 | {"alive", no_argument, 0, 'a'}, | ||
| 315 | {"bytes", required_argument, 0, 'b'}, | ||
| 316 | {"number", required_argument, 0, 'n'}, | ||
| 317 | {"target-timeout", required_argument, 0, 'T'}, | ||
| 318 | {"interval", required_argument, 0, 'i'}, | ||
| 319 | {"verbose", no_argument, 0, 'v'}, | ||
| 320 | {"version", no_argument, 0, 'V'}, | ||
| 321 | {"help", no_argument, 0, 'h'}, | ||
| 322 | {"use-ipv4", no_argument, 0, '4'}, | ||
| 323 | {"use-ipv6", no_argument, 0, '6'}, | ||
| 324 | {"dontfrag", no_argument, 0, 'M'}, | ||
| 325 | {"random", no_argument, 0, 'R'}, | ||
| 326 | #ifdef FPING_VERSION_5_2_OR_HIGHER | ||
| 327 | // only available with fping version >= 5.2 | ||
| 328 | {"fwmark", required_argument, NULL, FWMARK_OPT}, | ||
| 329 | # ifdef FPING_VERSION_5_3_OR_HIGHER | ||
| 330 | // only available with fping version >= 5.3 | ||
| 331 | {"icmp-timestamp", no_argument, NULL, ICMP_TIMESTAMP_OPT}, | ||
| 332 | {"check-source", no_argument, NULL, CHECK_SOURCE_OPT}, | ||
| 333 | # endif | ||
| 334 | #endif | ||
| 335 | {0, 0, 0, 0}}; | ||
| 285 | 336 | ||
| 286 | char *rv[2]; | 337 | char *rv[2]; |
| 287 | rv[PL] = NULL; | 338 | rv[PL] = NULL; |
| @@ -306,8 +357,9 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { | |||
| 306 | argc--; | 357 | argc--; |
| 307 | } | 358 | } |
| 308 | 359 | ||
| 309 | while (1) { | 360 | while (true) { |
| 310 | 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); | ||
| 311 | 363 | ||
| 312 | if (option_index == -1 || option_index == EOF || option_index == 1) { | 364 | if (option_index == -1 || option_index == EOF || option_index == 1) { |
| 313 | break; | 365 | break; |
| @@ -409,6 +461,20 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { | |||
| 409 | case 'M': | 461 | case 'M': |
| 410 | result.config.dontfrag = true; | 462 | result.config.dontfrag = true; |
| 411 | break; | 463 | break; |
| 464 | case FWMARK_OPT: | ||
| 465 | if (is_intpos(optarg)) { | ||
| 466 | result.config.fwmark = (unsigned int)atol(optarg); | ||
| 467 | result.config.fwmark_set = true; | ||
| 468 | } else { | ||
| 469 | usage(_("fwmark must be a positive integer")); | ||
| 470 | } | ||
| 471 | break; | ||
| 472 | case ICMP_TIMESTAMP_OPT: | ||
| 473 | result.config.icmp_timestamp = true; | ||
| 474 | break; | ||
| 475 | case CHECK_SOURCE_OPT: | ||
| 476 | result.config.check_source = true; | ||
| 477 | break; | ||
| 412 | } | 478 | } |
| 413 | } | 479 | } |
| 414 | 480 | ||
| @@ -430,10 +496,12 @@ int get_threshold(char *arg, char *rv[2]) { | |||
| 430 | if (arg2) { | 496 | if (arg2) { |
| 431 | arg1[strcspn(arg1, ",:")] = 0; | 497 | arg1[strcspn(arg1, ",:")] = 0; |
| 432 | if (strstr(arg1, "%") && strstr(arg2, "%")) { | 498 | if (strstr(arg1, "%") && strstr(arg2, "%")) { |
| 433 | 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); | ||
| 434 | } | 501 | } |
| 435 | if (!strstr(arg1, "%") && !strstr(arg2, "%")) { | 502 | if (!strstr(arg1, "%") && !strstr(arg2, "%")) { |
| 436 | 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); | ||
| 437 | } | 505 | } |
| 438 | } | 506 | } |
| 439 | 507 | ||
| @@ -459,7 +527,8 @@ void print_help(void) { | |||
| 459 | 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"); |
| 460 | printf(COPYRIGHT, copyright, email); | 528 | printf(COPYRIGHT, copyright, email); |
| 461 | 529 | ||
| 462 | 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")); | ||
| 463 | 532 | ||
| 464 | 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.")); |
| 465 | 534 | ||
| @@ -473,7 +542,8 @@ void print_help(void) { | |||
| 473 | printf(UT_IPv46); | 542 | printf(UT_IPv46); |
| 474 | 543 | ||
| 475 | printf(" %s\n", "-H, --hostname=HOST"); | 544 | printf(" %s\n", "-H, --hostname=HOST"); |
| 476 | 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)")); | ||
| 477 | printf(" %s\n", "-w, --warning=THRESHOLD"); | 547 | printf(" %s\n", "-w, --warning=THRESHOLD"); |
| 478 | printf(" %s\n", _("warning threshold pair")); | 548 | printf(" %s\n", _("warning threshold pair")); |
| 479 | printf(" %s\n", "-c, --critical=THRESHOLD"); | 549 | printf(" %s\n", "-c, --critical=THRESHOLD"); |
| @@ -487,7 +557,8 @@ void print_help(void) { | |||
| 487 | printf(" %s\n", "-T, --target-timeout=INTEGER"); | 557 | printf(" %s\n", "-T, --target-timeout=INTEGER"); |
| 488 | 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)")); |
| 489 | printf(" %s\n", "-i, --interval=INTEGER"); | 559 | printf(" %s\n", "-i, --interval=INTEGER"); |
| 490 | 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")); | ||
| 491 | printf(" %s\n", "-S, --sourceip=HOST"); | 562 | printf(" %s\n", "-S, --sourceip=HOST"); |
| 492 | printf(" %s\n", _("name or IP Address of sourceip")); | 563 | printf(" %s\n", _("name or IP Address of sourceip")); |
| 493 | printf(" %s\n", "-I, --sourceif=IF"); | 564 | printf(" %s\n", "-I, --sourceif=IF"); |
| @@ -496,9 +567,20 @@ void print_help(void) { | |||
| 496 | printf(" %s\n", _("set the Don't Fragment flag")); | 567 | printf(" %s\n", _("set the Don't Fragment flag")); |
| 497 | printf(" %s\n", "-R, --random"); | 568 | printf(" %s\n", "-R, --random"); |
| 498 | printf(" %s\n", _("random packet data (to foil link data compression)")); | 569 | printf(" %s\n", _("random packet data (to foil link data compression)")); |
| 570 | #ifdef FPING_VERSION_5_2_OR_HIGHER | ||
| 571 | printf(" %s\n", "--fwmark=INTEGER"); | ||
| 572 | printf(" %s\n", _("set the routing mark to INTEGER (fping option)")); | ||
| 573 | # ifdef FPING_VERSION_5_3_OR_HIGHER | ||
| 574 | printf(" %s\n", "--icmp-timestamp"); | ||
| 575 | printf(" %s\n", _("use ICMP Timestamp instead of ICMP Echo (fping option)")); | ||
| 576 | printf(" %s\n", "--check-source"); | ||
| 577 | printf(" %s\n", _("discard replies not from target address (fping option)")); | ||
| 578 | # endif | ||
| 579 | #endif | ||
| 499 | printf(UT_VERBOSE); | 580 | printf(UT_VERBOSE); |
| 500 | printf("\n"); | 581 | printf("\n"); |
| 501 | 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)")); | ||
| 502 | 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")); |
| 503 | printf(" %s\n", _("packet loss to trigger an alarm state.")); | 585 | printf(" %s\n", _("packet loss to trigger an alarm state.")); |
| 504 | 586 | ||
| @@ -510,5 +592,6 @@ void print_help(void) { | |||
| 510 | 592 | ||
| 511 | void print_usage(void) { | 593 | void print_usage(void) { |
| 512 | printf("%s\n", _("Usage:")); | 594 | printf("%s\n", _("Usage:")); |
| 513 | 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); | ||
| 514 | } | 597 | } |
