diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-15 01:58:26 +0200 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-15 01:58:26 +0200 |
commit | 404d52efb9b814013d5664019cab714253ac13ff (patch) | |
tree | 7f8034f1f7625c63da282e900eb5baae9ee3d05c /plugins | |
parent | afa81204dc2f7cadb63c23aa47a0262dbf654139 (diff) | |
download | monitoring-plugins-404d52efb9b814013d5664019cab714253ac13ff.tar.gz |
Fix/adapt tests
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/t/check_curl.t | 43 | ||||
-rwxr-xr-x | plugins/tests/check_curl.t | 4 |
2 files changed, 29 insertions, 18 deletions
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 7f1a2de0..240c8f37 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t | |||
@@ -124,14 +124,14 @@ SKIP: { | |||
124 | 124 | ||
125 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing'" ); | 125 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing'" ); |
126 | cmp_ok( $res->return_code, "==", 2, "Not got 'mONiTORing'"); | 126 | cmp_ok( $res->return_code, "==", 2, "Not got 'mONiTORing'"); |
127 | like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'"); | 127 | like ( $res->output, "/matched not/", "Error message says 'matched not'"); |
128 | 128 | ||
129 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -R 'mONiTORing'" ); | 129 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -R 'mONiTORing'" ); |
130 | cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'mONiTORing'"); | 130 | cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'mONiTORing'"); |
131 | 131 | ||
132 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'monitoring' --invert-regex" ); | 132 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'monitoring' --invert-regex" ); |
133 | cmp_ok( $res->return_code, "==", 2, "Invert results work when found"); | 133 | cmp_ok( $res->return_code, "==", 2, "Invert results work when found"); |
134 | like ( $res->output, "/pattern found/", "Error message says 'pattern found'"); | 134 | like ( $res->output, "/matched/", "Error message says 'matched'"); |
135 | 135 | ||
136 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing' --invert-regex" ); | 136 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing' --invert-regex" ); |
137 | cmp_ok( $res->return_code, "==", 0, "And also when not found"); | 137 | cmp_ok( $res->return_code, "==", 0, "And also when not found"); |
@@ -151,63 +151,74 @@ SKIP: { | |||
151 | 151 | ||
152 | $res = NPTest->testCmd( "./$plugin -C 8000,1 --ssl $host_tls_http" ); | 152 | $res = NPTest->testCmd( "./$plugin -C 8000,1 --ssl $host_tls_http" ); |
153 | cmp_ok( $res->return_code, '==', 1, "Checking certificate for $host_tls_http"); | 153 | cmp_ok( $res->return_code, '==', 1, "Checking certificate for $host_tls_http"); |
154 | like ( $res->output, qr/WARNING - Certificate '$host_tls_cert' expires in \d+ day/, "Output Warning" ); | 154 | like ( $res->output, qr/Certificate '$host_tls_cert' expires in \d+ day/, "Output Warning" ); |
155 | 155 | ||
156 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); | 156 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); |
157 | is( $res->return_code, 0, "Old syntax for cert checking okay" ); | 157 | is( $res->return_code, 0, "Old syntax for cert checking okay" ); |
158 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); | 158 | # deactived since different timings will change the output |
159 | # TODO compare without perfdata | ||
160 | # is( $res->output, $saved_cert_output, "Same output as new syntax" ); | ||
159 | 161 | ||
160 | $res = NPTest->testCmd( "./$plugin -H $host_tls_http -C 1" ); | 162 | $res = NPTest->testCmd( "./$plugin -H $host_tls_http -C 1" ); |
161 | is( $res->return_code, 0, "Updated syntax for cert checking okay" ); | 163 | is( $res->return_code, 0, "Updated syntax for cert checking okay" ); |
162 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); | 164 | # deactived since different timings will change the output |
165 | # TODO compare without perfdata | ||
166 | # is( $res->output, $saved_cert_output, "Same output as new syntax" ); | ||
163 | 167 | ||
164 | $res = NPTest->testCmd( "./$plugin -C 1 $host_tls_http" ); | 168 | $res = NPTest->testCmd( "./$plugin -C 1 $host_tls_http" ); |
165 | cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added"); | 169 | # deactived since different timings will change the output |
170 | # TODO compare without perfdata | ||
171 | # cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added"); | ||
166 | 172 | ||
167 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); | 173 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); |
168 | cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); | 174 | # deactived since different timings will change the output |
175 | # TODO compare without perfdata | ||
176 | # cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); | ||
169 | 177 | ||
170 | # run some certificate checks with faketime | 178 | # run some certificate checks with faketime |
171 | SKIP: { | 179 | SKIP: { |
172 | skip "No faketime binary found", 12 if !$faketime; | 180 | skip "No faketime binary found", 12 if !$faketime; |
173 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./$plugin -C 1 $host_tls_http"); | 181 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./$plugin -C 1 $host_tls_http"); |
174 | like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); | 182 | like($res->output, qr/Certificate '$host_tls_cert' will expire on/, "Catch cert output"); |
175 | is( $res->return_code, 0, "Catch cert output exit code" ); | 183 | is( $res->return_code, 0, "Catch cert output exit code" ); |
184 | |||
176 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); | 185 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); |
177 | if(!defined $year) { | 186 | if(!defined $year) { |
178 | die("parsing date failed from: ".$res->output); | 187 | die("parsing date failed from: ".$res->output); |
179 | } | 188 | } |
189 | |||
180 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; | 190 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; |
181 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); | 191 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); |
182 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); | 192 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); |
193 | |||
183 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./$plugin -C 1 $host_tls_http"); | 194 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./$plugin -C 1 $host_tls_http"); |
184 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date"); | 195 | like($res->output, qr/Certificate '$host_tls_cert' just expired/, "Output on expire date"); |
185 | is( $res->return_code, 2, "Output on expire date" ); | 196 | is( $res->return_code, 2, "Output on expire date" ); |
186 | 197 | ||
187 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./$plugin -C 1 $host_tls_http"); | 198 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./$plugin -C 1 $host_tls_http"); |
188 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); | 199 | like($res->output, qr/Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); |
189 | is( $res->return_code, 2, "cert expires in 1 second exit code" ); | 200 | is( $res->return_code, 2, "cert expires in 1 second exit code" ); |
190 | 201 | ||
191 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./$plugin -C 1 $host_tls_http"); | 202 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./$plugin -C 1 $host_tls_http"); |
192 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); | 203 | like($res->output, qr/Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); |
193 | is( $res->return_code, 2, "cert expires in 2 minutes exit code" ); | 204 | is( $res->return_code, 2, "cert expires in 2 minutes exit code" ); |
194 | 205 | ||
195 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./$plugin -C 1 $host_tls_http"); | 206 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./$plugin -C 1 $host_tls_http"); |
196 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); | 207 | like($res->output, qr/Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); |
197 | is( $res->return_code, 2, "cert expires in 2 hours exit code" ); | 208 | is( $res->return_code, 2, "cert expires in 2 hours exit code" ); |
198 | 209 | ||
199 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./$plugin -C 1 $host_tls_http"); | 210 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./$plugin -C 1 $host_tls_http"); |
200 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output"); | 211 | like($res->output, qr/Certificate '$host_tls_cert' expired on/, "Certificate expired output"); |
201 | is( $res->return_code, 2, "Certificate expired exit code" ); | 212 | is( $res->return_code, 2, "Certificate expired exit code" ); |
202 | }; | 213 | }; |
203 | 214 | ||
204 | $res = NPTest->testCmd( "./$plugin --ssl $host_tls_http -E" ); | 215 | $res = NPTest->testCmd( "./$plugin --ssl $host_tls_http -E" ); |
205 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 216 | like ( $res->output, '/\'time_connect\'=[\d\.]+/', 'Extended Performance Data Output OK' ); |
206 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 217 | like ( $res->output, '/\'time_tls\'=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
207 | 218 | ||
208 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" ); | 219 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" ); |
209 | is( $res->return_code, 0, "Redirection based on location is okay"); | 220 | is( $res->return_code, 0, "Redirection based on location is okay"); |
210 | 221 | ||
211 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" ); | 222 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" ); |
212 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 223 | like ( $res->output, '/\'time_connect\'=[\d\.]+/', 'Extended Performance Data Output OK' ); |
213 | } | 224 | } |
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index e66d0ba6..52c5ad1c 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t | |||
@@ -246,7 +246,7 @@ SKIP: { | |||
246 | 246 | ||
247 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 247 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
248 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); | 248 | is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); |
249 | like( $result->output, "/.*Certificate \'Monitoring Plugins\' will expire on $expiry.*", "output ok" ); | 249 | like( $result->output, '/.*Certificate \'Monitoring Plugins\' will expire on ' . quotemeta($expiry) . '.*/', "output ok" ); |
250 | 250 | ||
251 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 251 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
252 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); | 252 | is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); |
@@ -260,7 +260,7 @@ SKIP: { | |||
260 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 260 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); |
261 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); | 261 | is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); |
262 | like( $result->output, | 262 | like( $result->output, |
263 | '/.*Certificate \'Monitoring Plugins\' expired on Wed Jan 2 12:00:00 2008 +0000.*/', | 263 | '/.*Certificate \'Monitoring Plugins\' expired on Wed Jan\s+2 12:00:00 2008 \+0000.*/', |
264 | "output ok" ); | 264 | "output ok" ); |
265 | 265 | ||
266 | } | 266 | } |