aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_by_ssh.c
diff options
context:
space:
mode:
authorGravatar Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> 2008-05-21 08:57:13 +0000
committerGravatar Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> 2008-05-21 08:57:13 +0000
commitb52e63da65ac5db7affbd09e110904855f3b1ed7 (patch)
tree58f05c66343ca46dc792a3d0842da1598f3ae1f7 /plugins/check_by_ssh.c
parent6b2cc2f23c6665f0990701a1fd93d4c99840842d (diff)
downloadmonitoring-plugins-b52e63da65ac5db7affbd09e110904855f3b1ed7.tar.gz
Fixed passive option in check_by_ssh
Also: - On non-skipped stderr, check_by_ssh now returns UNKNOWN or worse (result from command) instead of always UNKNOWN. - Fixed passive tests and make is always run the specified number of tests (using fail if there's nothing to test). git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1997 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_by_ssh.c')
-rw-r--r--plugins/check_by_ssh.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 9def404d..05c34848 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -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)