[Nagiosplug-devel] patch for check_by_ssh passive mode

mike mike at primaledge.ca
Tue Jan 8 00:01:40 CET 2008


The current one doesn't really work.  It basically did nothing if there was
a \n anywhere in the command output (most commands return a \n at the end
:)  This makes it better by writing the last output line (up to the \n) in
the log, and doesn't abort if one of the commands has an error.  Still isn't
perfect but it's usable.
Enjoy,
Mike


--- check_by_ssh.c.orig 2007-09-23 05:26:03.000000000 -0700
+++ check_by_ssh.c      2008-01-07 14:59:42.000000000 -0800
@@ -100,7 +100,7 @@ main (int argc, char **argv)
                skip_stderr = chld_err.lines;

        /* UNKNOWN if (non-skipped) output found on stderr */
-       if(chld_err.lines > skip_stderr) {
+       if(!passive && chld_err.lines > skip_stderr) {
                printf (_("Remote command execution failed: %s\n"),
                        chld_err.line[skip_stderr]);
                return STATE_UNKNOWN;
@@ -133,16 +133,14 @@ main (int argc, char **argv)
        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;
-               }
                if (service[commands] && status_text
                        && sscanf (status_text, "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]);
+                       fprintf (fp, "[%d]
PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;",
+                                (int) local_time, host_shortname,
service[commands++], cresult);
+                       if (cresult == 0) fprintf (fp, "%s\n",
chld_out.line[i-1]);
+                       else if(chld_err.lines > skip_stderr)
+                               fprintf (fp, "%s\n",
chld_err.line[skip_stderr]);
                }
        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nagios-plugins.org/archive/devel/attachments/20080107/46e36c4e/attachment.html>


More information about the Devel mailing list