summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6b2cc2f)
raw | patch | inline | side by side (parent: 6b2cc2f)
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | |
Wed, 21 May 2008 08:57:13 +0000 (08:57 +0000) | ||
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | |
Wed, 21 May 2008 08:57:13 +0000 (08:57 +0000) |
Also:
- On non-skipped stderr, check_by_ssh now returns UNKNOWN or worse (result from command) instead of always UNKNOWN.
- Fixed passive tests and make is always run the specified number of tests (using fail if there's nothing to test).
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1997 f882894a-f735-0410-b71e-b25c423dba1c
- On non-skipped stderr, check_by_ssh now returns UNKNOWN or worse (result from command) instead of always UNKNOWN.
- Fixed passive tests and make is always run the specified number of tests (using fail if there's nothing to test).
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1997 f882894a-f735-0410-b71e-b25c423dba1c
NEWS | patch | blob | history | |
plugins/check_by_ssh.c | patch | blob | history | |
plugins/t/check_by_ssh.t | patch | blob | history |
index d01b678c94e9de0a9a0e706901a59d1c660704d6..62cb47afb998f94f9b870b18731d1849e1779964 100644 (file)
--- a/NEWS
+++ b/NEWS
negate now has the ability to replace the status text as well (-s, --substitute)
Added performance data to check_ping (Christian Schneemann)
Added support for --extra-opts in all C plugins (disabled by default, see configure --help)
+ Fixed passive option in check_by_ssh
+ On non-skipped stderr, check_by_ssh now returns UNKNOWN or worse (result from command) instead of always UNKNOWN.
1.4.11 13th December 2007
Fixed check_http regression in 1.4.10 where following redirects to
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 9def404dd15def11d316defff44580754bc3ccb9..05c348487717fe0a1a3e734cff9536d8bc5c3a58 100644 (file)
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
if (skip_stderr == -1) /* --skip-stderr specified without argument */
skip_stderr = chld_err.lines;
- /* UNKNOWN if (non-skipped) output found on stderr */
+ /* UNKNOWN or worse if (non-skipped) output found on stderr */
if(chld_err.lines > skip_stderr) {
printf (_("Remote command execution failed: %s\n"),
chld_err.line[skip_stderr]);
- return STATE_UNKNOWN;
+ return max_state_alt(result, STATE_UNKNOWN);
}
/* this is simple if we're not supposed to be passive.
local_time = time (NULL);
commands = 0;
for(i = skip_stdout; i < chld_out.lines; i++) {
- status_text = strstr (chld_out.line[i], "STATUS CODE: ");
- if (status_text == NULL) {
- printf ("%s", chld_out.line[i]);
- return result;
- }
+ status_text = chld_out.line[i++];
+ if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL)
+ die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);
+
if (service[commands] && status_text
- && sscanf (status_text, "STATUS CODE: %d", &cresult) == 1)
+ && sscanf (chld_out.line[i], "STATUS CODE: %d", &cresult) == 1)
{
fprintf (fp, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n",
(int) local_time, host_shortname, service[commands++],
- cresult, chld_out.line[i]);
+ cresult, status_text);
}
}
- /* force an OK state */
+ /* Multiple commands and passive checking should always return OK */
return result;
}
asprintf (&remotecmd, "%s", argv[c]);
}
- if (commands > 1)
+ if (commands > 1 || passive)
asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
if (remotecmd == NULL || strlen (remotecmd) <= 1)
index 8bdb65672c5d96d3c1992d98e8bd59a7b808a96b..88e5405cf07c23f643c0a58dd3bf648b13d9e1ff 100644 (file)
--- a/plugins/t/check_by_ssh.t
+++ b/plugins/t/check_by_ssh.t
plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key);
-plan tests => 38;
+plan tests => 40;
# Some random check strings/response
my @responce = ('OK: Everything is fine!',
'UNKNOWN: What can I do for ya?',
'WOOPS: What did I smoke?',
);
+my @responce_re;
my @check;
for (@responce) {
push(@check, "echo $_");
+ my $re_str = $_;
+ $re_str =~ s{(.)} { "\Q$1" }ge;
+ push(@responce_re, $re_str);
}
my $result;
);
cmp_ok($result->return_code, '==', 0, "Multiple checks always return OK");
my @lines = split(/\n/, $result->output);
+cmp_ok(scalar(@lines), '==', 8, "Correct number of output lined for multiple checks");
my %linemap = (
'0' => '1',
'2' => '0',
}
# Passive checks
+unlink("/tmp/check_by_ssh.$$");
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -n flint -s serv -C '$check[2]; sh -c exit\\ 2' -O /tmp/check_by_ssh.$$"
);
cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks");
open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!");
-my $count=0;
-while (<PASV>) {
- like($_, '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;$responce[2]$/', 'proper result for passive check');
- $count++;
+my @pasv = <PASV>;
+close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!");
+cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed');
+for (0) {
+ if ($pasv[$_]) {
+ like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $responce_re[2] . '$/', 'proper result for passive check');
+ } else {
+ fail('proper result for passive check');
+ }
}
-cmp_ok($count, '==', 1, 'One passive result for one check performed');
unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!");
+undef @pasv;
$result = NPTest->testCmd(
- "./check_by_ssh -i $ssh_key -H $ssh_service -n flint -s c0:c1:c2:c3:c4 -C '$check[0], exit 0' -C '$check[1]; exit 1' -C '$check[2]; exit 2' -C '$check[3]; exit 3' -C '$check[4]; exit 9' -O /tmp/check_by_ssh.$$"
+ "./check_by_ssh -i $ssh_key -H $ssh_service -n flint -s c0:c1:c2:c3:c4 -C '$check[0];sh -c exit\\ 0' -C '$check[1];sh -c exit\\ 1' -C '$check[2];sh -c exit\\ 2' -C '$check[3];sh -c exit\\ 3' -C '$check[4];sh -c exit\\ 9' -O /tmp/check_by_ssh.$$"
);
cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks");
-$count=0;
open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!");
-while (<PASV>) {
- my $ret;
- ($count == 4 ? $ret = 7 : $ret = $count);
- like($_, '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $count . ';' . $ret . ';' . $responce[$count] . '$/', "proper result for passive check $count");
+@pasv = <PASV>;
+close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!");
+cmp_ok(scalar(@pasv), '==', 5, 'Five passive result for five checks performed');
+for (0, 1, 2, 3, 4) {
+ if ($pasv[$_]) {
+ my $ret = $_;
+ $ret = 9 if ($_ == 4);
+ like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $responce_re[$_] . '$/', "proper result for passive check $_");
+ } else {
+ fail("proper result for passive check $_");
+ }
}
-cmp_ok($count, '==', 5, 'Five passive result for five checks performed');
unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!");