summaryrefslogtreecommitdiffstats
path: root/plugins/check_by_ssh.c
diff options
context:
space:
mode:
authorArchie L. Cobbs <archie.cobbs@gmail.com>2022-07-14 06:47:54 (GMT)
committerGitHub <noreply@github.com>2022-07-14 06:47:54 (GMT)
commitccf4ed25f9c96e4d0cd647bbd8d91f38df75dfc0 (patch)
tree628738bdc24a81f22e0cde8a83f616973c0a25c9 /plugins/check_by_ssh.c
parent175e43133c9dbeb156e52b8e54cd04e44401f424 (diff)
downloadmonitoring-plugins-ccf4ed25f9c96e4d0cd647bbd8d91f38df75dfc0.tar.gz
check_by_ssh: Add "-U" flag (#1123). (#1774)
This causes a 255 exit value from ssh(1), which indicates a connection failure, to return UNKNOWN instead of CRITICAL; similar to check_nrpe's "-u" flag.
Diffstat (limited to 'plugins/check_by_ssh.c')
-rw-r--r--plugins/check_by_ssh.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 39d4907..1ad547e 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -50,6 +50,7 @@ unsigned int services = 0;
50int skip_stdout = 0; 50int skip_stdout = 0;
51int skip_stderr = 0; 51int skip_stderr = 0;
52int warn_on_stderr = 0; 52int warn_on_stderr = 0;
53bool unknown_timeout = FALSE;
53char *remotecmd = NULL; 54char *remotecmd = NULL;
54char **commargv = NULL; 55char **commargv = NULL;
55int commargc = 0; 56int 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
474print_usage (void) 488print_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",