Code

Verbose should not have to exceed 3 as per developement guidelines
[nagiosplug.git] / plugins / check_by_ssh.c
index 9def404dd15def11d316defff44580754bc3ccb9..ce62ebafb3816fed1fbd45f28177bedb23fe570f 100644 (file)
@@ -100,11 +100,11 @@ main (int argc, char **argv)
        if (skip_stderr == -1) /* --skip-stderr specified without argument */
                skip_stderr = chld_err.lines;
 
-       /* UNKNOWN if (non-skipped) output found on stderr */
+       /* UNKNOWN or worse if (non-skipped) output found on stderr */
        if(chld_err.lines > skip_stderr) {
                printf (_("Remote command execution failed: %s\n"),
                        chld_err.line[skip_stderr]);
-               return STATE_UNKNOWN;
+               return max_state_alt(result, STATE_UNKNOWN);
        }
 
        /* this is simple if we're not supposed to be passive.
@@ -133,21 +133,20 @@ main (int argc, char **argv)
        local_time = time (NULL);
        commands = 0;
        for(i = skip_stdout; i < chld_out.lines; i++) {
-               status_text = strstr (chld_out.line[i], "STATUS CODE: ");
-               if (status_text == NULL) {
-                       printf ("%s", chld_out.line[i]);
-                       return result;
-               }
+               status_text = chld_out.line[i++];
+               if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL)
+                       die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);
+
                if (service[commands] && status_text
-                       && sscanf (status_text, "STATUS CODE: %d", &cresult) == 1)
+                       && sscanf (chld_out.line[i], "STATUS CODE: %d", &cresult) == 1)
                {
                        fprintf (fp, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n",
                                 (int) local_time, host_shortname, service[commands++],
-                                cresult, chld_out.line[i]);
+                                cresult, status_text);
                }
        }
        
-       /* force an OK state */
+       /* Multiple commands and passive checking should always return OK */
        return result;
 }
 
@@ -308,7 +307,7 @@ process_arguments (int argc, char **argv)
                                asprintf (&remotecmd, "%s", argv[c]);
        }
 
-       if (commands > 1)
+       if (commands > 1 || passive)
                asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
 
        if (remotecmd == NULL || strlen (remotecmd) <= 1)
@@ -368,7 +367,7 @@ print_help (void)
   printf (" %s\n", "-E, --skip-stderr[=n]");
   printf ("    %s\n", _("Ignore all or (if specified) first n lines on STDERR [optional]"));
   printf (" %s\n", "-f");
-  printf ("    %s\n", _("tells ssh to fork rather than create a tty [optional]"));
+  printf ("    %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always return OK if ssh is executed"));
   printf (" %s\n","-C, --command='COMMAND STRING'");
   printf ("    %s\n", _("command to execute on the remote machine"));
   printf (" %s\n","-l, --logname=USERNAME");