diff options
Diffstat (limited to 'plugins/check_by_ssh.c')
-rw-r--r-- | plugins/check_by_ssh.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 04bce38d..1ad547ed 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
@@ -49,6 +49,8 @@ unsigned int commands = 0; | |||
49 | unsigned int services = 0; | 49 | unsigned int services = 0; |
50 | int skip_stdout = 0; | 50 | int skip_stdout = 0; |
51 | int skip_stderr = 0; | 51 | int skip_stderr = 0; |
52 | int warn_on_stderr = 0; | ||
53 | bool unknown_timeout = FALSE; | ||
52 | char *remotecmd = NULL; | 54 | char *remotecmd = NULL; |
53 | char **commargv = NULL; | 55 | char **commargv = NULL; |
54 | int commargc = 0; | 56 | int commargc = 0; |
@@ -100,6 +102,20 @@ main (int argc, char **argv) | |||
100 | 102 | ||
101 | result = cmd_run_array (commargv, &chld_out, &chld_err, 0); | 103 | result = cmd_run_array (commargv, &chld_out, &chld_err, 0); |
102 | 104 | ||
105 | /* SSH returns 255 if connection attempt fails; include the first line of error output */ | ||
106 | if (result == 255 && unknown_timeout) { | ||
107 | printf (_("SSH connection failed: %s\n"), | ||
108 | chld_err.lines > 0 ? chld_err.line[0] : "(no error output)"); | ||
109 | return STATE_UNKNOWN; | ||
110 | } | ||
111 | |||
112 | if (verbose) { | ||
113 | for(i = 0; i < chld_out.lines; i++) | ||
114 | printf("stdout: %s\n", chld_out.line[i]); | ||
115 | for(i = 0; i < chld_err.lines; i++) | ||
116 | printf("stderr: %s\n", chld_err.line[i]); | ||
117 | } | ||
118 | |||
103 | if (skip_stdout == -1) /* --skip-stdout specified without argument */ | 119 | if (skip_stdout == -1) /* --skip-stdout specified without argument */ |
104 | skip_stdout = chld_out.lines; | 120 | skip_stdout = chld_out.lines; |
105 | if (skip_stderr == -1) /* --skip-stderr specified without argument */ | 121 | if (skip_stderr == -1) /* --skip-stderr specified without argument */ |
@@ -109,7 +125,10 @@ main (int argc, char **argv) | |||
109 | if(chld_err.lines > skip_stderr) { | 125 | if(chld_err.lines > skip_stderr) { |
110 | printf (_("Remote command execution failed: %s\n"), | 126 | printf (_("Remote command execution failed: %s\n"), |
111 | chld_err.line[skip_stderr]); | 127 | chld_err.line[skip_stderr]); |
112 | return max_state_alt(result, STATE_UNKNOWN); | 128 | if ( warn_on_stderr ) |
129 | return max_state_alt(result, STATE_WARNING); | ||
130 | else | ||
131 | return max_state_alt(result, STATE_UNKNOWN); | ||
113 | } | 132 | } |
114 | 133 | ||
115 | /* this is simple if we're not supposed to be passive. | 134 | /* this is simple if we're not supposed to be passive. |
@@ -169,6 +188,7 @@ process_arguments (int argc, char **argv) | |||
169 | {"verbose", no_argument, 0, 'v'}, | 188 | {"verbose", no_argument, 0, 'v'}, |
170 | {"fork", no_argument, 0, 'f'}, | 189 | {"fork", no_argument, 0, 'f'}, |
171 | {"timeout", required_argument, 0, 't'}, | 190 | {"timeout", required_argument, 0, 't'}, |
191 | {"unknown-timeout", no_argument, 0, 'U'}, | ||
172 | {"host", required_argument, 0, 'H'}, /* backward compatibility */ | 192 | {"host", required_argument, 0, 'H'}, /* backward compatibility */ |
173 | {"hostname", required_argument, 0, 'H'}, | 193 | {"hostname", required_argument, 0, 'H'}, |
174 | {"port", required_argument,0,'p'}, | 194 | {"port", required_argument,0,'p'}, |
@@ -182,6 +202,7 @@ process_arguments (int argc, char **argv) | |||
182 | {"skip", optional_argument, 0, 'S'}, /* backwards compatibility */ | 202 | {"skip", optional_argument, 0, 'S'}, /* backwards compatibility */ |
183 | {"skip-stdout", optional_argument, 0, 'S'}, | 203 | {"skip-stdout", optional_argument, 0, 'S'}, |
184 | {"skip-stderr", optional_argument, 0, 'E'}, | 204 | {"skip-stderr", optional_argument, 0, 'E'}, |
205 | {"warn-on-stderr", no_argument, 0, 'W'}, | ||
185 | {"proto1", no_argument, 0, '1'}, | 206 | {"proto1", no_argument, 0, '1'}, |
186 | {"proto2", no_argument, 0, '2'}, | 207 | {"proto2", no_argument, 0, '2'}, |
187 | {"use-ipv4", no_argument, 0, '4'}, | 208 | {"use-ipv4", no_argument, 0, '4'}, |
@@ -200,7 +221,7 @@ process_arguments (int argc, char **argv) | |||
200 | strcpy (argv[c], "-t"); | 221 | strcpy (argv[c], "-t"); |
201 | 222 | ||
202 | while (1) { | 223 | while (1) { |
203 | c = getopt_long (argc, argv, "Vvh1246fqt:H:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, | 224 | c = getopt_long (argc, argv, "Vvh1246fqt:UH:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, |
204 | &option); | 225 | &option); |
205 | 226 | ||
206 | if (c == -1 || c == EOF) | 227 | if (c == -1 || c == EOF) |
@@ -222,8 +243,10 @@ process_arguments (int argc, char **argv) | |||
222 | else | 243 | else |
223 | timeout_interval = atoi (optarg); | 244 | timeout_interval = atoi (optarg); |
224 | break; | 245 | break; |
246 | case 'U': | ||
247 | unknown_timeout = TRUE; | ||
248 | break; | ||
225 | case 'H': /* host */ | 249 | case 'H': /* host */ |
226 | host_or_die(optarg); | ||
227 | hostname = optarg; | 250 | hostname = optarg; |
228 | break; | 251 | break; |
229 | case 'p': /* port number */ | 252 | case 'p': /* port number */ |
@@ -301,6 +324,9 @@ process_arguments (int argc, char **argv) | |||
301 | else | 324 | else |
302 | skip_stderr = atoi (optarg); | 325 | skip_stderr = atoi (optarg); |
303 | break; | 326 | break; |
327 | case 'W': /* exit with warning if there is an output on stderr */ | ||
328 | warn_on_stderr = 1; | ||
329 | break; | ||
304 | case 'o': /* Extra options for the ssh command */ | 330 | case 'o': /* Extra options for the ssh command */ |
305 | comm_append("-o"); | 331 | comm_append("-o"); |
306 | comm_append(optarg); | 332 | comm_append(optarg); |
@@ -322,7 +348,6 @@ process_arguments (int argc, char **argv) | |||
322 | if (c <= argc) { | 348 | if (c <= argc) { |
323 | die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname); | 349 | die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname); |
324 | } | 350 | } |
325 | host_or_die(argv[c]); | ||
326 | hostname = argv[c++]; | 351 | hostname = argv[c++]; |
327 | } | 352 | } |
328 | 353 | ||
@@ -408,6 +433,8 @@ print_help (void) | |||
408 | printf (" %s\n", _("Ignore all or (if specified) first n lines on STDOUT [optional]")); | 433 | printf (" %s\n", _("Ignore all or (if specified) first n lines on STDOUT [optional]")); |
409 | printf (" %s\n", "-E, --skip-stderr[=n]"); | 434 | printf (" %s\n", "-E, --skip-stderr[=n]"); |
410 | printf (" %s\n", _("Ignore all or (if specified) first n lines on STDERR [optional]")); | 435 | printf (" %s\n", _("Ignore all or (if specified) first n lines on STDERR [optional]")); |
436 | printf (" %s\n", "-W, --warn-on-stderr]"); | ||
437 | printf (" %s\n", _("Exit with an warning, if there is an output on STDERR")); | ||
411 | printf (" %s\n", "-f"); | 438 | printf (" %s\n", "-f"); |
412 | printf (" %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always return OK if ssh is executed")); | 439 | printf (" %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always return OK if ssh is executed")); |
413 | printf (" %s\n","-C, --command='COMMAND STRING'"); | 440 | printf (" %s\n","-C, --command='COMMAND STRING'"); |
@@ -430,6 +457,8 @@ print_help (void) | |||
430 | printf (" %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]")); | 457 | printf (" %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]")); |
431 | printf (UT_WARN_CRIT); | 458 | printf (UT_WARN_CRIT); |
432 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 459 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
460 | printf (" %s\n","-U, --unknown-timeout"); | ||
461 | printf (" %s\n", _("Make connection problems return UNKNOWN instead of CRITICAL")); | ||
433 | printf (UT_VERBOSE); | 462 | printf (UT_VERBOSE); |
434 | printf("\n"); | 463 | printf("\n"); |
435 | printf (" %s\n", _("The most common mode of use is to refer to a local identity file with")); | 464 | printf (" %s\n", _("The most common mode of use is to refer to a local identity file with")); |
@@ -459,8 +488,8 @@ void | |||
459 | print_usage (void) | 488 | print_usage (void) |
460 | { | 489 | { |
461 | printf ("%s\n", _("Usage:")); | 490 | printf ("%s\n", _("Usage:")); |
462 | printf (" %s -H <host> -C <command> [-fqv] [-1|-2] [-4|-6]\n" | 491 | printf (" %s -H <host> -C <command> [-fqvU] [-1|-2] [-4|-6]\n" |
463 | " [-S [lines]] [-E [lines]] [-t timeout] [-i identity]\n" | 492 | " [-S [lines]] [-E [lines]] [-W] [-t timeout] [-i identity]\n" |
464 | " [-l user] [-n name] [-s servicelist] [-O outputfile]\n" | 493 | " [-l user] [-n name] [-s servicelist] [-O outputfile]\n" |
465 | " [-p port] [-o ssh-option] [-F configfile]\n", | 494 | " [-p port] [-o ssh-option] [-F configfile]\n", |
466 | progname); | 495 | progname); |