[Nagiosplug-checkins] SF.net SVN: nagiosplug: [1997] nagiosplug/trunk
dermoth at users.sourceforge.net
dermoth at users.sourceforge.net
Wed May 21 10:57:14 CEST 2008
Revision: 1997
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1997&view=rev
Author: dermoth
Date: 2008-05-21 01:57:13 -0700 (Wed, 21 May 2008)
Log Message:
-----------
Fixed passive option in check_by_ssh
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).
Modified Paths:
--------------
nagiosplug/trunk/NEWS
nagiosplug/trunk/plugins/check_by_ssh.c
nagiosplug/trunk/plugins/t/check_by_ssh.t
Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS 2008-05-20 11:37:27 UTC (rev 1996)
+++ nagiosplug/trunk/NEWS 2008-05-21 08:57:13 UTC (rev 1997)
@@ -23,6 +23,8 @@
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
Modified: nagiosplug/trunk/plugins/check_by_ssh.c
===================================================================
--- nagiosplug/trunk/plugins/check_by_ssh.c 2008-05-20 11:37:27 UTC (rev 1996)
+++ nagiosplug/trunk/plugins/check_by_ssh.c 2008-05-21 08:57:13 UTC (rev 1997)
@@ -100,11 +100,11 @@
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.
@@ -133,21 +133,20 @@
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;
}
@@ -308,7 +307,7 @@
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)
Modified: nagiosplug/trunk/plugins/t/check_by_ssh.t
===================================================================
--- nagiosplug/trunk/plugins/t/check_by_ssh.t 2008-05-20 11:37:27 UTC (rev 1996)
+++ nagiosplug/trunk/plugins/t/check_by_ssh.t 2008-05-21 08:57:13 UTC (rev 1997)
@@ -20,7 +20,7 @@
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!',
@@ -29,9 +29,13 @@
'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;
@@ -88,6 +92,7 @@
);
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',
@@ -102,30 +107,41 @@
}
# 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");
+ at 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.$$': $!");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list