diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2023-01-09 16:55:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 16:55:10 +0100 |
commit | e0ada6f11a82ed6119836482b84c8ba5df491d8f (patch) | |
tree | 6ddcd5f7850169d82d88dca56a2e5c0dbda08b4e /plugins/check_by_ssh.c | |
parent | c389aa4f918aab5cf181aa2cb9dec68b3bf34d4f (diff) | |
parent | 0899e41f5075d661153eb2c77ace1734a8f66bfa (diff) | |
download | monitoring-plugins-e0ada6f.tar.gz |
Merge branch 'master' into rename_output_to_cmd_output
Diffstat (limited to 'plugins/check_by_ssh.c')
-rw-r--r-- | plugins/check_by_ssh.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 193657c3..4ea721b2 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
@@ -50,6 +50,7 @@ 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; | 52 | int warn_on_stderr = 0; |
53 | bool unknown_timeout = FALSE; | ||
53 | char *remotecmd = NULL; | 54 | char *remotecmd = NULL; |
54 | char **commargv = NULL; | 55 | char **commargv = NULL; |
55 | int commargc = 0; | 56 | int commargc = 0; |
@@ -101,6 +102,13 @@ main (int argc, char **argv) | |||
101 | 102 | ||
102 | result = cmd_run_array (commargv, &chld_out, &chld_err, 0); | 103 | result = cmd_run_array (commargv, &chld_out, &chld_err, 0); |
103 | 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 | |||
104 | if (verbose) { | 112 | if (verbose) { |
105 | for(i = 0; i < chld_out.lines; i++) | 113 | for(i = 0; i < chld_out.lines; i++) |
106 | printf("stdout: %s\n", chld_out.line[i]); | 114 | printf("stdout: %s\n", chld_out.line[i]); |
@@ -180,6 +188,7 @@ process_arguments (int argc, char **argv) | |||
180 | {"verbose", no_argument, 0, 'v'}, | 188 | {"verbose", no_argument, 0, 'v'}, |
181 | {"fork", no_argument, 0, 'f'}, | 189 | {"fork", no_argument, 0, 'f'}, |
182 | {"timeout", required_argument, 0, 't'}, | 190 | {"timeout", required_argument, 0, 't'}, |
191 | {"unknown-timeout", no_argument, 0, 'U'}, | ||
183 | {"host", required_argument, 0, 'H'}, /* backward compatibility */ | 192 | {"host", required_argument, 0, 'H'}, /* backward compatibility */ |
184 | {"hostname", required_argument, 0, 'H'}, | 193 | {"hostname", required_argument, 0, 'H'}, |
185 | {"port", required_argument,0,'p'}, | 194 | {"port", required_argument,0,'p'}, |
@@ -212,7 +221,7 @@ process_arguments (int argc, char **argv) | |||
212 | strcpy (argv[c], "-t"); | 221 | strcpy (argv[c], "-t"); |
213 | 222 | ||
214 | while (1) { | 223 | while (1) { |
215 | 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, |
216 | &option); | 225 | &option); |
217 | 226 | ||
218 | if (c == -1 || c == EOF) | 227 | if (c == -1 || c == EOF) |
@@ -234,6 +243,9 @@ process_arguments (int argc, char **argv) | |||
234 | else | 243 | else |
235 | timeout_interval = atoi (optarg); | 244 | timeout_interval = atoi (optarg); |
236 | break; | 245 | break; |
246 | case 'U': | ||
247 | unknown_timeout = TRUE; | ||
248 | break; | ||
237 | case 'H': /* host */ | 249 | case 'H': /* host */ |
238 | hostname = optarg; | 250 | hostname = optarg; |
239 | break; | 251 | break; |
@@ -445,6 +457,8 @@ print_help (void) | |||
445 | 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]")); |
446 | printf (UT_WARN_CRIT); | 458 | printf (UT_WARN_CRIT); |
447 | 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")); | ||
448 | printf (UT_VERBOSE); | 462 | printf (UT_VERBOSE); |
449 | printf("\n"); | 463 | printf("\n"); |
450 | 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")); |
@@ -474,7 +488,7 @@ void | |||
474 | print_usage (void) | 488 | print_usage (void) |
475 | { | 489 | { |
476 | printf ("%s\n", _("Usage:")); | 490 | printf ("%s\n", _("Usage:")); |
477 | 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" |
478 | " [-S [lines]] [-E [lines]] [-W] [-t timeout] [-i identity]\n" | 492 | " [-S [lines]] [-E [lines]] [-W] [-t timeout] [-i identity]\n" |
479 | " [-l user] [-n name] [-s servicelist] [-O outputfile]\n" | 493 | " [-l user] [-n name] [-s servicelist] [-O outputfile]\n" |
480 | " [-p port] [-o ssh-option] [-F configfile]\n", | 494 | " [-p port] [-o ssh-option] [-F configfile]\n", |