summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-05-20 11:37:27 (GMT)
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-05-20 11:37:27 (GMT)
commit6b2cc2f23c6665f0990701a1fd93d4c99840842d (patch)
tree8f51ea6c28eef6c51b76325a38d9eb731db6871d /plugins/t
parent5ed2b9258241449b40ff55f5e3d5d3fd40c17167 (diff)
downloadmonitoring-plugins-6b2cc2f23c6665f0990701a1fd93d4c99840842d.tar.gz
Oops - forgot to remove the SKIP block (which didn't seem to work fine)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1996 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/t')
-rw-r--r--plugins/t/check_by_ssh.t186
1 files changed, 91 insertions, 95 deletions
diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t
index 34b749f..8bdb656 100644
--- a/plugins/t/check_by_ssh.t
+++ b/plugins/t/check_by_ssh.t
@@ -34,102 +34,98 @@ for (@responce) {
34 push(@check, "echo $_"); 34 push(@check, "echo $_");
35} 35}
36 36
37#SKIP { 37my $result;
38# skip "SSH_HOST and SSH_IDENTITY must be defined", 36 unless($ssh_service && $ssh_key); 38
39 39## Single active checks
40 my $result; 40
41 41for (my $i=0; $i<4; $i++) {
42 ## Single active checks
43
44 for (my $i=0; $i<4; $i++) {
45 $result = NPTest->testCmd(
46 "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'"
47 );
48 cmp_ok($result->return_code, '==', $i, "Exit with return code $i");
49 is($result->output, $responce[$i], "Status text is correct for check $i");
50 }
51
52 $result = NPTest->testCmd(
53 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 0'"
54 );
55 cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)");
56 is($result->output, 'OK - check_by_ssh: Remote command \'exit 0\' returned status 0', "Status text if command returned none (OK)");
57
58 $result = NPTest->testCmd(
59 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 1'"
60 );
61 cmp_ok($result->return_code, '==', 1, "Exit with return code 1 (WARNING)");
62 is($result->output, 'WARNING - check_by_ssh: Remote command \'exit 1\' returned status 1', "Status text if command returned none (WARNING)");
63
64 $result = NPTest->testCmd(
65 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 2'"
66 );
67 cmp_ok($result->return_code, '==', 2, "Exit with return code 2 (CRITICAL)");
68 is($result->output, 'CRITICAL - check_by_ssh: Remote command \'exit 2\' returned status 2', "Status text if command returned none (CRITICAL)");
69
70 $result = NPTest->testCmd(
71 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 3'"
72 );
73 cmp_ok($result->return_code, '==', 3, "Exit with return code 3 (UNKNOWN)");
74 is($result->output, 'UNKNOWN - check_by_ssh: Remote command \'exit 3\' returned status 3', "Status text if command returned none (UNKNOWN)");
75
76 $result = NPTest->testCmd(
77 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 7'"
78 );
79 cmp_ok($result->return_code, '==', 7, "Exit with return code 7 (out of bounds)");
80 is($result->output, 'UNKNOWN - check_by_ssh: Remote command \'exit 7\' returned status 7', "Status text if command returned none (out of bounds)");
81
82 $result = NPTest->testCmd(
83 "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'"
84 );
85 cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)");
86 is($result->output, $responce[4], "Return proper status text even with unknown status codes");
87
88 # Multiple active checks
89 $result = NPTest->testCmd( 42 $result = NPTest->testCmd(
90 "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[1]; sh -c exit\\ 1' -C '$check[0]; sh -c exit\\ 0' -C '$check[3]; sh -c exit\\ 3' -C '$check[2]; sh -c exit\\ 2'" 43 "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'"
91 ); 44 );
92 cmp_ok($result->return_code, '==', 0, "Multiple checks always return OK"); 45 cmp_ok($result->return_code, '==', $i, "Exit with return code $i");
93 my @lines = split(/\n/, $result->output); 46 is($result->output, $responce[$i], "Status text is correct for check $i");
94 my %linemap = ( 47}
95 '0' => '1', 48
96 '2' => '0', 49$result = NPTest->testCmd(
97 '4' => '3', 50 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 0'"
98 '6' => '2',
99 ); 51 );
100 foreach my $line (0, 2, 4, 6) { 52cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)");
101 my $code = $linemap{$line}; 53is($result->output, 'OK - check_by_ssh: Remote command \'exit 0\' returned status 0', "Status text if command returned none (OK)");
102 my $statline = $line+1; 54
103 is($lines[$line], "$responce[$code]", "multiple checks status text is correct for line $line"); 55$result = NPTest->testCmd(
104 is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line"); 56 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 1'"
105 } 57 );
106 58cmp_ok($result->return_code, '==', 1, "Exit with return code 1 (WARNING)");
107 # Passive checks 59is($result->output, 'WARNING - check_by_ssh: Remote command \'exit 1\' returned status 1', "Status text if command returned none (WARNING)");
108 $result = NPTest->testCmd( 60
109 "./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.$$" 61$result = NPTest->testCmd(
110 ); 62 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 2'"
111 cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks"); 63 );
112 open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!"); 64cmp_ok($result->return_code, '==', 2, "Exit with return code 2 (CRITICAL)");
113 my $count=0; 65is($result->output, 'CRITICAL - check_by_ssh: Remote command \'exit 2\' returned status 2', "Status text if command returned none (CRITICAL)");
114 while (<PASV>) { 66
115 like($_, '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;$responce[2]$/', 'proper result for passive check'); 67$result = NPTest->testCmd(
116 $count++; 68 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 3'"
117 } 69 );
118 cmp_ok($count, '==', 1, 'One passive result for one check performed'); 70cmp_ok($result->return_code, '==', 3, "Exit with return code 3 (UNKNOWN)");
119 unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!"); 71is($result->output, 'UNKNOWN - check_by_ssh: Remote command \'exit 3\' returned status 3', "Status text if command returned none (UNKNOWN)");
120 72
121 $result = NPTest->testCmd( 73$result = NPTest->testCmd(
122 "./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.$$" 74 "./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 7'"
123 ); 75 );
124 cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks"); 76cmp_ok($result->return_code, '==', 7, "Exit with return code 7 (out of bounds)");
125 $count=0; 77is($result->output, 'UNKNOWN - check_by_ssh: Remote command \'exit 7\' returned status 7', "Status text if command returned none (out of bounds)");
126 open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!"); 78
127 while (<PASV>) { 79$result = NPTest->testCmd(
128 my $ret; 80 "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'"
129 ($count == 4 ? $ret = 7 : $ret = $count); 81 );
130 like($_, '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $count . ';' . $ret . ';' . $responce[$count] . '$/', "proper result for passive check $count"); 82cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)");
131 } 83is($result->output, $responce[4], "Return proper status text even with unknown status codes");
132 cmp_ok($count, '==', 5, 'Five passive result for five checks performed'); 84
133 unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!"); 85# Multiple active checks
134#} 86$result = NPTest->testCmd(
87 "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[1]; sh -c exit\\ 1' -C '$check[0]; sh -c exit\\ 0' -C '$check[3]; sh -c exit\\ 3' -C '$check[2]; sh -c exit\\ 2'"
88 );
89cmp_ok($result->return_code, '==', 0, "Multiple checks always return OK");
90my @lines = split(/\n/, $result->output);
91my %linemap = (
92 '0' => '1',
93 '2' => '0',
94 '4' => '3',
95 '6' => '2',
96);
97foreach my $line (0, 2, 4, 6) {
98 my $code = $linemap{$line};
99 my $statline = $line+1;
100 is($lines[$line], "$responce[$code]", "multiple checks status text is correct for line $line");
101 is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line");
102}
103
104# Passive checks
105$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.$$"
107 );
108cmp_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.$$': $!");
110my $count=0;
111while (<PASV>) {
112 like($_, '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;$responce[2]$/', 'proper result for passive check');
113 $count++;
114}
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.$$': $!");
117
118$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.$$"
120 );
121cmp_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.$$': $!");
124while (<PASV>) {
125 my $ret;
126 ($count == 4 ? $ret = 7 : $ret = $count);
127 like($_, '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $count . ';' . $ret . ';' . $responce[$count] . '$/', "proper result for passive check $count");
128}
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.$$': $!");
135 131