summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_by_ssh.t
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-05-21 08:57:13 +0000
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-05-21 08:57:13 +0000
commitb52e63da65ac5db7affbd09e110904855f3b1ed7 (patch)
tree58f05c66343ca46dc792a3d0842da1598f3ae1f7 /plugins/t/check_by_ssh.t
parent6b2cc2f23c6665f0990701a1fd93d4c99840842d (diff)
downloadmonitoring-plugins-b52e63da65ac5db7affbd09e110904855f3b1ed7.tar.gz
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). git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1997 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/t/check_by_ssh.t')
-rw-r--r--plugins/t/check_by_ssh.t42
1 files changed, 29 insertions, 13 deletions
diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t
index 8bdb6567..88e5405c 100644
--- a/plugins/t/check_by_ssh.t
+++ b/plugins/t/check_by_ssh.t
@@ -20,7 +20,7 @@ my $ssh_key = getTestParameter( "NP_SSH_IDENTITY",
20 20
21plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); 21plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key);
22 22
23plan tests => 38; 23plan tests => 40;
24 24
25# Some random check strings/response 25# Some random check strings/response
26my @responce = ('OK: Everything is fine!', 26my @responce = ('OK: Everything is fine!',
@@ -29,9 +29,13 @@ my @responce = ('OK: Everything is fine!',
29 'UNKNOWN: What can I do for ya?', 29 'UNKNOWN: What can I do for ya?',
30 'WOOPS: What did I smoke?', 30 'WOOPS: What did I smoke?',
31); 31);
32my @responce_re;
32my @check; 33my @check;
33for (@responce) { 34for (@responce) {
34 push(@check, "echo $_"); 35 push(@check, "echo $_");
36 my $re_str = $_;
37 $re_str =~ s{(.)} { "\Q$1" }ge;
38 push(@responce_re, $re_str);
35} 39}
36 40
37my $result; 41my $result;
@@ -88,6 +92,7 @@ $result = NPTest->testCmd(
88 ); 92 );
89cmp_ok($result->return_code, '==', 0, "Multiple checks always return OK"); 93cmp_ok($result->return_code, '==', 0, "Multiple checks always return OK");
90my @lines = split(/\n/, $result->output); 94my @lines = split(/\n/, $result->output);
95cmp_ok(scalar(@lines), '==', 8, "Correct number of output lined for multiple checks");
91my %linemap = ( 96my %linemap = (
92 '0' => '1', 97 '0' => '1',
93 '2' => '0', 98 '2' => '0',
@@ -102,30 +107,41 @@ foreach my $line (0, 2, 4, 6) {
102} 107}
103 108
104# Passive checks 109# Passive checks
110unlink("/tmp/check_by_ssh.$$");
105$result = NPTest->testCmd( 111$result = NPTest->testCmd(
106 "./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.$$" 112 "./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.$$"
107 ); 113 );
108cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks"); 114cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks");
109open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!"); 115open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!");
110my $count=0; 116my @pasv = <PASV>;
111while (<PASV>) { 117close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!");
112 like($_, '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;$responce[2]$/', 'proper result for passive check'); 118cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed');
113 $count++; 119for (0) {
120 if ($pasv[$_]) {
121 like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $responce_re[2] . '$/', 'proper result for passive check');
122 } else {
123 fail('proper result for passive check');
124 }
114} 125}
115cmp_ok($count, '==', 1, 'One passive result for one check performed');
116unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!"); 126unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!");
127undef @pasv;
117 128
118$result = NPTest->testCmd( 129$result = NPTest->testCmd(
119 "./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.$$" 130 "./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.$$"
120 ); 131 );
121cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks"); 132cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks");
122$count=0;
123open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!"); 133open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!");
124while (<PASV>) { 134@pasv = <PASV>;
125 my $ret; 135close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!");
126 ($count == 4 ? $ret = 7 : $ret = $count); 136cmp_ok(scalar(@pasv), '==', 5, 'Five passive result for five checks performed');
127 like($_, '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $count . ';' . $ret . ';' . $responce[$count] . '$/', "proper result for passive check $count"); 137for (0, 1, 2, 3, 4) {
138 if ($pasv[$_]) {
139 my $ret = $_;
140 $ret = 9 if ($_ == 4);
141 like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $responce_re[$_] . '$/', "proper result for passive check $_");
142 } else {
143 fail("proper result for passive check $_");
144 }
128} 145}
129cmp_ok($count, '==', 5, 'Five passive result for five checks performed');
130unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!"); 146unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!");
131 147