diff options
Diffstat (limited to 'plugins/check_fping.c')
| -rw-r--r-- | plugins/check_fping.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 521d0fef..23a9e990 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
| @@ -37,6 +37,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 37 | #include "popen.h" | 37 | #include "popen.h" |
| 38 | #include "netutils.h" | 38 | #include "netutils.h" |
| 39 | #include "utils.h" | 39 | #include "utils.h" |
| 40 | #include <stdbool.h> | ||
| 40 | 41 | ||
| 41 | enum { | 42 | enum { |
| 42 | PACKET_COUNT = 1, | 43 | PACKET_COUNT = 1, |
| @@ -65,13 +66,14 @@ double crta; | |||
| 65 | double wrta; | 66 | double wrta; |
| 66 | int cpl_p = FALSE; | 67 | int cpl_p = FALSE; |
| 67 | int wpl_p = FALSE; | 68 | int wpl_p = FALSE; |
| 69 | bool alive_p = FALSE; | ||
| 68 | int crta_p = FALSE; | 70 | int crta_p = FALSE; |
| 69 | int wrta_p = FALSE; | 71 | int wrta_p = FALSE; |
| 70 | 72 | ||
| 71 | int | 73 | int |
| 72 | main (int argc, char **argv) | 74 | main (int argc, char **argv) |
| 73 | { | 75 | { |
| 74 | /* normaly should be int result = STATE_UNKNOWN; */ | 76 | /* normally should be int result = STATE_UNKNOWN; */ |
| 75 | 77 | ||
| 76 | int status = STATE_UNKNOWN; | 78 | int status = STATE_UNKNOWN; |
| 77 | int result = 0; | 79 | int result = 0; |
| @@ -147,9 +149,11 @@ main (int argc, char **argv) | |||
| 147 | (void) fclose (child_stderr); | 149 | (void) fclose (child_stderr); |
| 148 | 150 | ||
| 149 | /* close the pipe */ | 151 | /* close the pipe */ |
| 150 | if (result = spclose (child_process)) | 152 | result = spclose (child_process); |
| 153 | if (result) { | ||
| 151 | /* need to use max_state not max */ | 154 | /* need to use max_state not max */ |
| 152 | status = max_state (status, STATE_WARNING); | 155 | status = max_state (status, STATE_WARNING); |
| 156 | } | ||
| 153 | 157 | ||
| 154 | if (result > 1 ) { | 158 | if (result > 1 ) { |
| 155 | status = max_state (status, STATE_UNKNOWN); | 159 | status = max_state (status, STATE_UNKNOWN); |
| @@ -171,10 +175,7 @@ main (int argc, char **argv) | |||
| 171 | } | 175 | } |
| 172 | 176 | ||
| 173 | 177 | ||
| 174 | 178 | int textscan (char *buf) { | |
| 175 | int | ||
| 176 | textscan (char *buf) | ||
| 177 | { | ||
| 178 | char *rtastr = NULL; | 179 | char *rtastr = NULL; |
| 179 | char *losstr = NULL; | 180 | char *losstr = NULL; |
| 180 | char *xmtstr = NULL; | 181 | char *xmtstr = NULL; |
| @@ -183,6 +184,20 @@ textscan (char *buf) | |||
| 183 | double xmt; | 184 | double xmt; |
| 184 | int status = STATE_UNKNOWN; | 185 | int status = STATE_UNKNOWN; |
| 185 | 186 | ||
| 187 | /* stops testing after the first successful reply. */ | ||
| 188 | if (alive_p && strstr(buf, "avg, 0% loss)")) { | ||
| 189 | rtastr = strstr (buf, "ms ("); | ||
| 190 | rtastr = 1 + index(rtastr, '('); | ||
| 191 | rta = strtod(rtastr, NULL); | ||
| 192 | loss=strtod("0",NULL); | ||
| 193 | die (STATE_OK, | ||
| 194 | _("FPING %s - %s (rta=%f ms)|%s\n"), | ||
| 195 | state_text (STATE_OK), server_name,rta, | ||
| 196 | /* No loss since we only waited for the first reply | ||
| 197 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), */ | ||
| 198 | fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); | ||
| 199 | } | ||
| 200 | |||
| 186 | if (strstr (buf, "not found")) { | 201 | if (strstr (buf, "not found")) { |
| 187 | die (STATE_CRITICAL, _("FPING UNKNOWN - %s not found\n"), server_name); | 202 | die (STATE_CRITICAL, _("FPING UNKNOWN - %s not found\n"), server_name); |
| 188 | 203 | ||
| @@ -278,6 +293,7 @@ process_arguments (int argc, char **argv) | |||
| 278 | {"sourceif", required_argument, 0, 'I'}, | 293 | {"sourceif", required_argument, 0, 'I'}, |
| 279 | {"critical", required_argument, 0, 'c'}, | 294 | {"critical", required_argument, 0, 'c'}, |
| 280 | {"warning", required_argument, 0, 'w'}, | 295 | {"warning", required_argument, 0, 'w'}, |
| 296 | {"alive", no_argument, 0, 'a'}, | ||
| 281 | {"bytes", required_argument, 0, 'b'}, | 297 | {"bytes", required_argument, 0, 'b'}, |
| 282 | {"number", required_argument, 0, 'n'}, | 298 | {"number", required_argument, 0, 'n'}, |
| 283 | {"target-timeout", required_argument, 0, 'T'}, | 299 | {"target-timeout", required_argument, 0, 'T'}, |
| @@ -304,7 +320,7 @@ process_arguments (int argc, char **argv) | |||
| 304 | } | 320 | } |
| 305 | 321 | ||
| 306 | while (1) { | 322 | while (1) { |
| 307 | c = getopt_long (argc, argv, "+hVvH:S:c:w:b:n:T:i:I:46", longopts, &option); | 323 | c = getopt_long (argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:46", longopts, &option); |
| 308 | 324 | ||
| 309 | if (c == -1 || c == EOF || c == 1) | 325 | if (c == -1 || c == EOF || c == 1) |
| 310 | break; | 326 | break; |
| @@ -312,6 +328,9 @@ process_arguments (int argc, char **argv) | |||
| 312 | switch (c) { | 328 | switch (c) { |
| 313 | case '?': /* print short usage statement if args not parsable */ | 329 | case '?': /* print short usage statement if args not parsable */ |
| 314 | usage5 (); | 330 | usage5 (); |
| 331 | case 'a': /* host alive mode */ | ||
| 332 | alive_p = TRUE; | ||
| 333 | break; | ||
| 315 | case 'h': /* help */ | 334 | case 'h': /* help */ |
| 316 | print_help (); | 335 | print_help (); |
| 317 | exit (STATE_UNKNOWN); | 336 | exit (STATE_UNKNOWN); |
| @@ -335,6 +354,7 @@ process_arguments (int argc, char **argv) | |||
| 335 | break; | 354 | break; |
| 336 | case 'I': /* sourceip */ | 355 | case 'I': /* sourceip */ |
| 337 | sourceif = strscpy (sourceif, optarg); | 356 | sourceif = strscpy (sourceif, optarg); |
| 357 | break; | ||
| 338 | case '4': /* IPv4 only */ | 358 | case '4': /* IPv4 only */ |
| 339 | address_family = AF_INET; | 359 | address_family = AF_INET; |
| 340 | break; | 360 | break; |
| @@ -446,9 +466,7 @@ get_threshold (char *arg, char *rv[2]) | |||
| 446 | } | 466 | } |
| 447 | 467 | ||
| 448 | 468 | ||
| 449 | void | 469 | void print_help (void) { |
| 450 | print_help (void) | ||
| 451 | { | ||
| 452 | 470 | ||
| 453 | print_revision (progname, NP_VERSION); | 471 | print_revision (progname, NP_VERSION); |
| 454 | 472 | ||
| @@ -474,6 +492,8 @@ print_help (void) | |||
| 474 | printf (" %s\n", _("warning threshold pair")); | 492 | printf (" %s\n", _("warning threshold pair")); |
| 475 | printf (" %s\n", "-c, --critical=THRESHOLD"); | 493 | printf (" %s\n", "-c, --critical=THRESHOLD"); |
| 476 | printf (" %s\n", _("critical threshold pair")); | 494 | printf (" %s\n", _("critical threshold pair")); |
| 495 | printf (" %s\n", "-a, --alive"); | ||
| 496 | printf (" %s\n", _("Return OK after first successful reply")); | ||
| 477 | printf (" %s\n", "-b, --bytes=INTEGER"); | 497 | printf (" %s\n", "-b, --bytes=INTEGER"); |
| 478 | printf (" %s (default: %d)\n", _("size of ICMP packet"),PACKET_SIZE); | 498 | printf (" %s (default: %d)\n", _("size of ICMP packet"),PACKET_SIZE); |
| 479 | printf (" %s\n", "-n, --number=INTEGER"); | 499 | printf (" %s\n", "-n, --number=INTEGER"); |
