adapted from...

From 4b3f684d33af7459024011a06704cf4ca85dd0a3 Mon Sep 17 00:00:00 2001
From: Alvar Penning <post@0x21.biz>
Date: Mon, 15 Sep 2025 22:20:08 +0200
Subject: [PATCH] check_by_ssh: Ignore output on stderr by default

Index: plugins/check_by_ssh.c
--- plugins/check_by_ssh.c.orig
+++ plugins/check_by_ssh.c
@@ -49,6 +49,7 @@ unsigned int commands = 0;
 unsigned int services = 0;
 int skip_stdout = 0;
 int skip_stderr = 0;
+int unknown_on_stderr = 0;
 int warn_on_stderr = 0;
 bool unknown_timeout = false;
 char *remotecmd = NULL;
@@ -120,14 +121,14 @@ main (int argc, char **argv)
 	if (skip_stderr == -1) /* --skip-stderr specified without argument */
 		skip_stderr = chld_err.lines;
 
-	/* UNKNOWN or worse if (non-skipped) output found on stderr */
-	if(chld_err.lines > (size_t)skip_stderr) {
+	/* Allow UNKNOWN or WARNING state for (non-skipped) output found on stderr */
+	if(chld_err.lines > (size_t)skip_stderr && (unknown_on_stderr || warn_on_stderr)) {
 		printf (_("Remote command execution failed: %s\n"),
 		        chld_err.line[skip_stderr]);
-		if ( warn_on_stderr ) 
-			return max_state_alt(result, STATE_WARNING);
-		else
+		if ( unknown_on_stderr )
 			return max_state_alt(result, STATE_UNKNOWN);
+		else if ( warn_on_stderr )
+			return max_state_alt(result, STATE_WARNING);
 	}
 
 	/* this is simple if we're not supposed to be passive.
@@ -201,6 +202,7 @@ process_arguments (int argc, char **argv)
 		{"skip", optional_argument, 0, 'S'}, /* backwards compatibility */
 		{"skip-stdout", optional_argument, 0, 'S'},
 		{"skip-stderr", optional_argument, 0, 'E'},
+		{"unknown-on-stderr", no_argument, 0, 'e'},
 		{"warn-on-stderr", no_argument, 0, 'W'},
 		{"proto1", no_argument, 0, '1'},
 		{"proto2", no_argument, 0, '2'},
@@ -323,6 +325,9 @@ process_arguments (int argc, char **argv)
 			else
 				skip_stderr = atoi (optarg);
 			break;
+		case 'e':									/* exit with UNKNOWN if there is output on stderr */
+			unknown_on_stderr = 1;
+			break;
 		case 'W':									/* exit with warning if there is an output on stderr */
 			warn_on_stderr = 1;
 			break;
@@ -488,7 +493,7 @@ print_usage (void)
 {
 	printf ("%s\n", _("Usage:"));
 	printf (" %s -H <host> -C <command> [-fqvU] [-1|-2] [-4|-6]\n"
-	        "       [-S [lines]] [-E [lines]] [-W] [-t timeout] [-i identity]\n"
+	        "       [-S [lines]] [-E [lines]] [-e|-W] [-t timeout] [-i identity]\n"
 	        "       [-l user] [-n name] [-s servicelist] [-O outputfile]\n"
 	        "       [-p port] [-o ssh-option] [-F configfile]\n",
 	        progname);
