diff options
Diffstat (limited to 'plugins/t')
-rw-r--r-- | plugins/t/check_disk.t | 220 | ||||
-rw-r--r-- | plugins/t/check_ftp.t | 2 | ||||
-rw-r--r-- | plugins/t/check_http.t | 2 | ||||
-rw-r--r-- | plugins/t/check_jabber.t | 6 | ||||
-rw-r--r-- | plugins/t/check_ldap.t | 2 | ||||
-rw-r--r-- | plugins/t/check_mysql.t | 32 | ||||
-rw-r--r-- | plugins/t/check_ntp.t | 2 | ||||
-rw-r--r-- | plugins/t/check_smtp.t | 3 | ||||
-rw-r--r-- | plugins/t/check_ssh.t | 114 | ||||
-rw-r--r-- | plugins/t/check_swap.t | 58 | ||||
-rw-r--r-- | plugins/t/check_tcp.t | 12 | ||||
-rw-r--r-- | plugins/t/check_udp.t | 4 |
12 files changed, 280 insertions, 177 deletions
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index 9eb77ce4..0f62fb2b 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
@@ -10,6 +10,7 @@ use strict; | |||
10 | use Test::More; | 10 | use Test::More; |
11 | use NPTest; | 11 | use NPTest; |
12 | use POSIX qw(ceil floor); | 12 | use POSIX qw(ceil floor); |
13 | use Data::Dumper; | ||
13 | 14 | ||
14 | my $successOutput = '/^DISK OK/'; | 15 | my $successOutput = '/^DISK OK/'; |
15 | my $failureOutput = '/^DISK CRITICAL/'; | 16 | my $failureOutput = '/^DISK CRITICAL/'; |
@@ -20,173 +21,216 @@ my $result; | |||
20 | my $mountpoint_valid = getTestParameter( "NP_MOUNTPOINT_VALID", "Path to valid mountpoint", "/"); | 21 | my $mountpoint_valid = getTestParameter( "NP_MOUNTPOINT_VALID", "Path to valid mountpoint", "/"); |
21 | my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to another valid mountpoint. Must be different from 1st one", "/var"); | 22 | my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to another valid mountpoint. Must be different from 1st one", "/var"); |
22 | 23 | ||
24 | my $output_format = "--output-format mp-test-json"; | ||
25 | |||
23 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { | 26 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { |
24 | plan skip_all => "Need 2 mountpoints to test"; | 27 | plan skip_all => "Need 2 mountpoints to test"; |
25 | } else { | 28 | } else { |
26 | plan tests => 94; | 29 | plan tests => 97; |
27 | } | 30 | } |
28 | 31 | ||
29 | $result = NPTest->testCmd( | 32 | $result = NPTest->testCmd( |
30 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" | 33 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -P -p $mountpoint2_valid $output_format" |
31 | ); | 34 | ); |
32 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); | 35 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); |
33 | my $c = 0; | ||
34 | $_ = $result->output; | ||
35 | $c++ while /\(/g; # counts number of "(" - should be two | ||
36 | cmp_ok( $c, '==', 2, "Got two mountpoints in output"); | ||
37 | 36 | ||
37 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "Main result is OK"); | ||
38 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'state'}, "/OK/", "First sub result is OK"); | ||
39 | like($result->{'mp_test_result'}->{'checks'}->[1]->{'state'}, "/OK/", "Second sub result is OK"); | ||
40 | |||
41 | my $absolut_space_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
42 | # print("absolute space on mp1: ". $absolut_space_mp1 . "\n"); | ||
43 | |||
44 | my $free_percent_on_mp1 = ($result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'} / ($absolut_space_mp1/100)); | ||
45 | print("free percent on mp1: ". $free_percent_on_mp1 . "\n"); | ||
46 | |||
47 | my $absolut_space_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
48 | # print("absolute space on mp2: ". $absolut_space_mp2 . "\n"); | ||
49 | |||
50 | my $free_percent_on_mp2 = ($result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'}/ ($absolut_space_mp2/100)); | ||
51 | print("free percent on mp2: ". $free_percent_on_mp2 . "\n"); | ||
38 | 52 | ||
39 | # Get perf data | 53 | my @perfdata; |
40 | # Should use Monitoring::Plugin | 54 | @perfdata[0] = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]; |
41 | my @perf_data = sort(split(/ /, $result->perf_output)); | 55 | @perfdata[1] = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]; |
42 | 56 | ||
57 | # Decrease precision of numbers since the the fs might be modified between the two runs | ||
58 | $perfdata[0]->{'value'}->{'value'} = int($perfdata[0]->{'value'}->{'value'} / 1000000); | ||
59 | $perfdata[1]->{'value'}->{'value'} = int($perfdata[1]->{'value'}->{'value'} / 1000000); | ||
43 | 60 | ||
44 | # Calculate avg_free free on mountpoint1 and mountpoint2 | 61 | # Calculate avg_free free on mountpoint1 and mountpoint2 |
45 | # because if you check in the middle, you should get different errors | 62 | # because if you check in the middle, you should get different errors |
46 | $_ = $result->output; | 63 | my $avg_free_percent = ceil(($free_percent_on_mp1+$free_percent_on_mp2)/2); |
47 | my ($free_on_mp1, $free_on_mp2) = (m/\((\d+\.\d+)%.*\((\d+\.\d+)%/); | 64 | # print("avg_free: " . $avg_free_percent . "\n"); |
48 | die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2); | ||
49 | my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2); | ||
50 | my ($more_free, $less_free); | 65 | my ($more_free, $less_free); |
51 | if ($free_on_mp1 > $free_on_mp2) { | 66 | if ($free_percent_on_mp1 > $free_percent_on_mp2) { |
52 | $more_free = $mountpoint_valid; | 67 | $more_free = $mountpoint_valid; |
53 | $less_free = $mountpoint2_valid; | 68 | $less_free = $mountpoint2_valid; |
54 | } elsif ($free_on_mp1 < $free_on_mp2) { | 69 | } elsif ($free_percent_on_mp1 < $free_percent_on_mp2) { |
55 | $more_free = $mountpoint2_valid; | 70 | $more_free = $mountpoint2_valid; |
56 | $less_free = $mountpoint_valid; | 71 | $less_free = $mountpoint_valid; |
57 | } else { | 72 | } else { |
58 | die "Two mountpoints are the same - cannot do rest of test"; | 73 | die "Two mountpoints are the same - cannot do rest of test"; |
59 | } | 74 | } |
60 | if($free_on_mp1 == $avg_free || $free_on_mp2 == $avg_free) { | 75 | |
76 | print("less free: " . $less_free . "\n"); | ||
77 | print("more free: " . $more_free . "\n"); | ||
78 | |||
79 | if($free_percent_on_mp1 == $avg_free_percent || $free_percent_on_mp2 == $avg_free_percent) { | ||
61 | die "One mountpoints has average space free - cannot do rest of test"; | 80 | die "One mountpoints has average space free - cannot do rest of test"; |
62 | } | 81 | } |
63 | 82 | ||
83 | my $free_inodes_on_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}[2]->{'perfdata'}->[0]->{'value'}->{'value'}; | ||
84 | my $total_inodes_on_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}[2]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
85 | my $free_inode_percentage_on_mp1 = $free_inodes_on_mp1 / ($total_inodes_on_mp1 / 100); | ||
64 | 86 | ||
65 | # Do same for inodes | 87 | my $free_inodes_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[2]->{'perfdata'}->[0]->{'value'}->{'value'}; |
66 | $_ = $result->output; | 88 | my $total_inodes_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[2]->{'perfdata'}->[0]->{'max'}->{'value'}; |
67 | my ($free_inode_on_mp1, $free_inode_on_mp2) = (m/inode=(\d+)%.*inode=(\d+)%/); | 89 | my $free_inode_percentage_on_mp2 = $free_inodes_on_mp2 / ($total_inodes_on_mp2 / 100); |
68 | die "Cannot parse free inodes: $_" unless ($free_inode_on_mp1 && $free_inode_on_mp2); | 90 | |
69 | my $avg_inode_free = ceil(($free_inode_on_mp1 + $free_inode_on_mp2)/2); | 91 | my $avg_inode_free_percentage = ceil(($free_inode_percentage_on_mp1 + $free_inode_percentage_on_mp2)/2); |
70 | my ($more_inode_free, $less_inode_free); | 92 | my ($more_inode_free, $less_inode_free); |
71 | if ($free_inode_on_mp1 > $free_inode_on_mp2) { | 93 | if ($free_inode_percentage_on_mp1 > $free_inode_percentage_on_mp2) { |
72 | $more_inode_free = $mountpoint_valid; | 94 | $more_inode_free = $mountpoint_valid; |
73 | $less_inode_free = $mountpoint2_valid; | 95 | $less_inode_free = $mountpoint2_valid; |
74 | } elsif ($free_inode_on_mp1 < $free_inode_on_mp2) { | 96 | } elsif ($free_inode_percentage_on_mp1 < $free_inode_percentage_on_mp2) { |
75 | $more_inode_free = $mountpoint2_valid; | 97 | $more_inode_free = $mountpoint2_valid; |
76 | $less_inode_free = $mountpoint_valid; | 98 | $less_inode_free = $mountpoint_valid; |
77 | } else { | 99 | } else { |
78 | die "Two mountpoints with same inodes free - cannot do rest of test"; | 100 | die "Two mountpoints with same inodes free - cannot do rest of test"; |
79 | } | 101 | } |
80 | if($free_inode_on_mp1 == $avg_inode_free || $free_inode_on_mp2 == $avg_inode_free) { | 102 | if($free_inode_percentage_on_mp1 == $avg_inode_free_percentage || $free_inode_percentage_on_mp2 == $avg_inode_free_percentage) { |
81 | die "One mountpoints has average inodes free - cannot do rest of test"; | 103 | die "One mountpoints has average inodes free - cannot do rest of test"; |
82 | } | 104 | } |
83 | 105 | ||
84 | # Verify performance data | 106 | # Verify performance data |
85 | # First check absolute thresholds... | 107 | # First check absolute thresholds... |
86 | $result = NPTest->testCmd( | 108 | $result = NPTest->testCmd( |
87 | "./check_disk -w 20 -c 10 -p $mountpoint_valid" | 109 | "./check_disk -w 20 -c 10 -p $mountpoint_valid $output_format" |
88 | ); | 110 | ); |
89 | $_ = $result->perf_output; | 111 | |
90 | my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/); | 112 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
91 | # default unit is MiB, but perfdata is always bytes | 113 | |
92 | is ($warn_absth_data, $total_absth_data - (20 * (2 ** 20)), "Wrong warning in perf data using absolute thresholds"); | 114 | my $warn_absth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'warn'}->{'end'}->{'value'}; |
93 | is ($crit_absth_data, $total_absth_data - (10 * (2 ** 20)), "Wrong critical in perf data using absolute thresholds"); | 115 | my $crit_absth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'crit'}->{'end'}->{'value'}; |
116 | my $total_absth_data= $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
117 | |||
118 | # print("warn: " .$warn_absth_data . "\n"); | ||
119 | # print("crit: " .$crit_absth_data . "\n"); | ||
120 | # print("total: " .$total_absth_data . "\n"); | ||
121 | |||
122 | is ($warn_absth_data <=> (20 * (2 ** 20)), 0, "Wrong warning in perf data using absolute thresholds"); | ||
123 | is ($crit_absth_data <=> (10 * (2 ** 20)), 0, "Wrong critical in perf data using absolute thresholds"); | ||
94 | 124 | ||
95 | # Then check percent thresholds. | 125 | # Then check percent thresholds. |
96 | $result = NPTest->testCmd( | 126 | $result = NPTest->testCmd( |
97 | "./check_disk -w 20% -c 10% -p $mountpoint_valid" | 127 | "./check_disk -w 20% -c 10% -p $mountpoint_valid $output_format" |
98 | ); | 128 | ); |
99 | $_ = $result->perf_output; | 129 | |
100 | my ($warn_percth_data, $crit_percth_data, $total_percth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/); | 130 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
101 | is ($warn_percth_data, int((1-20/100)*$total_percth_data), "Wrong warning in perf data using percent thresholds"); | 131 | |
102 | is ($crit_percth_data, int((1-10/100)*$total_percth_data), "Wrong critical in perf data using percent thresholds"); | 132 | my $warn_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'warn'}->{'end'}->{'value'}; |
133 | my $crit_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'crit'}->{'end'}->{'value'}; | ||
134 | my $total_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
135 | |||
136 | print("warn_percth_data: " . $warn_percth_data . "\n"); | ||
137 | print("crit_percth_data: " . $crit_percth_data . "\n"); | ||
138 | |||
139 | is (int($warn_percth_data), int((20/100)*$total_percth_data), "Wrong warning in perf data using percent thresholds. Got " . $warn_percth_data . " with total " . $total_percth_data); | ||
140 | is (int($crit_percth_data), int((10/100)*$total_percth_data), "Wrong critical in perf data using percent thresholds. Got " . $crit_percth_data . " with total " . $total_percth_data); | ||
103 | 141 | ||
104 | 142 | ||
105 | # Check when order of mount points are reversed, that perf data remains same | 143 | # Check when order of mount points are reversed, that perf data remains same |
106 | $result = NPTest->testCmd( | 144 | $result = NPTest->testCmd( |
107 | "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid" | 145 | "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid $output_format" |
108 | ); | 146 | ); |
109 | @_ = sort(split(/ /, $result->perf_output)); | 147 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
110 | is_deeply( \@perf_data, \@_, "perf data for both filesystems same when reversed"); | ||
111 | 148 | ||
149 | # write comparison set for perfdata here, but in reversed order, maybe there is a smarter way | ||
150 | my @perfdata2; | ||
151 | @perfdata2[0] = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]; | ||
152 | @perfdata2[1] = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]; | ||
153 | # Decrease precision of numbers since the the fs might be modified between the two runs | ||
154 | $perfdata2[0]->{'value'}->{'value'} = int($perfdata2[0]->{'value'}->{'value'} / 1000000); | ||
155 | $perfdata2[1]->{'value'}->{'value'} = int($perfdata2[1]->{'value'}->{'value'} / 1000000); | ||
156 | is_deeply(\@perfdata, \@perfdata2, "perf data for both filesystems same when reversed"); | ||
112 | 157 | ||
113 | # Basic filesystem checks for sizes | 158 | # Basic filesystem checks for sizes |
114 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free" ); | 159 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free $output_format"); |
115 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free"); | 160 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
116 | like ( $result->output, $successOutput, "OK output" ); | 161 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "At least 1 MB available on $more_free"); |
117 | like ( $result->only_output, qr/free space/, "Have free space text"); | ||
118 | like ( $result->only_output, qr/$more_free/, "Have disk name in text"); | ||
119 | 162 | ||
120 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); | 163 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free $output_format" ); |
121 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); | 164 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
165 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "At least 1 MB available on $more_free and $less_free"); | ||
122 | 166 | ||
123 | $_ = $result->output; | 167 | my $free_mb_on_mp1 =$result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'} / (1024 * 1024); |
124 | 168 | my $free_mb_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'}/ (1024 * 1024); | |
125 | my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); | ||
126 | die "Cannot parse output: $_" unless ($free_mb_on_mp1 && $free_mb_on_mp2); | 169 | die "Cannot parse output: $_" unless ($free_mb_on_mp1 && $free_mb_on_mp2); |
127 | 170 | ||
128 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; | 171 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; |
129 | 172 | ||
130 | 173 | ||
174 | $result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free $output_format" ); | ||
175 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); | ||
131 | 176 | ||
132 | $result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" ); | 177 | $result = NPTest->testCmd( "./check_disk 101 101 $more_free" ); |
133 | is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs"); | 178 | like($result->output, "/OK/", "OK in Output"); |
134 | 179 | cmp_ok( $result->return_code, '==', 0, "Old syntax okay, output was: ". $result->output . "\n" ); | |
135 | $result = NPTest->testCmd( "./check_disk 100 100 $more_free" ); | ||
136 | cmp_ok( $result->return_code, '==', 0, "Old syntax okay" ); | ||
137 | 180 | ||
138 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); | 181 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); |
139 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); | 182 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); |
140 | 183 | ||
141 | $result = NPTest->testCmd( | 184 | $result = NPTest->testCmd( |
142 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" | 185 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free $output_format" |
143 | ); | 186 | ); |
144 | cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); | 187 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
145 | like( $result->output, $failureOutput, "Right output" ); | 188 | like($result->{'mp_test_result'}->{'state'}, "/CRITICAL/", "Get critical on less_free mountpoint $less_free"); |
146 | 189 | ||
147 | 190 | ||
148 | $result = NPTest->testCmd( | 191 | $result = NPTest->testCmd( |
149 | "./check_disk -w $avg_free% -c 0% -p $less_free" | 192 | "./check_disk -w $avg_free_percent% -c 0% -p $less_free $output_format" |
150 | ); | 193 | ); |
151 | cmp_ok( $result->return_code, '==', 1, "Get warning on less_free mountpoint, when checking avg_free"); | 194 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
195 | like($result->{'mp_test_result'}->{'state'}, "/WARNING/", "Get warning on less_free mountpoint, when checking avg_free"); | ||
152 | 196 | ||
153 | $result = NPTest->testCmd( | 197 | $result = NPTest->testCmd( |
154 | "./check_disk -w $avg_free% -c $avg_free% -p $more_free" | 198 | "./check_disk -w $avg_free_percent% -c $avg_free_percent% -p $more_free" |
155 | ); | 199 | ); |
156 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); | 200 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); |
157 | 201 | ||
158 | $result = NPTest->testCmd( | 202 | $result = NPTest->testCmd( |
159 | "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 203 | "./check_disk -w $avg_free_percent% -c 0% -p $less_free -w $avg_free_percent% -c $avg_free_percent% -p $more_free" |
160 | ); | 204 | ); |
161 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); | 205 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); |
162 | my $all_disks = $result->output; | 206 | my $all_disks = $result->output; |
163 | 207 | ||
164 | $result = NPTest->testCmd( | 208 | $result = NPTest->testCmd( |
165 | "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 209 | "./check_disk -e -w $avg_free_percent% -c 0% -p $less_free -w $avg_free_percent% -c $avg_free_percent% -p $more_free" |
166 | ); | 210 | ); |
167 | isnt( $result->output, $all_disks, "-e gives different output"); | 211 | isnt( $result->output, $all_disks, "-e gives different output"); |
168 | 212 | ||
169 | # Need spaces around filesystem name in case less_free and more_free are nested | 213 | # Need spaces around filesystem name in case less_free and more_free are nested |
170 | like( $result->output, qr/ $less_free /, "Found problem $less_free"); | 214 | like( $result->output, qr/ $less_free /, "Found problem $less_free"); |
171 | unlike( $result->only_output, qr/ $more_free /, "Has ignored $more_free as not a problem"); | 215 | unlike( $result->only_output, qr/ $more_free /, "Has ignored $more_free as not a problem"); |
172 | like( $result->perf_output, qr/ $more_free=/, "But $more_free is still in perf data"); | 216 | like( $result->perf_output, qr/'$more_free'=/, "But $more_free is still in perf data"); |
173 | 217 | ||
174 | $result = NPTest->testCmd( | 218 | $result = NPTest->testCmd( |
175 | "./check_disk -w $avg_free% -c 0% -p $more_free" | 219 | "./check_disk -w $avg_free_percent% -c 0% -p $more_free" |
176 | ); | 220 | ); |
177 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, checking avg_free"); | 221 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, checking avg_free"); |
178 | 222 | ||
179 | $result = NPTest->testCmd( | 223 | $result = NPTest->testCmd( |
180 | "./check_disk -w $avg_free% -c $avg_free% -p $less_free" | 224 | "./check_disk -w $avg_free_percent% -c $avg_free_percent% -p $less_free" |
181 | ); | 225 | ); |
182 | cmp_ok( $result->return_code, '==', 2, "Get critical on less_free, checking avg_free"); | 226 | cmp_ok( $result->return_code, '==', 2, "Get critical on less_free, checking avg_free"); |
183 | $result = NPTest->testCmd( | 227 | $result = NPTest->testCmd( |
184 | "./check_disk -w $avg_free% -c 0% -p $more_free -w $avg_free% -c $avg_free% -p $less_free" | 228 | "./check_disk -w $avg_free_percent% -c 0% -p $more_free -w $avg_free_percent% -c $avg_free_percent% -p $less_free" |
185 | ); | 229 | ); |
186 | cmp_ok( $result->return_code, '==', 2, "Combining above two tests, get critical"); | 230 | cmp_ok( $result->return_code, '==', 2, "Combining above two tests, get critical"); |
187 | 231 | ||
188 | $result = NPTest->testCmd( | 232 | $result = NPTest->testCmd( |
189 | "./check_disk -w $avg_free% -c $avg_free% -p $less_free -w $avg_free% -c 0% -p $more_free" | 233 | "./check_disk -w $avg_free_percent% -c $avg_free_percent% -p $less_free -w $avg_free_percent% -c 0% -p $more_free" |
190 | ); | 234 | ); |
191 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); | 235 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); |
192 | 236 | ||
@@ -203,32 +247,32 @@ is( $result->return_code, 2, "Critical requesting 100% free inodes for both moun | |||
203 | $result = NPTest->testCmd( "./check_disk --iwarning 1% --icritical 1% -p $more_inode_free -K 100% -W 100% -p $less_inode_free" ); | 247 | $result = NPTest->testCmd( "./check_disk --iwarning 1% --icritical 1% -p $more_inode_free -K 100% -W 100% -p $less_inode_free" ); |
204 | is( $result->return_code, 2, "Get critical on less_inode_free mountpoint $less_inode_free"); | 248 | is( $result->return_code, 2, "Get critical on less_inode_free mountpoint $less_inode_free"); |
205 | 249 | ||
206 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $less_inode_free" ); | 250 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $less_inode_free" ); |
207 | is( $result->return_code, 1, "Get warning on less_inode_free, when checking average"); | 251 | is( $result->return_code, 1, "Get warning on less_inode_free, when checking average"); |
208 | 252 | ||
209 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free "); | 253 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free "); |
210 | is( $result->return_code, 0, "Get ok on more_inode_free when checking average"); | 254 | is( $result->return_code, 0, "Get ok on more_inode_free when checking average"); |
211 | 255 | ||
212 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $less_inode_free -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free" ); | 256 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $less_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free" ); |
213 | is ($result->return_code, 1, "Combine above two tests, get warning"); | 257 | is ($result->return_code, 1, "Combine above two tests, get warning"); |
214 | $all_disks = $result->output; | 258 | $all_disks = $result->output; |
215 | 259 | ||
216 | $result = NPTest->testCmd( "./check_disk -e -W $avg_inode_free% -K 0% -p $less_inode_free -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free" ); | 260 | $result = NPTest->testCmd( "./check_disk -e -W $avg_inode_free_percentage% -K 0% -p $less_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free" ); |
217 | isnt( $result->output, $all_disks, "-e gives different output"); | 261 | isnt( $result->output, $all_disks, "-e gives different output"); |
218 | like( $result->output, qr/$less_inode_free/, "Found problem $less_inode_free"); | 262 | like( $result->output, qr/$less_inode_free/, "Found problem $less_inode_free"); |
219 | unlike( $result->only_output, qr/$more_inode_free\s/, "Has ignored $more_inode_free as not a problem"); | 263 | unlike( $result->only_output, qr/$more_inode_free\s/, "Has ignored $more_inode_free as not a problem"); |
220 | like( $result->perf_output, qr/$more_inode_free/, "But $more_inode_free is still in perf data"); | 264 | like( $result->perf_output, qr/$more_inode_free/, "But $more_inode_free is still in perf data"); |
221 | 265 | ||
222 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $more_inode_free" ); | 266 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $more_inode_free" ); |
223 | is( $result->return_code, 0, "Get ok on more_inode_free mountpoint, checking average"); | 267 | is( $result->return_code, 0, "Get ok on more_inode_free mountpoint, checking average"); |
224 | 268 | ||
225 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free" ); | 269 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free" ); |
226 | is( $result->return_code, 2, "Get critical on less_inode_free, checking average"); | 270 | is( $result->return_code, 2, "Get critical on less_inode_free, checking average"); |
227 | 271 | ||
228 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $more_inode_free -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free" ); | 272 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $more_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free" ); |
229 | is( $result->return_code, 2, "Combining above two tests, get critical"); | 273 | is( $result->return_code, 2, "Combining above two tests, get critical"); |
230 | 274 | ||
231 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free -W $avg_inode_free% -K 0% -p $more_inode_free" ); | 275 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free -W $avg_inode_free_percentage% -K 0% -p $more_inode_free" ); |
232 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); | 276 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); |
233 | 277 | ||
234 | 278 | ||
@@ -249,9 +293,9 @@ $result = NPTest->testCmd( | |||
249 | ); | 293 | ); |
250 | cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); | 294 | cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); |
251 | 295 | ||
252 | $result = NPTest->testCmd( "./check_disk -w 100% -c 100% ".${mountpoint_valid} ); # 100% empty | 296 | $result = NPTest->testCmd( "./check_disk -w 100% -c 100% $output_format ".${mountpoint_valid} ); # 100% empty |
253 | cmp_ok( $result->return_code, "==", 2, "100% empty" ); | 297 | cmp_ok( $result->return_code, "==", 0, "100% empty" ); |
254 | like( $result->output, $failureOutput, "Right output" ); | 298 | like($result->{'mp_test_result'}->{'state'}, "/CRITICAL/", "100% empty"); |
255 | 299 | ||
256 | $result = NPTest->testCmd( "./check_disk -w 100000000 -c 100000000 $mountpoint_valid" ); | 300 | $result = NPTest->testCmd( "./check_disk -w 100000000 -c 100000000 $mountpoint_valid" ); |
257 | cmp_ok( $result->return_code, '==', 2, "Check for 100TB free" ); | 301 | cmp_ok( $result->return_code, '==', 2, "Check for 100TB free" ); |
@@ -263,7 +307,8 @@ cmp_ok( $result->return_code, "==", 2, "100 TB empty" ); | |||
263 | # Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds | 307 | # Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds |
264 | $result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} ); | 308 | $result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} ); |
265 | cmp_ok( $result->return_code, "==", 2, "Old syntax: 0% used"); | 309 | cmp_ok( $result->return_code, "==", 2, "Old syntax: 0% used"); |
266 | like ( $result->only_output, qr(^[^;]*;[^;]*$), "Select only one path with positional arguments"); | 310 | # like ( $result->only_output, qr(^[^;]*;[^;]*$), "Select only one path with positional arguments"); |
311 | # TODO not sure what the above should test, taking it out | ||
267 | 312 | ||
268 | $result = NPTest->testCmd( "./check_disk 100 100 $mountpoint_valid" ); | 313 | $result = NPTest->testCmd( "./check_disk 100 100 $mountpoint_valid" ); |
269 | cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" ); | 314 | cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" ); |
@@ -311,8 +356,9 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /" ); | |||
311 | unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice"); | 356 | unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice"); |
312 | 357 | ||
313 | # are partitions added if -C is given without path selection -p ? | 358 | # are partitions added if -C is given without path selection -p ? |
314 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoint_valid" ); | 359 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoint_valid $output_format" ); |
315 | like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given"); | 360 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
361 | cmp_ok(scalar $result->{'mp_test_result'}->{'checks'}, '>', 1, "-C invokes matchall logic again"); | ||
316 | 362 | ||
317 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit | 363 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit |
318 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); | 364 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); |
@@ -359,39 +405,37 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo | |||
359 | # ignore-missing: exit okay, when fs is not accessible | 405 | # ignore-missing: exit okay, when fs is not accessible |
360 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); | 406 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); |
361 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); | 407 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); |
362 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /bob;.*$/', 'Output OK'); | 408 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
363 | 409 | ||
364 | # ignore-missing: exit okay, when regex does not match | 410 | # ignore-missing: exit okay, when regex does not match |
365 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); | 411 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); |
366 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 412 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
367 | like( $result->output, '/^DISK OK - No disks were found for provided parameters.*$/', 'Output OK'); | 413 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
368 | 414 | ||
369 | # ignore-missing: exit okay, when fs with exact match (-E) is not found | 415 | # ignore-missing: exit okay, when fs with exact match (-E) is not found |
370 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); | 416 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); |
371 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); | 417 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); |
372 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /etc;.*$/', 'Output OK'); | 418 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
373 | 419 | ||
374 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) | 420 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) |
375 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); | 421 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); |
376 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 422 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
377 | like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK'); | ||
378 | 423 | ||
379 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) | 424 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) |
380 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); | 425 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); |
381 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 426 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
382 | like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); | 427 | # like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); |
383 | 428 | ||
384 | # ignore-missing: exit okay, when checking one non-existing fs (path) and one ignored | 429 | # ignore-missing: exit okay, when checking one non-existing fs (path) and one ignored |
385 | $result = NPTest->testCmd( "./check_disk -n -w 0% -c 0% -r /dummy -i /dummy2"); | 430 | $result = NPTest->testCmd( "./check_disk -n -w 0% -c 0% -r /dummy -i /dummy2"); |
386 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 431 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
387 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | 432 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
388 | 433 | ||
389 | # ignore-missing: exit okay, when regex match does not find anything | 434 | # ignore-missing: exit okay, when regex match does not find anything |
390 | $result = NPTest->testCmd( "./check_disk -n -e -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | 435 | $result = NPTest->testCmd( "./check_disk -n -e -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); |
391 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 436 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
392 | like( $result->output, '/^DISK OK\|$/', 'Output OK'); | ||
393 | 437 | ||
394 | # ignore-missing: exit okay, when regex match does not find anything | 438 | # ignore-missing: exit okay, when regex match does not find anything |
395 | $result = NPTest->testCmd( "./check_disk -n -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | 439 | $result = NPTest->testCmd( "./check_disk -n -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); |
396 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 440 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
397 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | 441 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
diff --git a/plugins/t/check_ftp.t b/plugins/t/check_ftp.t index 93a7d7c3..a2f79dca 100644 --- a/plugins/t/check_ftp.t +++ b/plugins/t/check_ftp.t | |||
@@ -15,7 +15,7 @@ my $host_tcp_ftp = getTestParameter("NP_HOST_TCP_FTP", "A host providing t | |||
15 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | 15 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
16 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | 16 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
17 | 17 | ||
18 | my $successOutput = '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/'; | 18 | my $successOutput = '/Connection time\s+[0-9]?\.?[0-9]+/'; |
19 | 19 | ||
20 | my $t; | 20 | my $t; |
21 | 21 | ||
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 6ab4a5b6..bb1fd27d 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -45,7 +45,7 @@ $res = NPTest->testCmd( | |||
45 | "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" | 45 | "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" |
46 | ); | 46 | ); |
47 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); | 47 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); |
48 | cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 3 seconds", "Output OK"); | 48 | like( $res->output, "/Socket timeout after/", "Output OK"); |
49 | 49 | ||
50 | $res = NPTest->testCmd( | 50 | $res = NPTest->testCmd( |
51 | "./$plugin $hostname_invalid -wt 1 -ct 2" | 51 | "./$plugin $hostname_invalid -wt 1 -ct 2" |
diff --git a/plugins/t/check_jabber.t b/plugins/t/check_jabber.t index fcdae179..dc46f4c3 100644 --- a/plugins/t/check_jabber.t +++ b/plugins/t/check_jabber.t | |||
@@ -15,11 +15,11 @@ my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname | |||
15 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | 15 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
16 | 16 | ||
17 | 17 | ||
18 | my $jabberOK = '/JABBER OK\s-\s\d+\.\d+\ssecond response time on '.$host_tcp_jabber.' port 5222/'; | 18 | my $jabberOK = '/Connection to '.$host_tcp_jabber.' on port 5222/'; |
19 | 19 | ||
20 | my $jabberUnresponsive = '/CRITICAL\s-\sSocket timeout after\s\d+\sseconds/'; | 20 | my $jabberUnresponsive = '/Socket timeout after\s\d+\sseconds/'; |
21 | 21 | ||
22 | my $jabberInvalid = '/JABBER CRITICAL - Invalid hostname, address or socket:\s.+/'; | 22 | my $jabberInvalid = '/Invalid hostname, address or socket:\s.+/'; |
23 | 23 | ||
24 | my $r; | 24 | my $r; |
25 | 25 | ||
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t index b8a4a766..fcba0393 100644 --- a/plugins/t/check_ldap.t +++ b/plugins/t/check_ldap.t | |||
@@ -24,7 +24,7 @@ SKIP: { | |||
24 | 24 | ||
25 | $result = NPTest->testCmd("$command -H $host_nonresponsive -b ou=blah -t 2 -w 1 -c 1"); | 25 | $result = NPTest->testCmd("$command -H $host_nonresponsive -b ou=blah -t 2 -w 1 -c 1"); |
26 | is( $result->return_code, 2, "$command -H $host_nonresponsive -b ou=blah -t 5 -w 2 -c 3" ); | 26 | is( $result->return_code, 2, "$command -H $host_nonresponsive -b ou=blah -t 5 -w 2 -c 3" ); |
27 | is( $result->output, 'CRITICAL - Socket timeout after 2 seconds', "output ok" ); | 27 | like($result->output, '/Socket timeout after \d+ seconds/', "output ok" ); |
28 | }; | 28 | }; |
29 | 29 | ||
30 | SKIP: { | 30 | SKIP: { |
diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t index baf3acc6..a383bc99 100644 --- a/plugins/t/check_mysql.t +++ b/plugins/t/check_mysql.t | |||
@@ -21,11 +21,11 @@ plan skip_all => "check_mysql not compiled" unless (-x "check_mysql"); | |||
21 | plan tests => 15; | 21 | plan tests => 15; |
22 | 22 | ||
23 | my $bad_login_output = '/Access denied for user /'; | 23 | my $bad_login_output = '/Access denied for user /'; |
24 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no slaves setup"); | 24 | my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no replica setup"); |
25 | my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket with no slaves setup"); | 25 | my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket with no replica setup"); |
26 | my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privileges)", "-u test -ptest"); | 26 | my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privileges)", "-u test -ptest"); |
27 | my $with_slave = getTestParameter("NP_MYSQL_WITH_SLAVE", "MySQL server with slaves setup"); | 27 | my $with_replica = getTestParameter("NP_MYSQL_WITH_REPLICA", "MySQL server with replica setup"); |
28 | my $with_slave_login = getTestParameter("NP_MYSQL_WITH_SLAVE_LOGIN", "Login details for server with slave (requires REPLICATION CLIENT privileges)", $mysql_login_details || "-u test -ptest"); | 28 | my $with_replica_login = getTestParameter("NP_MYSQL_WITH_REPLICA_LOGIN", "Login details for server with replica (requires REPLICATION CLIENT privileges)", $mysql_login_details || "-u test -ptest"); |
29 | 29 | ||
30 | my $result; | 30 | my $result; |
31 | 31 | ||
@@ -39,8 +39,8 @@ SKIP: { | |||
39 | like( $result->output, $bad_login_output, "Expected login failure message"); | 39 | like( $result->output, $bad_login_output, "Expected login failure message"); |
40 | 40 | ||
41 | $result = NPTest->testCmd("./check_mysql -S -H $mysqlserver $mysql_login_details"); | 41 | $result = NPTest->testCmd("./check_mysql -S -H $mysqlserver $mysql_login_details"); |
42 | cmp_ok( $result->return_code, "==", 1, "No slaves defined" ); | 42 | cmp_ok( $result->return_code, "==", 1, "No replicas defined" ); |
43 | like( $result->output, "/No slaves defined/", "Correct error message"); | 43 | like( $result->output, "/No replicas defined/", "Correct error message"); |
44 | } | 44 | } |
45 | 45 | ||
46 | SKIP: { | 46 | SKIP: { |
@@ -53,22 +53,22 @@ SKIP: { | |||
53 | like( $result->output, $bad_login_output, "Expected login failure message"); | 53 | like( $result->output, $bad_login_output, "Expected login failure message"); |
54 | 54 | ||
55 | $result = NPTest->testCmd("./check_mysql -S -s $mysqlsocket $mysql_login_details"); | 55 | $result = NPTest->testCmd("./check_mysql -S -s $mysqlsocket $mysql_login_details"); |
56 | cmp_ok( $result->return_code, "==", 1, "No slaves defined" ); | 56 | cmp_ok( $result->return_code, "==", 1, "No replicas defined" ); |
57 | like( $result->output, "/No slaves defined/", "Correct error message"); | 57 | like( $result->output, "/No replicas defined/", "Correct error message"); |
58 | } | 58 | } |
59 | 59 | ||
60 | SKIP: { | 60 | SKIP: { |
61 | skip "No mysql server with slaves defined", 5 unless $with_slave; | 61 | skip "No mysql server with replicas defined", 5 unless $with_replica; |
62 | $result = NPTest->testCmd("./check_mysql -H $with_slave $with_slave_login"); | 62 | $result = NPTest->testCmd("./check_mysql -H $with_replica $with_replica_login"); |
63 | cmp_ok( $result->return_code, '==', 0, "Login okay"); | 63 | cmp_ok( $result->return_code, '==', 0, "Login okay"); |
64 | 64 | ||
65 | $result = NPTest->testCmd("./check_mysql -S -H $with_slave $with_slave_login"); | 65 | $result = NPTest->testCmd("./check_mysql -S -H $with_replica $with_replica_login"); |
66 | cmp_ok( $result->return_code, "==", 0, "Slaves okay" ); | 66 | cmp_ok( $result->return_code, "==", 0, "Replicas okay" ); |
67 | 67 | ||
68 | $result = NPTest->testCmd("./check_mysql -S -H $with_slave $with_slave_login -w 60"); | 68 | $result = NPTest->testCmd("./check_mysql -S -H $with_replica $with_replica_login -w 60"); |
69 | cmp_ok( $result->return_code, '==', 0, 'Slaves are not > 60 seconds behind'); | 69 | cmp_ok( $result->return_code, '==', 0, 'Replicas are not > 60 seconds behind'); |
70 | 70 | ||
71 | $result = NPTest->testCmd("./check_mysql -S -H $with_slave $with_slave_login -w 60:"); | 71 | $result = NPTest->testCmd("./check_mysql -S -H $with_replica $with_replica_login -w 60:"); |
72 | cmp_ok( $result->return_code, '==', 1, 'Alert warning if < 60 seconds behind'); | 72 | cmp_ok( $result->return_code, '==', 1, 'Alert warning if < 60 seconds behind'); |
73 | like( $result->output, "/^SLOW_SLAVE WARNING:/", "Output okay"); | 73 | like( $result->output, "/^SLOW_REPLICA WARNING:/", "Output okay"); |
74 | } | 74 | } |
diff --git a/plugins/t/check_ntp.t b/plugins/t/check_ntp.t index b8fc8fdf..a8ac7bb8 100644 --- a/plugins/t/check_ntp.t +++ b/plugins/t/check_ntp.t | |||
@@ -37,7 +37,7 @@ my $ntp_critmatch1 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})? | |||
37 | my $ntp_okmatch2 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2},\struechimers=[0-9]+/'; | 37 | my $ntp_okmatch2 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2},\struechimers=[0-9]+/'; |
38 | my $ntp_warnmatch2 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}\s\(WARNING\),\struechimers=[0-9]+/'; | 38 | my $ntp_warnmatch2 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}\s\(WARNING\),\struechimers=[0-9]+/'; |
39 | my $ntp_critmatch2 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+\s\(CRITICAL\),\sstratum=[0-9]{1,2},\struechimers=[0-9]+/'; | 39 | my $ntp_critmatch2 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+\s\(CRITICAL\),\sstratum=[0-9]{1,2},\struechimers=[0-9]+/'; |
40 | my $ntp_noresponse = '/^(CRITICAL - Socket timeout after 3 seconds)|(NTP CRITICAL: No response from NTP server)$/'; | 40 | my $ntp_noresponse = '/(.*Socket timeout after \d+ seconds.*)|(.*No response from NTP server.*)/'; |
41 | my $ntp_nosuchhost = '/^check_ntp.*: Invalid hostname/address - ' . $hostname_invalid . '/'; | 41 | my $ntp_nosuchhost = '/^check_ntp.*: Invalid hostname/address - ' . $hostname_invalid . '/'; |
42 | 42 | ||
43 | 43 | ||
diff --git a/plugins/t/check_smtp.t b/plugins/t/check_smtp.t index 1a1ebe3e..73b4a1fd 100644 --- a/plugins/t/check_smtp.t +++ b/plugins/t/check_smtp.t | |||
@@ -24,7 +24,7 @@ my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | |||
24 | "An invalid (not known to DNS) hostname", "nosuchhost" ); | 24 | "An invalid (not known to DNS) hostname", "nosuchhost" ); |
25 | my $res; | 25 | my $res; |
26 | 26 | ||
27 | plan tests => 16; | 27 | plan tests => 15; |
28 | 28 | ||
29 | SKIP: { | 29 | SKIP: { |
30 | skip "No SMTP server defined", 4 unless $host_tcp_smtp; | 30 | skip "No SMTP server defined", 4 unless $host_tcp_smtp; |
@@ -73,7 +73,6 @@ SKIP: { | |||
73 | my $unused_port = 4465; | 73 | my $unused_port = 4465; |
74 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p $unused_port --ssl" ); | 74 | $res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p $unused_port --ssl" ); |
75 | is ($res->return_code, 2, "Check rc of connecting to $host_tcp_smtp_tls with TLS on unused port $unused_port" ); | 75 | is ($res->return_code, 2, "Check rc of connecting to $host_tcp_smtp_tls with TLS on unused port $unused_port" ); |
76 | like ($res->output, qr/^connect to address $host_tcp_smtp_tls and port $unused_port: Connection refused/, "Check output of connecting to $host_tcp_smtp_tls with TLS on unused port $unused_port"); | ||
77 | } | 76 | } |
78 | 77 | ||
79 | $res = NPTest->testCmd( "./check_smtp $host_nonresponsive" ); | 78 | $res = NPTest->testCmd( "./check_smtp $host_nonresponsive" ); |
diff --git a/plugins/t/check_ssh.t b/plugins/t/check_ssh.t index 907d33a8..8a20782e 100644 --- a/plugins/t/check_ssh.t +++ b/plugins/t/check_ssh.t | |||
@@ -5,10 +5,10 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use warnings; | ||
8 | use Test::More; | 9 | use Test::More; |
9 | use NPTest; | 10 | use NPTest; |
10 | 11 | use JSON; | |
11 | my $res; | ||
12 | 12 | ||
13 | # Required parameters | 13 | # Required parameters |
14 | my $ssh_host = getTestParameter("NP_SSH_HOST", | 14 | my $ssh_host = getTestParameter("NP_SSH_HOST", |
@@ -23,30 +23,38 @@ my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", | |||
23 | "An invalid (not known to DNS) hostname", | 23 | "An invalid (not known to DNS) hostname", |
24 | "nosuchhost" ); | 24 | "nosuchhost" ); |
25 | 25 | ||
26 | my $outputFormat = '--output-format mp-test-json'; | ||
27 | |||
28 | plan tests => 24; | ||
26 | 29 | ||
27 | plan tests => 14 + 6; | 30 | my $output; |
31 | my $result; | ||
28 | 32 | ||
29 | SKIP: { | 33 | SKIP: { |
30 | skip "SSH_HOST must be defined", 6 unless $ssh_host; | 34 | skip "SSH_HOST must be defined", 6 unless $ssh_host; |
35 | |||
36 | |||
31 | my $result = NPTest->testCmd( | 37 | my $result = NPTest->testCmd( |
32 | "./check_ssh -H $ssh_host" | 38 | "./check_ssh -H $ssh_host" ." ". $outputFormat |
33 | ); | 39 | ); |
34 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); | 40 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); |
35 | like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)"); | 41 | $output = decode_json($result->output); |
42 | is($output->{'state'}, "OK", "State was correct"); | ||
36 | 43 | ||
37 | 44 | ||
38 | $result = NPTest->testCmd( | 45 | $result = NPTest->testCmd( |
39 | "./check_ssh -H $host_nonresponsive -t 2" | 46 | "./check_ssh -H $host_nonresponsive -t 2" ." ". $outputFormat |
40 | ); | 47 | ); |
41 | cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)"); | 48 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); |
42 | like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)"); | 49 | $output = decode_json($result->output); |
50 | is($output->{'state'}, "CRITICAL", "State was correct"); | ||
43 | 51 | ||
44 | 52 | ||
45 | 53 | ||
46 | $result = NPTest->testCmd( | 54 | $result = NPTest->testCmd( |
47 | "./check_ssh -H $hostname_invalid -t 2" | 55 | "./check_ssh -H $hostname_invalid -t 2" ." ". $outputFormat |
48 | ); | 56 | ); |
49 | cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)"); | 57 | cmp_ok($result->return_code, '==', 3, "Exit with return code 3 (UNKNOWN)"); |
50 | like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)"); | 58 | like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)"); |
51 | 59 | ||
52 | 60 | ||
@@ -63,46 +71,80 @@ SKIP: { | |||
63 | # | 71 | # |
64 | # where `comments` is optional, protoversion is the SSH protocol version and | 72 | # where `comments` is optional, protoversion is the SSH protocol version and |
65 | # softwareversion is an arbitrary string representing the server software version | 73 | # softwareversion is an arbitrary string representing the server software version |
74 | |||
75 | my $found_version = 0; | ||
76 | |||
66 | open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1' | nc ${nc_flags}|"); | 77 | open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1' | nc ${nc_flags}|"); |
67 | sleep 0.1; | 78 | sleep 0.1; |
68 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | 79 | $result = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ." ". $outputFormat); |
69 | cmp_ok( $res->return_code, '==', 0, "Got SSH protocol version control string"); | 80 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); |
70 | like( $res->output, '/^SSH OK - nagiosplug.ssh.0.1 \(protocol 2.0\)/', "Output OK"); | 81 | $output = decode_json($result->output); |
82 | is($output->{'state'}, "OK", "State was correct"); | ||
83 | |||
84 | # looking for the version | ||
85 | for my $subcheck (@{$output->{'checks'}}) { | ||
86 | if ($subcheck->{'output'} =~ /.*nagiosplug.ssh.0.1 \(protocol version: 2.0\).*/ ){ | ||
87 | $found_version = 1; | ||
88 | } | ||
89 | } | ||
90 | cmp_ok($found_version, '==', 1, "Output OK"); | ||
71 | close NC; | 91 | close NC; |
72 | 92 | ||
73 | open(NC, "echo 'SSH-2.0-3.2.9.1' | nc ${nc_flags}|"); | 93 | open(NC, "echo 'SSH-2.0-3.2.9.1' | nc ${nc_flags}|"); |
74 | sleep 0.1; | 94 | sleep 0.1; |
75 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | 95 | $result = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ." ". $outputFormat); |
76 | cmp_ok( $res->return_code, "==", 0, "Got SSH protocol version control string with non-alpha softwareversion string"); | 96 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); |
77 | like( $res->output, '/^SSH OK - 3.2.9.1 \(protocol 2.0\)/', "Output OK for non-alpha softwareversion string"); | 97 | $output = decode_json($result->output); |
98 | is($output->{'state'}, "OK", "State was correct"); | ||
99 | |||
100 | $found_version = 0; | ||
101 | for my $subcheck (@{$output->{'checks'}}) { | ||
102 | if ($subcheck->{'output'} =~ /3.2.9.1 \(protocol version: 2.0\)/ ){ | ||
103 | $found_version = 1; | ||
104 | } | ||
105 | } | ||
106 | cmp_ok($found_version, '==', 1, "Output OK"); | ||
78 | close NC; | 107 | close NC; |
79 | 108 | ||
80 | open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1 this is a comment' | nc ${nc_flags} |"); | 109 | open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1 this is a comment' | nc ${nc_flags} |"); |
81 | sleep 0.1; | 110 | sleep 0.1; |
82 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003 -r nagiosplug.ssh.0.1" ); | 111 | $result = NPTest->testCmd( "./check_ssh -H localhost -p 5003 -r nagiosplug.ssh.0.1" ." ". $outputFormat); |
83 | cmp_ok( $res->return_code, '==', 0, "Got SSH protocol version control string, and parsed comment appropriately"); | 112 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); |
84 | like( $res->output, '/^SSH OK - nagiosplug.ssh.0.1 \(protocol 2.0\)/', "Output OK"); | 113 | $output = decode_json($result->output); |
114 | is($output->{'state'}, "OK", "State was correct"); | ||
115 | |||
116 | # looking for the version | ||
117 | $found_version = 0; | ||
118 | for my $subcheck (@{$output->{'checks'}}) { | ||
119 | if ($subcheck->{'output'} =~ /nagiosplug.ssh.0.1 \(protocol version: 2.0\)/ ){ | ||
120 | $found_version = 1; | ||
121 | } | ||
122 | } | ||
123 | cmp_ok($found_version, '==', 1, "Output OK"); | ||
85 | close NC; | 124 | close NC; |
86 | 125 | ||
87 | open(NC, "echo 'SSH-' | nc ${nc_flags}|"); | 126 | open(NC, "echo 'SSH-' | nc ${nc_flags}|"); |
88 | sleep 0.1; | 127 | sleep 0.1; |
89 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | 128 | $result = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ." ". $outputFormat); |
90 | cmp_ok( $res->return_code, '==', 2, "Got invalid SSH protocol version control string"); | 129 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); |
91 | like( $res->output, '/^SSH CRITICAL/', "Output OK"); | 130 | $output = decode_json($result->output); |
131 | is($output->{'state'}, "CRITICAL", "Got invalid SSH protocol version control string"); | ||
92 | close NC; | 132 | close NC; |
93 | 133 | ||
94 | open(NC, "echo '' | nc ${nc_flags}|"); | 134 | open(NC, "echo '' | nc ${nc_flags}|"); |
95 | sleep 0.1; | 135 | sleep 0.1; |
96 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | 136 | $result = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ." ". $outputFormat); |
97 | cmp_ok( $res->return_code, '==', 2, "No version control string received"); | 137 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); |
98 | like( $res->output, '/^SSH CRITICAL - No version control string received/', "Output OK"); | 138 | $output = decode_json($result->output); |
139 | is($output->{'state'}, "CRITICAL", "No version control string received"); | ||
99 | close NC; | 140 | close NC; |
100 | 141 | ||
101 | open(NC, "echo 'Not a version control string' | nc ${nc_flags}|"); | 142 | open(NC, "echo 'Not a version control string' | nc ${nc_flags}|"); |
102 | sleep 0.1; | 143 | sleep 0.1; |
103 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | 144 | $result = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ." ". $outputFormat); |
104 | cmp_ok( $res->return_code, '==', 2, "No version control string received"); | 145 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); |
105 | like( $res->output, '/^SSH CRITICAL - No version control string received/', "Output OK"); | 146 | $output = decode_json($result->output); |
147 | is($output->{'state'}, "CRITICAL", "No version control string received"); | ||
106 | close NC; | 148 | close NC; |
107 | 149 | ||
108 | 150 | ||
@@ -116,8 +158,18 @@ SKIP: { | |||
116 | echo 'Some\nPrepended\nData\nLines\n'; sleep 0.2; | 158 | echo 'Some\nPrepended\nData\nLines\n'; sleep 0.2; |
117 | echo 'SSH-2.0-nagiosplug.ssh.0.2';} | nc ${nc_flags}|"); | 159 | echo 'SSH-2.0-nagiosplug.ssh.0.2';} | nc ${nc_flags}|"); |
118 | sleep 0.1; | 160 | sleep 0.1; |
119 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | 161 | $result = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ." ". $outputFormat); |
120 | cmp_ok( $res->return_code, '==', 0, "Got delayed SSH protocol version control string"); | 162 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); |
121 | like( $res->output, '/^SSH OK - nagiosplug.ssh.0.2 \(protocol 2.0\)/', "Output OK"); | 163 | $output = decode_json($result->output); |
164 | is($output->{'state'}, "OK", "State was correct"); | ||
165 | |||
166 | # looking for the version | ||
167 | $found_version = 0; | ||
168 | for my $subcheck (@{$output->{'checks'}}) { | ||
169 | if ($subcheck->{'output'} =~ /nagiosplug.ssh.0.2 \(protocol version: 2.0\)/ ){ | ||
170 | $found_version = 1; | ||
171 | } | ||
172 | } | ||
173 | cmp_ok($found_version, '==', 1, "Output OK"); | ||
122 | close NC; | 174 | close NC; |
123 | } | 175 | } |
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index eaa81083..68946f6d 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t | |||
@@ -5,39 +5,47 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use Test::More tests => 14; | 8 | use warnings; |
9 | use Test::More tests => 21; | ||
9 | use NPTest; | 10 | use NPTest; |
10 | 11 | use JSON; | |
11 | my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | ||
12 | my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | ||
13 | my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | ||
14 | 12 | ||
15 | my $result; | 13 | my $result; |
14 | my $outputFormat = '--output-format mp-test-json'; | ||
15 | my $output; | ||
16 | my $message = '/^[0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | ||
16 | 17 | ||
17 | $result = NPTest->testCmd( "./check_swap" ); # Always OK | 18 | $result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK |
18 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 19 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
19 | like( $result->output, $successOutput, "Right output" ); | 20 | is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct"); |
21 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
20 | 22 | ||
21 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free | 23 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free |
22 | cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); | 24 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
23 | like( $result->output, $successOutput, "Right output" ); | 25 | is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct"); |
26 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
24 | 27 | ||
25 | $result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free | 28 | $result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free |
26 | cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); | 29 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
27 | like( $result->output, $successOutput, "Right output" ); | 30 | is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct"); |
31 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
28 | 32 | ||
29 | $result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical) | 33 | $result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical) |
30 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); | 34 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
31 | like( $result->output, $failureOutput, "Right output" ); | 35 | is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct"); |
36 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
32 | 37 | ||
33 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) | 38 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn) |
34 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | 39 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
35 | like( $result->output, $warnOutput, "Right output" ); | 40 | is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct"); |
41 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
36 | 42 | ||
37 | $result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn) | 43 | $result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn) |
38 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | 44 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
39 | like( $result->output, $warnOutput, "Right output" ); | 45 | is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct"); |
46 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
40 | 47 | ||
41 | $result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical) | 48 | $result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical) |
42 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); | 49 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
43 | like( $result->output, $failureOutput, "Right output" ); | 50 | is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct"); |
51 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t index cb4de53d..5c8fd0be 100644 --- a/plugins/t/check_tcp.t +++ b/plugins/t/check_tcp.t | |||
@@ -21,19 +21,19 @@ my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname | |||
21 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | 21 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
22 | my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes"); | 22 | my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes"); |
23 | 23 | ||
24 | my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; | 24 | my $successOutput = '/Connection time\s+[0-9]?\.?[0-9]+s is within thresholds+/'; |
25 | 25 | ||
26 | my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on port [0-9]+/'; | 26 | my $failedExpect = '/Answer failed to match/'; |
27 | 27 | ||
28 | my $t; | 28 | my $t; |
29 | 29 | ||
30 | $tests = $tests - 4 if $internet_access eq "no"; | 30 | $tests = $tests - 4 if $internet_access eq "no"; |
31 | plan tests => $tests; | 31 | plan tests => $tests; |
32 | 32 | ||
33 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); | 33 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -w 300 -c 600", 0, $successOutput ); |
34 | $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test | 34 | $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -w 0 -c 0 -t 1", 2 ); # use invalid port for this test |
35 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); | 35 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -w 0 -c 0 -t 1", 2 ); |
36 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); | 36 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -w 0 -c 0 -t 1", 2 ); |
37 | if($internet_access ne "no") { | 37 | if($internet_access ne "no") { |
38 | $t += checkCmd( "./check_tcp -S -D 1 -H $host_tls_http -p 443", 0 ); | 38 | $t += checkCmd( "./check_tcp -S -D 1 -H $host_tls_http -p 443", 0 ); |
39 | $t += checkCmd( "./check_tcp -S -D 9000,1 -H $host_tls_http -p 443", 1 ); | 39 | $t += checkCmd( "./check_tcp -S -D 9000,1 -H $host_tls_http -p 443", 1 ); |
diff --git a/plugins/t/check_udp.t b/plugins/t/check_udp.t index 6c47d095..5cb9e6dc 100644 --- a/plugins/t/check_udp.t +++ b/plugins/t/check_udp.t | |||
@@ -28,7 +28,7 @@ like ( $res->output, '/With UDP checks, a send/expect string must be specified. | |||
28 | 28 | ||
29 | $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s foo -e bar" ); | 29 | $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s foo -e bar" ); |
30 | cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" ); | 30 | cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" ); |
31 | like ( $res->output, '/No data received from host/', "Output OK"); | 31 | like ( $res->output, '/Received no data /', "Output OK"); |
32 | 32 | ||
33 | my $nc; | 33 | my $nc; |
34 | if(system("which nc.traditional >/dev/null 2>&1") == 0) { | 34 | if(system("which nc.traditional >/dev/null 2>&1") == 0) { |
@@ -48,7 +48,7 @@ SKIP: { | |||
48 | sleep 1; | 48 | sleep 1; |
49 | $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s '' -e barbar -4" ); | 49 | $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s '' -e barbar -4" ); |
50 | cmp_ok( $res->return_code, '==', 0, "Got barbar response back" ); | 50 | cmp_ok( $res->return_code, '==', 0, "Got barbar response back" ); |
51 | like ( $res->output, '/\[barbar\]/', "Output OK"); | 51 | like ( $res->output, '/answer of the server matched/', "Output OK"); |
52 | close NC; | 52 | close NC; |
53 | 53 | ||
54 | # Start up a udp server listening on port 3333, quit after 3 seconds | 54 | # Start up a udp server listening on port 3333, quit after 3 seconds |