[monitoring-plugins] Fixes the positioning of the code and some other ...

waja git at monitoring-plugins.org
Sat Jan 22 22:30:11 CET 2022


    Module: monitoring-plugins
    Branch: master
    Commit: 3bcc64396d8768d984eb58eb0a80213c2a8528ca
    Author: RincewindsHat <12514511+RincewindsHat at users.noreply.github.com>
 Committer: waja <waja at users.noreply.github.com>
      Date: Sat Jan 22 20:01:49 2022 +0100
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=3bcc643

Fixes the positioning of the code and some other changes

---

 plugins/check_fping.c | 53 +++++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 540650a..be9362a 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -37,6 +37,7 @@ const char *email = "devel at 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");



More information about the Commits mailing list