Explorar el Código

check_fping error handling enhanced, generates UNKNOWN on
fping parameter error (i.e. wrong interface, missing perms ..)

Steve Weinreich hace 12 años
padre
commit
96ec686004
Se han modificado 1 ficheros con 20 adiciones y 1 borrados
  1. 20 1
      plugins/check_fping.c

+ 20 - 1
plugins/check_fping.c

@@ -74,6 +74,7 @@ main (int argc, char **argv)
 /* normaly should be  int result = STATE_UNKNOWN; */
 /* normaly should be  int result = STATE_UNKNOWN; */
 
 
   int status = STATE_UNKNOWN;
   int status = STATE_UNKNOWN;
+  int result = 0;
   char *fping_prog = NULL;
   char *fping_prog = NULL;
   char *server = NULL;
   char *server = NULL;
   char *command_line = NULL;
   char *command_line = NULL;
@@ -146,10 +147,24 @@ main (int argc, char **argv)
   (void) fclose (child_stderr);
   (void) fclose (child_stderr);
 
 
   /* close the pipe */
   /* close the pipe */
-  if (spclose (child_process))
+  if (result = spclose (child_process))
     /* need to use max_state not max */
     /* need to use max_state not max */
     status = max_state (status, STATE_WARNING);
     status = max_state (status, STATE_WARNING);
 
 
+  if (result > 1 ) {
+    status = max_state (status, STATE_UNKNOWN);
+    if (result == 2) {
+      die (STATE_UNKNOWN, _("FPING UNKNOWN - IP address not found\n"));
+    }
+    if (result == 3) {
+      die (STATE_UNKNOWN, _("FPING UNKNOWN - invalid commandline argument\n"));
+    }
+    if (result == 4) {
+      die (STATE_UNKNOWN, _("FPING UNKNOWN - failed system call\n"));
+    }
+
+  }
+
   printf ("FPING %s - %s\n", state_text (status), server_name);
   printf ("FPING %s - %s\n", state_text (status), server_name);
 
 
   return status;
   return status;
@@ -175,6 +190,10 @@ textscan (char *buf)
                "host");
                "host");
 
 
   }
   }
+  else if (strstr (buf, "Operation not permitted") || strstr (buf, "No such device") ) {
+    die (STATE_UNKNOWN, _("FPING UNKNOWN - %s parameter error\n"),
+               "host");
+  }
   else if (strstr (buf, "is down")) {
   else if (strstr (buf, "is down")) {
     die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name);
     die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name);