Code

Ignore stderr messages unless return code is non-zero or there is no output
authorTon Voon <tonvoon@macbook.local>
Sat, 14 Mar 2009 02:36:20 +0000 (02:36 +0000)
committerTon Voon <tonvoon@macbook.local>
Sat, 14 Mar 2009 02:36:20 +0000 (02:36 +0000)
plugins/check_snmp.c

index 1b1eb2e85f075c6ba699799e667c1a19c0d93a11..03c2a174a132c69702d9c6f99147337e18affee9 100644 (file)
@@ -143,6 +143,8 @@ main (int argc, char **argv)
        int i = 0;
        int iresult = STATE_UNKNOWN;
        int result = STATE_UNKNOWN;
+       int return_code = 0;
+       int external_error = 0;
        char **command_line = NULL;
        char *cl_hidden_auth = NULL;
        char *oidname = NULL;
@@ -220,22 +222,28 @@ main (int argc, char **argv)
                printf ("%s\n", cl_hidden_auth);
 
        /* Run the command */
-       result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
-
-       if (chld_err.lines > 0) {
-               printf (_("External command error: %s\n"), chld_err.line[0]);
-               for (i = 1; i < chld_err.lines; i++) {
-                       printf ("%s\n", chld_err.line[i]);
+       return_code = cmd_run_array (command_line, &chld_out, &chld_err, 0);
+
+       /* Due to net-snmp sometimes showing stderr messages with poorly formed MIBs, 
+          only return state unknown if return code is non zero or there is no stdout.
+          Do this way so that if there is stderr, will get added to output, which helps problem diagnosis
+       /*
+       if (return_code != 0)
+               external_error=1;
+       if (chld_out.lines == 0)
+               external_error=1;
+       if (external_error) {
+               if (chld_err.lines > 0) {
+                       printf (_("External command error: %s\n"), chld_err.line[0]);
+                       for (i = 1; i < chld_err.lines; i++) {
+                               printf ("%s\n", chld_err.line[i]);
+                       }
+               } else {
+                       printf(_("External command error with no output (return code: %d)\n"), return_code);
                }
                exit (STATE_UNKNOWN);
        }
 
-       /* Return UNKNOWN or worse if no output is returned */
-       if (chld_out.lines == 0)
-               die (max_state_alt (result, STATE_UNKNOWN), _("%s problem - No data received from host\nCMD: %s\n"),
-                                                               label,
-                                                               cl_hidden_auth);
-
        if (verbose) {
                for (i = 0; i < chld_out.lines; i++) {
                        printf ("%s\n", chld_out.line[i]);