diff options
| author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2023-03-10 11:33:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-10 11:33:25 +0100 |
| commit | 5077120a251980b4fafed61b4aa8fa5730a85443 (patch) | |
| tree | 8500b8f5dbe774b399cfdc79f5665ba88ef7f255 /plugins/check_fping.c | |
| parent | a3de84594104ac87a91e200d569fb57edacca928 (diff) | |
| parent | 269718094177fb8a7e3d3005d1310495009fe8c4 (diff) | |
| download | monitoring-plugins-5077120a251980b4fafed61b4aa8fa5730a85443.tar.gz | |
Merge branch 'master' into master
Diffstat (limited to 'plugins/check_fping.c')
| -rw-r--r-- | plugins/check_fping.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 521d0fef..db433162 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,6 +66,7 @@ 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 | ||
| @@ -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); |
| @@ -446,9 +465,7 @@ get_threshold (char *arg, char *rv[2]) | |||
| 446 | } | 465 | } |
| 447 | 466 | ||
| 448 | 467 | ||
| 449 | void | 468 | void print_help (void) { |
| 450 | print_help (void) | ||
| 451 | { | ||
| 452 | 469 | ||
| 453 | print_revision (progname, NP_VERSION); | 470 | print_revision (progname, NP_VERSION); |
| 454 | 471 | ||
| @@ -474,6 +491,8 @@ print_help (void) | |||
| 474 | printf (" %s\n", _("warning threshold pair")); | 491 | printf (" %s\n", _("warning threshold pair")); |
| 475 | printf (" %s\n", "-c, --critical=THRESHOLD"); | 492 | printf (" %s\n", "-c, --critical=THRESHOLD"); |
| 476 | printf (" %s\n", _("critical threshold pair")); | 493 | printf (" %s\n", _("critical threshold pair")); |
| 494 | printf (" %s\n", "-a, --alive"); | ||
| 495 | printf (" %s\n", _("Return OK after first successful reply")); | ||
| 477 | printf (" %s\n", "-b, --bytes=INTEGER"); | 496 | printf (" %s\n", "-b, --bytes=INTEGER"); |
| 478 | printf (" %s (default: %d)\n", _("size of ICMP packet"),PACKET_SIZE); | 497 | printf (" %s (default: %d)\n", _("size of ICMP packet"),PACKET_SIZE); |
| 479 | printf (" %s\n", "-n, --number=INTEGER"); | 498 | printf (" %s\n", "-n, --number=INTEGER"); |
