[Nagiosplug-devel] patch for check_by_ssh passive mode

mike mike at primaledge.ca
Wed Jan 9 02:02:42 CET 2008


last one, I promise.  using it now in prod and it's working great.  ok i'm
gone (btw i'm not on this list, send comments, hate mail etc to me directly)

--- check_by_ssh.c.orig 2007-09-23 05:26:03.000000000 -0700
+++ check_by_ssh.c      2008-01-08 13:39:49.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 (i > 0 && strstr (chld_out.line[i-1], "STATUS
CODE: ") == 0) fprintf (fp, "%s\n", chld_out.line[i-1]);
+                       else fprintf (fp, "%s - Remote command exit status
%d\n",
+                                        state_text(cresult), cresult);
                }
        }

@@ -307,7 +305,7 @@ process_arguments (int argc, char **argv
                                asprintf (&remotecmd, "%s", argv[c]);
        }

-       if (commands > 1)
+       if (passive)
                asprintf (&remotecmd, "%s;echo STATUS CODE: $?;",
remotecmd);

        if (remotecmd == NULL || strlen (remotecmd) <= 1)



On 1/7/08, mike <mike at primaledge.ca> wrote:
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nagios-plugins.org/archive/devel/attachments/20080108/9109a592/attachment.html>


More information about the Devel mailing list