diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2022-01-22 20:01:49 +0100 |
---|---|---|
committer | waja <waja@users.noreply.github.com> | 2022-01-22 22:25:21 +0100 |
commit | 3bcc64396d8768d984eb58eb0a80213c2a8528ca (patch) | |
tree | 1a7a74163692f744b386618a6f88bcca6b2877ce /plugins | |
parent | b14e251d0f28cc2acb93df79da099bb3cdb5ec08 (diff) | |
download | monitoring-plugins-3bcc64396d8768d984eb58eb0a80213c2a8528ca.tar.gz |
Fixes the positioning of the code and some other changes
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_fping.c | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 540650ae..be9362ad 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -37,6 +37,7 @@ const char *email = "devel@monitoring-plugins.org"; #include "popen.h" #include "netutils.h" #include "utils.h" +#include <stdbool.h> enum { PACKET_COUNT = 1, @@ -65,7 +66,7 @@ double crta; double wrta; int cpl_p = FALSE; int wpl_p = FALSE; -int alive_p = FALSE; +bool alive_p = FALSE; int crta_p = FALSE; int wrta_p = FALSE; @@ -148,23 +149,12 @@ main (int argc, char **argv) (void) fclose (child_stderr); /* close the pipe */ - if (result = spclose (child_process)) + result = spclose (child_process); + if (result) { /* need to use max_state not max */ status = max_state (status, STATE_WARNING); - if (alive_p && strstr (buf, "avg, 0% loss)")){ - rtastr = strstr (buf, "ms ("); - rtastr = 1 + index (rtastr, '('); - rta = strtod (rtastr, NULL); - loss=strtod ("0",NULL); - die (STATE_OK, - _("FPING %s - %s (rta=%f ms)|%s %s\n"), - state_text (STATE_OK), server_name,rta, - perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), - fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); - } - if (result > 1 ) { status = max_state (status, STATE_UNKNOWN); if (result == 2) { @@ -185,10 +175,7 @@ main (int argc, char **argv) } - -int -textscan (char *buf) -{ +int textscan (char *buf) { char *rtastr = NULL; char *losstr = NULL; char *xmtstr = NULL; @@ -197,6 +184,20 @@ textscan (char *buf) double xmt; int status = STATE_UNKNOWN; + /* stops testing after the first successful reply. */ + if (alive_p && strstr(buf, "avg, 0% loss)")) { + rtastr = strstr (buf, "ms ("); + rtastr = 1 + index(rtastr, '('); + rta = strtod(rtastr, NULL); + loss=strtod("0",NULL); + die (STATE_OK, + _("FPING %s - %s (rta=%f ms)|%s\n"), + state_text (STATE_OK), server_name,rta, + /* No loss since we only waited for the first reply + perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), */ + fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); + } + if (strstr (buf, "not found")) { die (STATE_CRITICAL, _("FPING UNKNOWN - %s not found\n"), server_name); @@ -289,12 +290,10 @@ process_arguments (int argc, char **argv) static struct option longopts[] = { {"hostname", required_argument, 0, 'H'}, {"sourceip", required_argument, 0, 'S'}, - case 'a': /* host alive mode */ - alive_p = TRUE; - break; {"sourceif", required_argument, 0, 'I'}, {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, + {"alive", no_argument, 0, 'a'}, {"bytes", required_argument, 0, 'b'}, {"number", required_argument, 0, 'n'}, {"target-timeout", required_argument, 0, 'T'}, @@ -329,6 +328,9 @@ process_arguments (int argc, char **argv) switch (c) { case '?': /* print short usage statement if args not parsable */ usage5 (); + case 'a': /* host alive mode */ + alive_p = TRUE; + break; case 'h': /* help */ print_help (); exit (STATE_UNKNOWN); @@ -433,9 +435,6 @@ get_threshold (char *arg, char *rv[2]) arg2 = 1 + strpbrk (arg1, ",:"); if (arg2) { - printf (" %s\n", "-a"); - printf (" %s\n", _("Return OK after first successfull reply")); - arg1[strcspn (arg1, ",:")] = 0; if (strstr (arg1, "%") && strstr (arg2, "%")) die (STATE_UNKNOWN, @@ -466,9 +465,7 @@ get_threshold (char *arg, char *rv[2]) } -void -print_help (void) -{ +void print_help (void) { print_revision (progname, NP_VERSION); @@ -494,6 +491,8 @@ print_help (void) printf (" %s\n", _("warning threshold pair")); printf (" %s\n", "-c, --critical=THRESHOLD"); printf (" %s\n", _("critical threshold pair")); + printf (" %s\n", "-a, --alive"); + printf (" %s\n", _("Return OK after first successfull reply")); printf (" %s\n", "-b, --bytes=INTEGER"); printf (" %s (default: %d)\n", _("size of ICMP packet"),PACKET_SIZE); printf (" %s\n", "-n, --number=INTEGER"); |