File monitoring-plugins-2.3.1-check_by_ssh.patch of Package monitoring-plugins

diff -ur monitoring-plugins-2.3.1.orig/plugins/check_by_ssh.c monitoring-plugins-2.3.1/plugins/check_by_ssh.c
--- monitoring-plugins-2.3.1.orig/plugins/check_by_ssh.c	2021-04-10 07:13:41.000000000 -0500
+++ monitoring-plugins-2.3.1/plugins/check_by_ssh.c	2022-07-02 10:33:49.977417534 -0500
@@ -49,6 +49,7 @@
 unsigned int services = 0;
 int skip_stdout = 0;
 int skip_stderr = 0;
+int unknown_timeout = 0;
 char *remotecmd = NULL;
 char **commargv = NULL;
 int commargc = 0;
@@ -100,6 +101,13 @@
 
 	result = cmd_run_array (commargv, &chld_out, &chld_err, 0);
 
+	/* SSH returns 255 if connection attempt fails; include the first line of error output */
+	if (result == 255 && unknown_timeout) {
+		printf (_("SSH connection failed: %s\n"),
+		        chld_err.lines > 0 ? chld_err.line[0] : "(no error output)");
+		return STATE_UNKNOWN;
+	}
+
 	if (verbose) {
 		for(i = 0; i < chld_out.lines; i++)
 			printf("stdout: %s\n", chld_out.line[i]);
@@ -176,6 +184,7 @@
 		{"verbose", no_argument, 0, 'v'},
 		{"fork", no_argument, 0, 'f'},
 		{"timeout", required_argument, 0, 't'},
+		{"unknown-timeout", no_argument, 0, 'U'},
 		{"host", required_argument, 0, 'H'},    /* backward compatibility */
 		{"hostname", required_argument, 0, 'H'},
 		{"port", required_argument,0,'p'},
@@ -207,7 +216,7 @@
 			strcpy (argv[c], "-t");
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vvh1246fqt:H:O:p:i:u:l:C:S::E::n:s:o:F:", longopts,
+		c = getopt_long (argc, argv, "Vvh1246fqt:UH:O:p:i:u:l:C:S::E::n:s:o:F:", longopts,
 		                 &option);
 
 		if (c == -1 || c == EOF)
@@ -229,6 +238,9 @@
 			else
 				timeout_interval = atoi (optarg);
 			break;
+		case 'U':
+			unknown_timeout = 1;
+			break;
 		case 'H':									/* host */
 			host_or_die(optarg);
 			hostname = optarg;
@@ -437,6 +449,8 @@
   printf ("    %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]"));
 	printf (UT_WARN_CRIT);
 	printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
+	printf (" %s\n","-U, --unknown-timeout");
+	printf ("    %s\n", _("Make connection problems return UNKNOWN instead of CRITICAL"));
 	printf (UT_VERBOSE);
 	printf("\n");
   printf (" %s\n", _("The most common mode of use is to refer to a local identity file with"));
@@ -466,7 +480,7 @@
 print_usage (void)
 {
 	printf ("%s\n", _("Usage:"));
-	printf (" %s -H <host> -C <command> [-fqv] [-1|-2] [-4|-6]\n"
+	printf (" %s -H <host> -C <command> [-fqvU] [-1|-2] [-4|-6]\n"
 	        "       [-S [lines]] [-E [lines]] [-t timeout] [-i identity]\n"
 	        "       [-l user] [-n name] [-s servicelist] [-O outputfile]\n"
 	        "       [-p port] [-o ssh-option] [-F configfile]\n",
openSUSE Build Service is sponsored by