summaryrefslogtreecommitdiffstats
path: root/plugins/check_by_ssh.c
diff options
context:
space:
mode:
authorLorenz <12514511+RincewindsHat@users.noreply.github.com>2022-01-14 14:44:05 (GMT)
committerGitHub <noreply@github.com>2022-01-14 14:44:05 (GMT)
commitd999db01c07558ec9242f6e6a435a5d215d76ed6 (patch)
tree88150ff6bb21d62bf699c24504b753e0e7a5e16a /plugins/check_by_ssh.c
parent9899bc736f45400fa70bdee281f5f5b46490b805 (diff)
parentbb16b73130519cf5e93340480c8fd5e7e696a15f (diff)
downloadmonitoring-plugins-d999db01c07558ec9242f6e6a435a5d215d76ed6.tar.gz
Merge pull request #1301 from nafets/exit_on_stderr
check_by_ssh: added option to exit with an warning, if there is output on STDERR
Diffstat (limited to 'plugins/check_by_ssh.c')
-rw-r--r--plugins/check_by_ssh.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 485bf3b..39d4907 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -49,6 +49,7 @@ unsigned int commands = 0;
49unsigned int services = 0; 49unsigned int services = 0;
50int skip_stdout = 0; 50int skip_stdout = 0;
51int skip_stderr = 0; 51int skip_stderr = 0;
52int warn_on_stderr = 0;
52char *remotecmd = NULL; 53char *remotecmd = NULL;
53char **commargv = NULL; 54char **commargv = NULL;
54int commargc = 0; 55int commargc = 0;
@@ -116,7 +117,10 @@ main (int argc, char **argv)
116 if(chld_err.lines > skip_stderr) { 117 if(chld_err.lines > skip_stderr) {
117 printf (_("Remote command execution failed: %s\n"), 118 printf (_("Remote command execution failed: %s\n"),
118 chld_err.line[skip_stderr]); 119 chld_err.line[skip_stderr]);
119 return max_state_alt(result, STATE_UNKNOWN); 120 if ( warn_on_stderr )
121 return max_state_alt(result, STATE_WARNING);
122 else
123 return max_state_alt(result, STATE_UNKNOWN);
120 } 124 }
121 125
122 /* this is simple if we're not supposed to be passive. 126 /* this is simple if we're not supposed to be passive.
@@ -189,6 +193,7 @@ process_arguments (int argc, char **argv)
189 {"skip", optional_argument, 0, 'S'}, /* backwards compatibility */ 193 {"skip", optional_argument, 0, 'S'}, /* backwards compatibility */
190 {"skip-stdout", optional_argument, 0, 'S'}, 194 {"skip-stdout", optional_argument, 0, 'S'},
191 {"skip-stderr", optional_argument, 0, 'E'}, 195 {"skip-stderr", optional_argument, 0, 'E'},
196 {"warn-on-stderr", no_argument, 0, 'W'},
192 {"proto1", no_argument, 0, '1'}, 197 {"proto1", no_argument, 0, '1'},
193 {"proto2", no_argument, 0, '2'}, 198 {"proto2", no_argument, 0, '2'},
194 {"use-ipv4", no_argument, 0, '4'}, 199 {"use-ipv4", no_argument, 0, '4'},
@@ -307,6 +312,9 @@ process_arguments (int argc, char **argv)
307 else 312 else
308 skip_stderr = atoi (optarg); 313 skip_stderr = atoi (optarg);
309 break; 314 break;
315 case 'W': /* exit with warning if there is an output on stderr */
316 warn_on_stderr = 1;
317 break;
310 case 'o': /* Extra options for the ssh command */ 318 case 'o': /* Extra options for the ssh command */
311 comm_append("-o"); 319 comm_append("-o");
312 comm_append(optarg); 320 comm_append(optarg);
@@ -413,6 +421,8 @@ print_help (void)
413 printf (" %s\n", _("Ignore all or (if specified) first n lines on STDOUT [optional]")); 421 printf (" %s\n", _("Ignore all or (if specified) first n lines on STDOUT [optional]"));
414 printf (" %s\n", "-E, --skip-stderr[=n]"); 422 printf (" %s\n", "-E, --skip-stderr[=n]");
415 printf (" %s\n", _("Ignore all or (if specified) first n lines on STDERR [optional]")); 423 printf (" %s\n", _("Ignore all or (if specified) first n lines on STDERR [optional]"));
424 printf (" %s\n", "-W, --warn-on-stderr]");
425 printf (" %s\n", _("Exit with an warning, if there is an output on STDERR"));
416 printf (" %s\n", "-f"); 426 printf (" %s\n", "-f");
417 printf (" %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always return OK if ssh is executed")); 427 printf (" %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always return OK if ssh is executed"));
418 printf (" %s\n","-C, --command='COMMAND STRING'"); 428 printf (" %s\n","-C, --command='COMMAND STRING'");
@@ -465,7 +475,7 @@ print_usage (void)
465{ 475{
466 printf ("%s\n", _("Usage:")); 476 printf ("%s\n", _("Usage:"));
467 printf (" %s -H <host> -C <command> [-fqv] [-1|-2] [-4|-6]\n" 477 printf (" %s -H <host> -C <command> [-fqv] [-1|-2] [-4|-6]\n"
468 " [-S [lines]] [-E [lines]] [-t timeout] [-i identity]\n" 478 " [-S [lines]] [-E [lines]] [-W] [-t timeout] [-i identity]\n"
469 " [-l user] [-n name] [-s servicelist] [-O outputfile]\n" 479 " [-l user] [-n name] [-s servicelist] [-O outputfile]\n"
470 " [-p port] [-o ssh-option] [-F configfile]\n", 480 " [-p port] [-o ssh-option] [-F configfile]\n",
471 progname); 481 progname);