diff options
Diffstat (limited to 'plugins/t/check_by_ssh.t')
-rw-r--r-- | plugins/t/check_by_ssh.t | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t index 4797390d..b6479f1f 100644 --- a/plugins/t/check_by_ssh.t +++ b/plugins/t/check_by_ssh.t | |||
@@ -9,17 +9,9 @@ use Test::More; | |||
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | # Required parameters | 11 | # Required parameters |
12 | my $ssh_service = getTestParameter( "NP_SSH_HOST", | 12 | my $ssh_service = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost"); |
13 | "A host providing SSH service", | 13 | my $ssh_key = getTestParameter("NP_SSH_IDENTITY", "A key allowing access to NP_SSH_HOST", "~/.ssh/id_dsa"); |
14 | "localhost"); | 14 | my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE", "A config file with ssh settings", "~/.ssh/config"); |
15 | |||
16 | my $ssh_key = getTestParameter( "NP_SSH_IDENTITY", | ||
17 | "A key allowing access to NP_SSH_HOST", | ||
18 | "~/.ssh/id_dsa"); | ||
19 | |||
20 | my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE", | ||
21 | "A config file with ssh settings", | ||
22 | "~/.ssh/config"); | ||
23 | 15 | ||
24 | 16 | ||
25 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); | 17 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); |
@@ -27,19 +19,19 @@ plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_servic | |||
27 | plan tests => 42; | 19 | plan tests => 42; |
28 | 20 | ||
29 | # Some random check strings/response | 21 | # Some random check strings/response |
30 | my @responce = ('OK: Everything is fine', | 22 | my @response = ('OK: Everything is fine', |
31 | 'WARNING: Hey, pick me, pick me', | 23 | 'WARNING: Hey, pick me, pick me', |
32 | 'CRITICAL: Shit happens', | 24 | 'CRITICAL: Shit happens', |
33 | 'UNKNOWN: What can I do for ya', | 25 | 'UNKNOWN: What can I do for ya', |
34 | 'WOOPS: What did I smoke', | 26 | 'WOOPS: What did I smoke', |
35 | ); | 27 | ); |
36 | my @responce_re; | 28 | my @response_re; |
37 | my @check; | 29 | my @check; |
38 | for (@responce) { | 30 | for (@response) { |
39 | push(@check, "echo $_"); | 31 | push(@check, "echo $_"); |
40 | my $re_str = $_; | 32 | my $re_str = $_; |
41 | $re_str =~ s{(.)} { "\Q$1" }ge; | 33 | $re_str =~ s{(.)} { "\Q$1" }ge; |
42 | push(@responce_re, $re_str); | 34 | push(@response_re, $re_str); |
43 | } | 35 | } |
44 | 36 | ||
45 | my $result; | 37 | my $result; |
@@ -55,7 +47,7 @@ for (my $i=0; $i<4; $i++) { | |||
55 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'" | 47 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'" |
56 | ); | 48 | ); |
57 | cmp_ok($result->return_code, '==', $i, "Exit with return code $i"); | 49 | cmp_ok($result->return_code, '==', $i, "Exit with return code $i"); |
58 | is($result->output, $responce[$i], "Status text is correct for check $i"); | 50 | is($result->output, $response[$i], "Status text is correct for check $i"); |
59 | } | 51 | } |
60 | 52 | ||
61 | $result = NPTest->testCmd( | 53 | $result = NPTest->testCmd( |
@@ -92,7 +84,7 @@ $result = NPTest->testCmd( | |||
92 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'" | 84 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'" |
93 | ); | 85 | ); |
94 | cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)"); | 86 | cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)"); |
95 | is($result->output, $responce[4], "Return proper status text even with unknown status codes"); | 87 | is($result->output, $response[4], "Return proper status text even with unknown status codes"); |
96 | 88 | ||
97 | $result = NPTest->testCmd( | 89 | $result = NPTest->testCmd( |
98 | "./check_by_ssh -i $ssh_key -H $ssh_service -F $ssh_conf -C 'exit 0'" | 90 | "./check_by_ssh -i $ssh_key -H $ssh_service -F $ssh_conf -C 'exit 0'" |
@@ -116,7 +108,7 @@ my %linemap = ( | |||
116 | foreach my $line (0, 2, 4, 6) { | 108 | foreach my $line (0, 2, 4, 6) { |
117 | my $code = $linemap{$line}; | 109 | my $code = $linemap{$line}; |
118 | my $statline = $line+1; | 110 | my $statline = $line+1; |
119 | is($lines[$line], "$responce[$code]", "multiple checks status text is correct for line $line"); | 111 | is($lines[$line], "$response[$code]", "multiple checks status text is correct for line $line"); |
120 | is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line"); | 112 | is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line"); |
121 | } | 113 | } |
122 | 114 | ||
@@ -132,7 +124,7 @@ close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!"); | |||
132 | cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed'); | 124 | cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed'); |
133 | for (0) { | 125 | for (0) { |
134 | if ($pasv[$_]) { | 126 | if ($pasv[$_]) { |
135 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $responce_re[2] . '$/', 'proper result for passive check'); | 127 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $response_re[2] . '$/', 'proper result for passive check'); |
136 | } else { | 128 | } else { |
137 | fail('proper result for passive check'); | 129 | fail('proper result for passive check'); |
138 | } | 130 | } |
@@ -152,7 +144,7 @@ for (0, 1, 2, 3, 4) { | |||
152 | if ($pasv[$_]) { | 144 | if ($pasv[$_]) { |
153 | my $ret = $_; | 145 | my $ret = $_; |
154 | $ret = 9 if ($_ == 4); | 146 | $ret = 9 if ($_ == 4); |
155 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $responce_re[$_] . '$/', "proper result for passive check $_"); | 147 | like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $response_re[$_] . '$/', "proper result for passive check $_"); |
156 | } else { | 148 | } else { |
157 | fail("proper result for passive check $_"); | 149 | fail("proper result for passive check $_"); |
158 | } | 150 | } |