diff options
Diffstat (limited to 'plugins/t')
-rw-r--r-- | plugins/t/check_by_ssh.t | 42 |
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 | ||
21 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); | 21 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); |
22 | 22 | ||
23 | plan tests => 38; | 23 | plan tests => 40; |
24 | 24 | ||
25 | # Some random check strings/response | 25 | # Some random check strings/response |
26 | my @responce = ('OK: Everything is fine!', | 26 | my @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 | ); |
32 | my @responce_re; | ||
32 | my @check; | 33 | my @check; |
33 | for (@responce) { | 34 | for (@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 | ||
37 | my $result; | 41 | my $result; |
@@ -88,6 +92,7 @@ $result = NPTest->testCmd( | |||
88 | ); | 92 | ); |
89 | cmp_ok($result->return_code, '==', 0, "Multiple checks always return OK"); | 93 | cmp_ok($result->return_code, '==', 0, "Multiple checks always return OK"); |
90 | my @lines = split(/\n/, $result->output); | 94 | my @lines = split(/\n/, $result->output); |
95 | cmp_ok(scalar(@lines), '==', 8, "Correct number of output lined for multiple checks"); | ||
91 | my %linemap = ( | 96 | my %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 |
110 | unlink("/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 | ); |
108 | cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks"); | 114 | cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks"); |
109 | open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!"); | 115 | open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!"); |
110 | my $count=0; | 116 | my @pasv = <PASV>; |
111 | while (<PASV>) { | 117 | close(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'); | 118 | cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed'); |
113 | $count++; | 119 | for (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 | } |
115 | cmp_ok($count, '==', 1, 'One passive result for one check performed'); | ||
116 | unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!"); | 126 | unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!"); |
127 | undef @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 | ); |
121 | cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks"); | 132 | cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks"); |
122 | $count=0; | ||
123 | open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!"); | 133 | open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!"); |
124 | while (<PASV>) { | 134 | @pasv = <PASV>; |
125 | my $ret; | 135 | close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!"); |
126 | ($count == 4 ? $ret = 7 : $ret = $count); | 136 | cmp_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"); | 137 | for (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 | } |
129 | cmp_ok($count, '==', 5, 'Five passive result for five checks performed'); | ||
130 | unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!"); | 146 | unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!"); |
131 | 147 | ||