summaryrefslogtreecommitdiffstats
path: root/plugins/check_by_ssh.c
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-05-21 08:57:13 (GMT)
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-05-21 08:57:13 (GMT)
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 9def404..05c3484 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -100,11 +100,11 @@ main (int argc, char **argv)
100 if (skip_stderr == -1) /* --skip-stderr specified without argument */ 100 if (skip_stderr == -1) /* --skip-stderr specified without argument */
101 skip_stderr = chld_err.lines; 101 skip_stderr = chld_err.lines;
102 102
103 /* UNKNOWN if (non-skipped) output found on stderr */ 103 /* UNKNOWN or worse if (non-skipped) output found on stderr */
104 if(chld_err.lines > skip_stderr) { 104 if(chld_err.lines > skip_stderr) {
105 printf (_("Remote command execution failed: %s\n"), 105 printf (_("Remote command execution failed: %s\n"),
106 chld_err.line[skip_stderr]); 106 chld_err.line[skip_stderr]);
107 return STATE_UNKNOWN; 107 return max_state_alt(result, STATE_UNKNOWN);
108 } 108 }
109 109
110 /* this is simple if we're not supposed to be passive. 110 /* this is simple if we're not supposed to be passive.
@@ -133,21 +133,20 @@ main (int argc, char **argv)
133 local_time = time (NULL); 133 local_time = time (NULL);
134 commands = 0; 134 commands = 0;
135 for(i = skip_stdout; i < chld_out.lines; i++) { 135 for(i = skip_stdout; i < chld_out.lines; i++) {
136 status_text = strstr (chld_out.line[i], "STATUS CODE: "); 136 status_text = chld_out.line[i++];
137 if (status_text == NULL) { 137 if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL)
138 printf ("%s", chld_out.line[i]); 138 die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);
139 return result; 139
140 }
141 if (service[commands] && status_text 140 if (service[commands] && status_text
142 && sscanf (status_text, "STATUS CODE: %d", &cresult) == 1) 141 && sscanf (chld_out.line[i], "STATUS CODE: %d", &cresult) == 1)
143 { 142 {
144 fprintf (fp, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", 143 fprintf (fp, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n",
145 (int) local_time, host_shortname, service[commands++], 144 (int) local_time, host_shortname, service[commands++],
146 cresult, chld_out.line[i]); 145 cresult, status_text);
147 } 146 }
148 } 147 }
149 148
150 /* force an OK state */ 149 /* Multiple commands and passive checking should always return OK */
151 return result; 150 return result;
152} 151}
153 152
@@ -308,7 +307,7 @@ process_arguments (int argc, char **argv)
308 asprintf (&remotecmd, "%s", argv[c]); 307 asprintf (&remotecmd, "%s", argv[c]);
309 } 308 }
310 309
311 if (commands > 1) 310 if (commands > 1 || passive)
312 asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd); 311 asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
313 312
314 if (remotecmd == NULL || strlen (remotecmd) <= 1) 313 if (remotecmd == NULL || strlen (remotecmd) <= 1)