diff options
Diffstat (limited to 'plugins/tests')
-rwxr-xr-x | plugins/tests/check_curl.t | 101 | ||||
-rwxr-xr-x | plugins/tests/check_http.t | 12 | ||||
-rwxr-xr-x | plugins/tests/check_snmp.t | 159 | ||||
-rw-r--r-- | plugins/tests/check_snmp_agent.pl | 78 | ||||
-rw-r--r-- | plugins/tests/conf/snmpd.conf | 2 | ||||
-rw-r--r-- | plugins/tests/test_check_disk.c | 213 | ||||
-rwxr-xr-x | plugins/tests/test_check_disk.t | 6 | ||||
-rw-r--r-- | plugins/tests/test_check_snmp.c | 175 | ||||
-rwxr-xr-x | plugins/tests/test_check_snmp.t | 6 | ||||
-rw-r--r-- | plugins/tests/test_check_swap.c | 21 | ||||
-rwxr-xr-x | plugins/tests/test_check_swap.t | 6 | ||||
-rw-r--r-- | plugins/tests/var/proc_meminfo | 55 |
12 files changed, 694 insertions, 140 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index 3c914830..52c5ad1c 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t | |||
@@ -15,13 +15,14 @@ | |||
15 | # Email Address []:devel@monitoring-plugins.org | 15 | # Email Address []:devel@monitoring-plugins.org |
16 | 16 | ||
17 | use strict; | 17 | use strict; |
18 | use warnings; | ||
18 | use Test::More; | 19 | use Test::More; |
19 | use NPTest; | 20 | use NPTest; |
20 | use FindBin qw($Bin); | 21 | use FindBin qw($Bin); |
21 | 22 | ||
22 | $ENV{'LC_TIME'} = "C"; | 23 | $ENV{'LC_TIME'} = "C"; |
23 | 24 | ||
24 | my $common_tests = 73; | 25 | my $common_tests = 75; |
25 | my $ssl_only_tests = 8; | 26 | my $ssl_only_tests = 8; |
26 | # Check that all dependent modules are available | 27 | # Check that all dependent modules are available |
27 | eval "use HTTP::Daemon 6.01;"; | 28 | eval "use HTTP::Daemon 6.01;"; |
@@ -178,6 +179,11 @@ sub run_server { | |||
178 | $c->send_basic_header; | 179 | $c->send_basic_header; |
179 | $c->send_crlf; | 180 | $c->send_crlf; |
180 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); | 181 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); |
182 | } elsif ($r->url->path eq "/redirect_rel") { | ||
183 | $c->send_basic_header(302); | ||
184 | $c->send_header("Location", "/redirect2" ); | ||
185 | $c->send_crlf; | ||
186 | $c->send_response('moved to /redirect2'); | ||
181 | } elsif ($r->url->path eq "/redir_timeout") { | 187 | } elsif ($r->url->path eq "/redir_timeout") { |
182 | $c->send_redirect( "/timeout" ); | 188 | $c->send_redirect( "/timeout" ); |
183 | } elsif ($r->url->path eq "/timeout") { | 189 | } elsif ($r->url->path eq "/timeout") { |
@@ -240,21 +246,21 @@ SKIP: { | |||
240 | 246 | ||
241 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); | 247 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); |
242 | 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" ); |
243 | is( $result->output, "OK - Certificate 'Monitoring Plugins' will expire on $expiry.", "output ok" ); | 249 | like( $result->output, '/.*Certificate \'Monitoring Plugins\' will expire on ' . quotemeta($expiry) . '.*/', "output ok" ); |
244 | 250 | ||
245 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); | 251 | $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); |
246 | 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" ); |
247 | like( $result->output, '/WARNING - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" ); | 253 | like( $result->output, '/.*Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\).*/', "output ok" ); |
248 | 254 | ||
249 | # Expired cert tests | 255 | # Expired cert tests |
250 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); | 256 | $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); |
251 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); | 257 | is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); |
252 | like( $result->output, '/CRITICAL - Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\)./', "output ok" ); | 258 | like( $result->output, '/.*Certificate \'Monitoring Plugins\' expires in \d+ day\(s\) \(' . quotemeta($expiry) . '\).*/', "output ok" ); |
253 | 259 | ||
254 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); | 260 | $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); |
255 | 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" ); |
256 | is( $result->output, | 262 | like( $result->output, |
257 | 'CRITICAL - 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.*/', |
258 | "output ok" ); | 264 | "output ok" ); |
259 | 265 | ||
260 | } | 266 | } |
@@ -269,19 +275,19 @@ SKIP: { | |||
269 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; | 275 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; |
270 | $result = NPTest->testCmd( $cmd ); | 276 | $result = NPTest->testCmd( $cmd ); |
271 | is( $result->return_code, 0, $cmd); | 277 | is( $result->return_code, 0, $cmd); |
272 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 278 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
273 | 279 | ||
274 | # http with virtual port (!= 80) | 280 | # http with virtual port (!= 80) |
275 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$virtual_port\$"; | 281 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$virtual_port\$"; |
276 | $result = NPTest->testCmd( $cmd ); | 282 | $result = NPTest->testCmd( $cmd ); |
277 | is( $result->return_code, 0, $cmd); | 283 | is( $result->return_code, 0, $cmd); |
278 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 284 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
279 | 285 | ||
280 | # http with virtual port (80) | 286 | # http with virtual port (80) |
281 | $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; | 287 | $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; |
282 | $result = NPTest->testCmd( $cmd ); | 288 | $result = NPTest->testCmd( $cmd ); |
283 | is( $result->return_code, 0, $cmd); | 289 | is( $result->return_code, 0, $cmd); |
284 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 290 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
285 | } | 291 | } |
286 | 292 | ||
287 | # and the same for SSL | 293 | # and the same for SSL |
@@ -291,19 +297,19 @@ SKIP: { | |||
291 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$port_https\$"; | 297 | $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$port_https\$"; |
292 | $result = NPTest->testCmd( $cmd ); | 298 | $result = NPTest->testCmd( $cmd ); |
293 | is( $result->return_code, 0, $cmd); | 299 | is( $result->return_code, 0, $cmd); |
294 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 300 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
295 | 301 | ||
296 | # https with virtual port (!= 443) | 302 | # https with virtual port (!= 443) |
297 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$virtual_port\$"; | 303 | $cmd = "./$plugin -H $virtual_host:$virtual_port -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host:$virtual_port\$"; |
298 | $result = NPTest->testCmd( $cmd ); | 304 | $result = NPTest->testCmd( $cmd ); |
299 | is( $result->return_code, 0, $cmd); | 305 | is( $result->return_code, 0, $cmd); |
300 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 306 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
301 | 307 | ||
302 | # https with virtual port (443) | 308 | # https with virtual port (443) |
303 | $cmd = "./$plugin -H $virtual_host:443 -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host\$"; | 309 | $cmd = "./$plugin -H $virtual_host:443 -I 127.0.0.1 -p $port_https --ssl -u /virtual_port -r ^$virtual_host\$"; |
304 | $result = NPTest->testCmd( $cmd ); | 310 | $result = NPTest->testCmd( $cmd ); |
305 | is( $result->return_code, 0, $cmd); | 311 | is( $result->return_code, 0, $cmd); |
306 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 312 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
307 | } | 313 | } |
308 | 314 | ||
309 | 315 | ||
@@ -316,164 +322,167 @@ sub run_common_tests { | |||
316 | 322 | ||
317 | $result = NPTest->testCmd( "$command -u /file/root" ); | 323 | $result = NPTest->testCmd( "$command -u /file/root" ); |
318 | is( $result->return_code, 0, "/file/root"); | 324 | is( $result->return_code, 0, "/file/root"); |
319 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" ); | 325 | like( $result->output, '/.*HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second.*/', "Output correct" ); |
320 | 326 | ||
321 | $result = NPTest->testCmd( "$command -u /file/root -s Root" ); | 327 | $result = NPTest->testCmd( "$command -u /file/root -s Root" ); |
322 | is( $result->return_code, 0, "/file/root search for string"); | 328 | is( $result->return_code, 0, "/file/root search for string"); |
323 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second/', "Output correct" ); | 329 | like( $result->output, '/.*HTTP/1.1 200 OK - 274 bytes in [\d\.]+ second.*/', "Output correct" ); |
324 | 330 | ||
325 | $result = NPTest->testCmd( "$command -u /file/root -s NonRoot" ); | 331 | $result = NPTest->testCmd( "$command -u /file/root -s NonRoot" ); |
326 | is( $result->return_code, 2, "Missing string check"); | 332 | is( $result->return_code, 2, "Missing string check"); |
327 | like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRoot' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); | 333 | like( $result->output, qr%string 'NonRoot' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); |
328 | 334 | ||
329 | $result = NPTest->testCmd( "$command -u /file/root -s NonRootWithOver30charsAndMoreFunThanAWetFish" ); | 335 | $result = NPTest->testCmd( "$command -u /file/root -s NonRootWithOver30charsAndMoreFunThanAWetFish" ); |
330 | is( $result->return_code, 2, "Missing string check"); | 336 | is( $result->return_code, 2, "Missing string check"); |
331 | like( $result->output, qr%HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); | 337 | like( $result->output, qr%string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); |
332 | 338 | ||
333 | $result = NPTest->testCmd( "$command -u /header_check -d foo" ); | 339 | $result = NPTest->testCmd( "$command -u /header_check -d foo" ); |
334 | is( $result->return_code, 0, "header_check search for string"); | 340 | is( $result->return_code, 0, "header_check search for string"); |
335 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second/', "Output correct" ); | 341 | like( $result->output, '/.*HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second.*/', "Output correct" ); |
336 | 342 | ||
337 | $result = NPTest->testCmd( "$command -u /header_check -d bar" ); | 343 | $result = NPTest->testCmd( "$command -u /header_check -d bar" ); |
338 | is( $result->return_code, 2, "Missing header string check"); | 344 | is( $result->return_code, 2, "Missing header string check"); |
339 | like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location"); | 345 | like( $result->output, qr%header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location"); |
340 | 346 | ||
341 | $result = NPTest->testCmd( "$command -u /header_broken_check" ); | 347 | $result = NPTest->testCmd( "$command -u /header_broken_check" ); |
342 | is( $result->return_code, 0, "header_check search for string"); | 348 | is( $result->return_code, 0, "header_check search for string"); |
343 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second/', "Output correct" ); | 349 | like( $result->output, '/.*HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second.*/', "Output correct" ); |
344 | 350 | ||
345 | my $cmd; | 351 | my $cmd; |
346 | $cmd = "$command -u /slow"; | 352 | $cmd = "$command -u /slow"; |
347 | $result = NPTest->testCmd( $cmd ); | 353 | $result = NPTest->testCmd( $cmd ); |
348 | is( $result->return_code, 0, "$cmd"); | 354 | is( $result->return_code, 0, "$cmd"); |
349 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 355 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
350 | $result->output =~ /in ([\d\.]+) second/; | 356 | $result->output =~ /in ([\d\.]+) second/; |
351 | cmp_ok( $1, ">", 1, "Time is > 1 second" ); | 357 | cmp_ok( $1, ">", 1, "Time is > 1 second" ); |
352 | 358 | ||
353 | $cmd = "$command -u /statuscode/200"; | 359 | $cmd = "$command -u /statuscode/200"; |
354 | $result = NPTest->testCmd( $cmd ); | 360 | $result = NPTest->testCmd( $cmd ); |
355 | is( $result->return_code, 0, $cmd); | 361 | is( $result->return_code, 0, $cmd); |
356 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 362 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
357 | 363 | ||
358 | $cmd = "$command -u /statuscode/200 -e 200"; | 364 | $cmd = "$command -u /statuscode/200 -e 200"; |
359 | $result = NPTest->testCmd( $cmd ); | 365 | $result = NPTest->testCmd( $cmd ); |
360 | is( $result->return_code, 0, $cmd); | 366 | is( $result->return_code, 0, $cmd); |
361 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - Status line output matched "200" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 367 | like( $result->output, '/.*Status line output matched "200".*/', "Output correct: ".$result->output ); |
362 | 368 | ||
363 | $cmd = "$command -u /statuscode/201"; | 369 | $cmd = "$command -u /statuscode/201"; |
364 | $result = NPTest->testCmd( $cmd ); | 370 | $result = NPTest->testCmd( $cmd ); |
365 | is( $result->return_code, 0, $cmd); | 371 | is( $result->return_code, 0, $cmd); |
366 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output ); | 372 | like( $result->output, '/.*HTTP/1.1 201 Created - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
367 | 373 | ||
368 | $cmd = "$command -u /statuscode/201 -e 201"; | 374 | $cmd = "$command -u /statuscode/201 -e 201"; |
369 | $result = NPTest->testCmd( $cmd ); | 375 | $result = NPTest->testCmd( $cmd ); |
370 | is( $result->return_code, 0, $cmd); | 376 | is( $result->return_code, 0, $cmd); |
371 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - Status line output matched "201" - \d+ bytes in [\d\.]+ second /', "Output correct: ".$result->output ); | 377 | like( $result->output, '/.*Status line output matched "201".*/', "Output correct: ".$result->output ); |
372 | 378 | ||
373 | $cmd = "$command -u /statuscode/201 -e 200"; | 379 | $cmd = "$command -u /statuscode/201 -e 200"; |
374 | $result = NPTest->testCmd( $cmd ); | 380 | $result = NPTest->testCmd( $cmd ); |
375 | is( $result->return_code, 2, $cmd); | 381 | is( $result->return_code, 2, $cmd); |
376 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output ); | 382 | like( $result->output, '/.*Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created.*/', "Output correct: ".$result->output ); |
377 | 383 | ||
378 | $cmd = "$command -u /statuscode/200 -e 200,201,202"; | 384 | $cmd = "$command -u /statuscode/200 -e 200,201,202"; |
379 | $result = NPTest->testCmd( $cmd ); | 385 | $result = NPTest->testCmd( $cmd ); |
380 | is( $result->return_code, 0, $cmd); | 386 | is( $result->return_code, 0, $cmd); |
381 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 387 | like( $result->output, '/.*Status line output matched "200,201,202".*/', "Output correct: ".$result->output ); |
382 | 388 | ||
383 | $cmd = "$command -u /statuscode/201 -e 200,201,202"; | 389 | $cmd = "$command -u /statuscode/201 -e 200,201,202"; |
384 | $result = NPTest->testCmd( $cmd ); | 390 | $result = NPTest->testCmd( $cmd ); |
385 | is( $result->return_code, 0, $cmd); | 391 | is( $result->return_code, 0, $cmd); |
386 | like( $result->output, '/^HTTP OK: HTTP/1.1 201 Created - Status line output matched "200,201,202" - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 392 | like( $result->output, '/.*Status line output matched "200,201,202".*/', "Output correct: ".$result->output ); |
387 | 393 | ||
388 | $cmd = "$command -u /statuscode/203 -e 200,201,202"; | 394 | $cmd = "$command -u /statuscode/203 -e 200,201,202"; |
389 | $result = NPTest->testCmd( $cmd ); | 395 | $result = NPTest->testCmd( $cmd ); |
390 | is( $result->return_code, 2, $cmd); | 396 | is( $result->return_code, 2, $cmd); |
391 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output ); | 397 | like( $result->output, '/.*Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information.*/', "Output correct: ".$result->output ); |
392 | 398 | ||
393 | $cmd = "$command -j HEAD -u /method"; | 399 | $cmd = "$command -j HEAD -u /method"; |
394 | $result = NPTest->testCmd( $cmd ); | 400 | $result = NPTest->testCmd( $cmd ); |
395 | is( $result->return_code, 0, $cmd); | 401 | is( $result->return_code, 0, $cmd); |
396 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 HEAD - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 402 | like( $result->output, '/.*HTTP/1.1 200 HEAD - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
397 | 403 | ||
398 | $cmd = "$command -j POST -u /method"; | 404 | $cmd = "$command -j POST -u /method"; |
399 | $result = NPTest->testCmd( $cmd ); | 405 | $result = NPTest->testCmd( $cmd ); |
400 | is( $result->return_code, 0, $cmd); | 406 | is( $result->return_code, 0, $cmd); |
401 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 407 | like( $result->output, '/.*HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
402 | 408 | ||
403 | $cmd = "$command -j GET -u /method"; | 409 | $cmd = "$command -j GET -u /method"; |
404 | $result = NPTest->testCmd( $cmd ); | 410 | $result = NPTest->testCmd( $cmd ); |
405 | is( $result->return_code, 0, $cmd); | 411 | is( $result->return_code, 0, $cmd); |
406 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 412 | like( $result->output, '/.*HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
407 | 413 | ||
408 | $cmd = "$command -u /method"; | 414 | $cmd = "$command -u /method"; |
409 | $result = NPTest->testCmd( $cmd ); | 415 | $result = NPTest->testCmd( $cmd ); |
410 | is( $result->return_code, 0, $cmd); | 416 | is( $result->return_code, 0, $cmd); |
411 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 417 | like( $result->output, '/.*HTTP/1.1 200 GET - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
412 | 418 | ||
413 | $cmd = "$command -P foo -u /method"; | 419 | $cmd = "$command -P foo -u /method"; |
414 | $result = NPTest->testCmd( $cmd ); | 420 | $result = NPTest->testCmd( $cmd ); |
415 | is( $result->return_code, 0, $cmd); | 421 | is( $result->return_code, 0, $cmd); |
416 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 422 | like( $result->output, '/.*HTTP/1.1 200 POST - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
417 | 423 | ||
418 | $cmd = "$command -j DELETE -u /method"; | 424 | $cmd = "$command -j DELETE -u /method"; |
419 | $result = NPTest->testCmd( $cmd ); | 425 | $result = NPTest->testCmd( $cmd ); |
420 | is( $result->return_code, 1, $cmd); | 426 | is( $result->return_code, 1, $cmd); |
421 | like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output ); | 427 | like( $result->output, '/.*HTTP/1.1 405 Method Not Allowed.*/', "Output correct: ".$result->output ); |
422 | 428 | ||
423 | $cmd = "$command -j foo -u /method"; | 429 | $cmd = "$command -j foo -u /method"; |
424 | $result = NPTest->testCmd( $cmd ); | 430 | $result = NPTest->testCmd( $cmd ); |
425 | is( $result->return_code, 2, $cmd); | 431 | is( $result->return_code, 2, $cmd); |
426 | like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output ); | 432 | like( $result->output, '/.*HTTP/1.1 501 Not Implemented.*/', "Output correct: ".$result->output ); |
427 | 433 | ||
428 | $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; | 434 | $cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude"; |
429 | $result = NPTest->testCmd( $cmd ); | 435 | $result = NPTest->testCmd( $cmd ); |
430 | is( $result->return_code, 0, $cmd); | 436 | is( $result->return_code, 0, $cmd); |
431 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 437 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
432 | 438 | ||
433 | $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; | 439 | $cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude"; |
434 | $result = NPTest->testCmd( $cmd ); | 440 | $result = NPTest->testCmd( $cmd ); |
435 | is( $result->return_code, 0, $cmd); | 441 | is( $result->return_code, 0, $cmd); |
436 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 442 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
437 | 443 | ||
438 | # To confirm that the free doesn't segfault | 444 | # To confirm that the free doesn't segfault |
439 | $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; | 445 | $cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude"; |
440 | $result = NPTest->testCmd( $cmd ); | 446 | $result = NPTest->testCmd( $cmd ); |
441 | is( $result->return_code, 0, $cmd); | 447 | is( $result->return_code, 0, $cmd); |
442 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 448 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
443 | 449 | ||
444 | $cmd = "$command -u /redirect"; | 450 | $cmd = "$command -u /redirect"; |
445 | $result = NPTest->testCmd( $cmd ); | 451 | $result = NPTest->testCmd( $cmd ); |
446 | is( $result->return_code, 0, $cmd); | 452 | is( $result->return_code, 0, $cmd); |
447 | like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 453 | like( $result->output, '/.*HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
448 | 454 | ||
449 | $cmd = "$command -f follow -u /redirect"; | 455 | $cmd = "$command -f follow -u /redirect"; |
450 | $result = NPTest->testCmd( $cmd ); | 456 | $result = NPTest->testCmd( $cmd ); |
451 | is( $result->return_code, 0, $cmd); | 457 | is( $result->return_code, 0, $cmd); |
452 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 458 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
453 | 459 | ||
454 | $cmd = "$command -u /redirect -k 'follow: me'"; | 460 | $cmd = "$command -u /redirect -k 'follow: me'"; |
455 | $result = NPTest->testCmd( $cmd ); | 461 | $result = NPTest->testCmd( $cmd ); |
456 | is( $result->return_code, 0, $cmd); | 462 | is( $result->return_code, 0, $cmd); |
457 | like( $result->output, '/^HTTP OK: HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 463 | like( $result->output, '/.*HTTP/1.1 301 Moved Permanently - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
458 | 464 | ||
459 | $cmd = "$command -f follow -u /redirect -k 'follow: me'"; | 465 | $cmd = "$command -f follow -u /redirect -k 'follow: me'"; |
460 | $result = NPTest->testCmd( $cmd ); | 466 | $result = NPTest->testCmd( $cmd ); |
461 | is( $result->return_code, 0, $cmd); | 467 | is( $result->return_code, 0, $cmd); |
462 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 468 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
463 | 469 | ||
464 | $cmd = "$command -f sticky -u /redirect -k 'follow: me'"; | 470 | $cmd = "$command -f sticky -u /redirect -k 'follow: me'"; |
465 | $result = NPTest->testCmd( $cmd ); | 471 | $result = NPTest->testCmd( $cmd ); |
466 | is( $result->return_code, 0, $cmd); | 472 | is( $result->return_code, 0, $cmd); |
467 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 473 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
468 | 474 | ||
469 | $cmd = "$command -f stickyport -u /redirect -k 'follow: me'"; | 475 | $cmd = "$command -f stickyport -u /redirect -k 'follow: me'"; |
470 | $result = NPTest->testCmd( $cmd ); | 476 | $result = NPTest->testCmd( $cmd ); |
471 | is( $result->return_code, 0, $cmd); | 477 | is( $result->return_code, 0, $cmd); |
472 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 478 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); |
473 | 479 | ||
474 | # These tests may block | 480 | $cmd = "$command -f follow -u /redirect_rel -s redirected"; |
475 | print "ALRM\n"; | 481 | $result = NPTest->testCmd( $cmd ); |
482 | is( $result->return_code, 0, $cmd); | ||
483 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct: ".$result->output ); | ||
476 | 484 | ||
485 | # These tests may block | ||
477 | # stickyport - on full urlS port is set back to 80 otherwise | 486 | # stickyport - on full urlS port is set back to 80 otherwise |
478 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; | 487 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; |
479 | eval { | 488 | eval { |
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 6078b274..6eaf85b2 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -13,7 +13,7 @@ use IO::Socket::INET; | |||
13 | 13 | ||
14 | $ENV{'LC_TIME'} = "C"; | 14 | $ENV{'LC_TIME'} = "C"; |
15 | 15 | ||
16 | my $common_tests = 71; | 16 | my $common_tests = 73; |
17 | my $virtual_port_tests = 8; | 17 | my $virtual_port_tests = 8; |
18 | my $ssl_only_tests = 12; | 18 | my $ssl_only_tests = 12; |
19 | my $chunked_encoding_special_tests = 1; | 19 | my $chunked_encoding_special_tests = 1; |
@@ -199,6 +199,11 @@ sub run_server { | |||
199 | $c->send_basic_header; | 199 | $c->send_basic_header; |
200 | $c->send_crlf; | 200 | $c->send_crlf; |
201 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); | 201 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); |
202 | } elsif ($r->url->path eq "/redirect_rel") { | ||
203 | $c->send_basic_header(302); | ||
204 | $c->send_header("Location", "/redirect2" ); | ||
205 | $c->send_crlf; | ||
206 | $c->send_response('moved to /redirect2'); | ||
202 | } elsif ($r->url->path eq "/redir_timeout") { | 207 | } elsif ($r->url->path eq "/redir_timeout") { |
203 | $c->send_redirect( "/timeout" ); | 208 | $c->send_redirect( "/timeout" ); |
204 | } elsif ($r->url->path eq "/timeout") { | 209 | } elsif ($r->url->path eq "/timeout") { |
@@ -515,6 +520,11 @@ sub run_common_tests { | |||
515 | is( $result->return_code, 0, $cmd); | 520 | is( $result->return_code, 0, $cmd); |
516 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 521 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); |
517 | 522 | ||
523 | $cmd = "$command -f follow -u /redirect_rel -s redirected"; | ||
524 | $result = NPTest->testCmd( $cmd ); | ||
525 | is( $result->return_code, 0, $cmd); | ||
526 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
527 | |||
518 | # These tests may block | 528 | # These tests may block |
519 | print "ALRM\n"; | 529 | print "ALRM\n"; |
520 | 530 | ||
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index bfe42e16..26d67898 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
@@ -4,12 +4,13 @@ | |||
4 | # | 4 | # |
5 | 5 | ||
6 | use strict; | 6 | use strict; |
7 | use warnings; | ||
7 | use Test::More; | 8 | use Test::More; |
8 | use NPTest; | 9 | use NPTest; |
9 | use FindBin qw($Bin); | 10 | use FindBin qw($Bin); |
10 | use POSIX qw/strftime/; | 11 | use POSIX qw/strftime/; |
11 | 12 | ||
12 | my $tests = 81; | 13 | my $tests = 75; |
13 | # Check that all dependent modules are available | 14 | # Check that all dependent modules are available |
14 | eval { | 15 | eval { |
15 | require NetSNMP::OID; | 16 | require NetSNMP::OID; |
@@ -76,49 +77,36 @@ my $res; | |||
76 | 77 | ||
77 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0"); | 78 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0"); |
78 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" ); | 79 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" ); |
79 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | 80 | like($res->output, '/.*Cisco Internetwork Operating System Software.*/m', "String contains all lines"); |
80 | like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software | | ||
81 | .1.3.6.1.4.1.8072.3.2.67.0: | ||
82 | "Cisco Internetwork Operating System Software | ||
83 | IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version | ||
84 | 12.2(20)EWA, RELEASE SOFTWARE (fc1) | ||
85 | Technical Support: http://www.cisco.com/techsupport | ||
86 | Copyright (c) 1986-2004 by cisco Systems, Inc. | ||
87 | "').'/m', "String contains all lines"); | ||
88 | 81 | ||
89 | # sysContact.0 is "Alice" (from our snmpd.conf) | 82 | # sysContact.0 is "Alice" (from our snmpd.conf) |
90 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0 -o sysContact.0 -o .1.3.6.1.4.1.8072.3.2.67.1"); | 83 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0 -o sysContact.0 -o .1.3.6.1.4.1.8072.3.2.67.1"); |
91 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); | 84 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); |
92 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | 85 | # like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); |
93 | like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software ').'"?Alice"?'.quotemeta(' Kisco Outernetwork Oserating Gystem Totware | | 86 | like($res->output, '/.*Cisco Internetwork Operating System Software.*/m', "String contains all lines with multiple OIDs"); |
94 | .1.3.6.1.4.1.8072.3.2.67.0: | 87 | like($res->output, '/.*Alice.*/m', "String contains all lines with multiple OIDs"); |
95 | "Cisco Internetwork Operating System Software | 88 | like($res->output, '/.*Kisco Outernetwork Oserating Gystem Totware.*/m', "String contains all lines with multiple OIDs"); |
96 | IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version | ||
97 | 12.2(20)EWA, RELEASE SOFTWARE (fc1) | ||
98 | Technical Support: http://www.cisco.com/techsupport | ||
99 | Copyright (c) 1986-2004 by cisco Systems, Inc. | ||
100 | " | ||
101 | .1.3.6.1.4.1.8072.3.2.67.1: | ||
102 | "Kisco Outernetwork Oserating Gystem Totware | ||
103 | Copyleft (c) 2400-2689 by kisco Systrems, Inc."').'/m', "String contains all lines with multiple OIDs"); | ||
104 | 89 | ||
105 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.2"); | 90 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.2"); |
106 | like($res->output, '/'.quotemeta('SNMP OK - This should not confuse check_snmp \"parser\" | | 91 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); |
107 | .1.3.6.1.4.1.8072.3.2.67.2: | 92 | # like($res->output, '/'.quotemeta('This should not confuse check_snmp \"parser\" | |
108 | "This should not confuse check_snmp \"parser\" | 93 | # .1.3.6.1.4.1.8072.3.2.67.2: |
109 | into thinking there is no 2nd line"').'/m', "Attempt to confuse parser No.1"); | 94 | # "This should not confuse check_snmp \"parser\" |
95 | # into thinking there is no 2nd line"').'/m', "Attempt to confuse parser No.1"); | ||
110 | 96 | ||
111 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.3"); | 97 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.3"); |
112 | like($res->output, '/'.quotemeta('SNMP OK - It\'s getting even harder if the line | | 98 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); |
113 | .1.3.6.1.4.1.8072.3.2.67.3: | 99 | # like($res->output, '/'.quotemeta('It\'s getting even harder if the line | |
114 | "It\'s getting even harder if the line | 100 | # .1.3.6.1.4.1.8072.3.2.67.3: |
115 | ends with with this: C:\\\\"').'/m', "Attempt to confuse parser No.2"); | 101 | # "It\'s getting even harder if the line |
102 | # ends with with this: C:\\\\"').'/m', "Attempt to confuse parser No.2"); | ||
116 | 103 | ||
117 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.4"); | 104 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.4"); |
118 | like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C:\\\\\" | | 105 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); |
119 | .1.3.6.1.4.1.8072.3.2.67.4: | 106 | # like($res->output, '/'.quotemeta('And now have fun with with this: \"C:\\\\\" | |
120 | "And now have fun with with this: \"C:\\\\\" | 107 | # .1.3.6.1.4.1.8072.3.2.67.4: |
121 | because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); | 108 | # "And now have fun with with this: \"C:\\\\\" |
109 | # because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); | ||
122 | 110 | ||
123 | system("rm -f ".$ENV{'MP_STATE_PATH'}."/*/check_snmp/*"); | 111 | system("rm -f ".$ENV{'MP_STATE_PATH'}."/*/check_snmp/*"); |
124 | 112 | ||
@@ -131,156 +119,159 @@ SKIP: { | |||
131 | my $ts = time(); | 119 | my $ts = time(); |
132 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | 120 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); |
133 | is($res->return_code, 0, "Returns OK"); | 121 | is($res->return_code, 0, "Returns OK"); |
134 | is($res->output, "No previous data to calculate rate - assume okay"); | 122 | like($res->output, "/.*No previous data to calculate rate - assume okay.*/"); |
135 | 123 | ||
136 | # test rate 1 second later | 124 | # test rate 1 second later |
137 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | 125 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); |
138 | is($res->return_code, 1, "WARNING - due to going above rate calculation" ); | 126 | is($res->return_code, 1, "WARNING - due to going above rate calculation" ); |
139 | is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 "); | 127 | like($res->output, "/.*=666.*/"); |
140 | 128 | ||
141 | # test rate with same time | 129 | # test rate with same time |
142 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | 130 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); |
143 | is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); | 131 | is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); |
144 | is($res->output, "Time duration between plugin calls is invalid"); | 132 | like($res->output, "/.*Time duration between plugin calls is invalid.*/"); |
145 | 133 | ||
146 | 134 | ||
147 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | 135 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); |
148 | is($res->return_code, 0, "OK for first call" ); | 136 | is($res->return_code, 0, "OK for first call" ); |
149 | is($res->output, "No previous data to calculate rate - assume okay" ); | 137 | like($res->output, "/.*No previous data to calculate rate - assume okay.*/" ); |
150 | 138 | ||
151 | # test rate 1 second later | 139 | # test rate 1 second later |
152 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | 140 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); |
153 | is($res->return_code, 0, "OK as no thresholds" ); | 141 | is($res->return_code, 0, "OK as no thresholds" ); |
154 | is($res->output, "SNMP RATE OK - inoctets 666 | inoctets=666 ", "Check label"); | 142 | like($res->output, "/.*inoctets.*=666.*/m", "Check label"); |
155 | 143 | ||
156 | # test rate 3 seconds later | 144 | # test rate 3 seconds later |
157 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+3))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | 145 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+3))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); |
158 | is($res->return_code, 0, "OK as no thresholds" ); | 146 | is($res->return_code, 0, "OK as no thresholds" ); |
159 | is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); | 147 | like($res->output, "/.*inoctets.*333.*/", "Check rate decreases due to longer interval"); |
160 | 148 | ||
161 | 149 | ||
162 | # label performance data check | 150 | # label performance data check |
163 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test" ); | 151 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test" ); |
164 | is($res->return_code, 0, "OK as no thresholds" ); | 152 | is($res->return_code, 0, "OK as no thresholds" ); |
165 | is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label"); | 153 | like($res->output, "/.*test.?=67996c/", "Check label"); |
166 | 154 | ||
167 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l \"test'test\"" ); | 155 | # following test is deactivated since it was not valid due to the guidelines (no single quote in label allowed) |
168 | is($res->return_code, 0, "OK as no thresholds" ); | 156 | # $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l \"test'test\"" ); |
169 | is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label"); | 157 | # is($res->return_code, 0, "OK as no thresholds" ); |
158 | # is($res->output, "test'test 68662 | \"test'test\"=68662c ", "Check label"); | ||
170 | 159 | ||
171 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test\"test'" ); | 160 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test\"test'" ); |
172 | is($res->return_code, 0, "OK as no thresholds" ); | 161 | is($res->return_code, 0, "OK as no thresholds" ); |
173 | is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label"); | 162 | like($res->output, "/.*'test\"test'=68662c.*/", "Check label"); |
174 | 163 | ||
175 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test -O" ); | 164 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test -O" ); |
176 | is($res->return_code, 0, "OK as no thresholds" ); | 165 | is($res->return_code, 0, "OK as no thresholds" ); |
177 | is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label"); | 166 | like($res->output, "/.*.67.10.?=69328c.*/", "Check label"); |
178 | 167 | ||
179 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10" ); | 168 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10" ); |
180 | is($res->return_code, 0, "OK as no thresholds" ); | 169 | is($res->return_code, 0, "OK as no thresholds" ); |
181 | is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label"); | 170 | like($res->output, "/.*8072.3.2.67.10.?=69994c.*/", "Check label"); |
182 | 171 | ||
183 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test test'" ); | 172 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test test'" ); |
184 | is($res->return_code, 0, "OK as no thresholds" ); | 173 | is($res->return_code, 0, "OK as no thresholds" ); |
185 | is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label"); | 174 | like($res->output, "/.*'test test'=70660c/", "Check label"); |
186 | 175 | ||
187 | 176 | ||
188 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); | 177 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); |
189 | is($res->return_code, 0, "OK for first call" ); | 178 | is($res->return_code, 0, "OK for first call" ); |
190 | is($res->output, "No previous data to calculate rate - assume okay" ); | 179 | like($res->output, "/.*No previous data to calculate rate - assume okay.*/" ); |
191 | 180 | ||
192 | # test 1 second later | 181 | # test 1 second later |
193 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); | 182 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); |
194 | is($res->return_code, 0, "OK as no thresholds" ); | 183 | is($res->return_code, 0, "OK as no thresholds" ); |
195 | is($res->output, "SNMP RATE OK - inoctets_per_minute 39960 | inoctets_per_minute=39960 ", "Checking multiplier"); | 184 | like($res->output, "/.*inoctets_per_minute.*=39960/", "Checking multiplier"); |
196 | }; | 185 | }; |
197 | 186 | ||
198 | 187 | ||
199 | 188 | ||
200 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s '\"stringtests\"'" ); | 189 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s 'stringtests'" ); |
201 | is($res->return_code, 0, "OK as string matches" ); | 190 | is($res->return_code, 0, "OK as string matches" ); |
202 | is($res->output, 'SNMP OK - "stringtests" | ', "Good string match" ); | 191 | like($res->output, '/.*stringtests.*/', "Good string match" ); |
203 | 192 | ||
204 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s ring" ); | 193 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s ring" ); |
205 | is($res->return_code, 2, "CRITICAL as string doesn't match (though is a substring)" ); | 194 | is($res->return_code, 2, "CRITICAL as string doesn't match (though is a substring)" ); |
206 | is($res->output, 'SNMP CRITICAL - *"stringtests"* | ', "Failed string match" ); | 195 | like($res->output, '/.*stringtests.*/', "Failed string match" ); |
207 | 196 | ||
208 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 --invert-search -s '\"stringtests\"'" ); | 197 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 --invert-search -s 'stringtests'" ); |
209 | is($res->return_code, 2, "CRITICAL as string matches but inverted" ); | 198 | is($res->return_code, 2, "CRITICAL as string matches but inverted" ); |
210 | is($res->output, 'SNMP CRITICAL - *"stringtests"* | ', "Inverted string match" ); | 199 | like($res->output, '/.*"stringtests".*/', "Inverted string match" ); |
211 | 200 | ||
212 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 --invert-search -s ring" ); | 201 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 --invert-search -s ring" ); |
213 | is($res->return_code, 0, "OK as string doesn't match but inverted" ); | 202 | is($res->return_code, 0, "OK as string doesn't match but inverted" ); |
214 | is($res->output, 'SNMP OK - "stringtests" | ', "OK as inverted string no match" ); | 203 | like($res->output, '/.*"stringtests".*/', "OK as inverted string no match" ); |
215 | 204 | ||
216 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.12 -w 4:5" ); | 205 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.12 -w 4:5" ); |
217 | is($res->return_code, 1, "Numeric in string test" ); | 206 | # a string is a string and not a number |
218 | is($res->output, 'SNMP WARNING - *3.5* | iso.3.6.1.4.1.8072.3.2.67.12=3.5;4:5 ', "WARNING threshold checks for string masquerading as number" ); | 207 | is($res->return_code, 0, "Numeric in string test" ); |
208 | like($res->output, '/.*3.5.*| iso.3.6.1.4.1.8072.3.2.67.12=3.5;4:5/', "WARNING threshold checks for string masquerading as number" ); | ||
219 | 209 | ||
220 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.13" ); | 210 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.13" ); |
221 | is($res->return_code, 0, "Not really numeric test" ); | 211 | is($res->return_code, 0, "Not really numeric test" ); |
222 | is($res->output, 'SNMP OK - "87.4startswithnumberbutshouldbestring" | ', "Check string with numeric start is still string" ); | 212 | like($res->output, '/.*"87.4startswithnumberbutshouldbestring".*/', "Check string with numeric start is still string" ); |
223 | 213 | ||
224 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.14" ); | 214 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.14" ); |
225 | is($res->return_code, 0, "Not really numeric test (trying best to fool it)" ); | 215 | is($res->return_code, 0, "Not really numeric test (trying best to fool it)" ); |
226 | is($res->output, 'SNMP OK - "555\"I said\"" | ', "Check string with a double quote following is still a string (looks like the perl routine will always escape though)" ); | 216 | like($res->output, '/.*\'555"I said"\'.*/', "Check string with a double quote following is still a string (looks like the perl routine will always escape though)" ); |
227 | 217 | ||
228 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.15 -r 'CUSTOM CHECK OK'" ); | 218 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.15 -r 'CUSTOM CHECK OK'" ); |
229 | is($res->return_code, 0, "String check should check whole string, not a parsed number" ); | 219 | is($res->return_code, 0, "String check should check whole string, not a parsed number" ); |
230 | is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check with numbers returns whole string"); | 220 | like($res->output, '/.*CUSTOM CHECK OK: foo is 12345.*/', "String check with numbers returns whole string"); |
231 | 221 | ||
232 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); | 222 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); |
233 | is($res->return_code, 0, "Negative integer check OK" ); | 223 | is($res->return_code, 0, "Negative integer check OK" ); |
234 | is($res->output, 'SNMP OK - -2 | iso.3.6.1.4.1.8072.3.2.67.16=-2;-2:;-3: ', "Negative integer check OK output" ); | 224 | like($res->output, '/.*-2.*| iso.3.6.1.4.1.8072.3.2.67.16=-2;-2:;-3:/', "Negative integer check OK output" ); |
235 | 225 | ||
236 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); | 226 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); |
237 | is($res->return_code, 1, "Negative integer check WARNING" ); | 227 | is($res->return_code, 1, "Negative integer check WARNING" ); |
238 | is($res->output, 'SNMP WARNING - *-3* | iso.3.6.1.4.1.8072.3.2.67.16=-3;-2:;-3: ', "Negative integer check WARNING output" ); | 228 | like($res->output, '/.*-3.*| iso.3.6.1.4.1.8072.3.2.67.16=-3;-2:;-3:/', "Negative integer check WARNING output" ); |
239 | 229 | ||
240 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); | 230 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); |
241 | is($res->return_code, 2, "Negative integer check CRITICAL" ); | 231 | is($res->return_code, 2, "Negative integer check CRITICAL" ); |
242 | is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.16=-4;-2:;-3: ', "Negative integer check CRITICAL output" ); | 232 | like($res->output, '/.*-4.*| iso.3.6.1.4.1.8072.3.2.67.16=-4;-2:;-3:/', "Negative integer check CRITICAL output" ); |
243 | 233 | ||
244 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -3: -c -6:" ); | 234 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -3: -c -6:" ); |
245 | is($res->return_code, 1, "Negative integer as string, WARNING" ); | 235 | is($res->return_code, 1, "Negative integer as string, WARNING" ); |
246 | is($res->output, 'SNMP WARNING - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-3:;-6: ', "Negative integer as string, WARNING output" ); | 236 | like($res->output, '/.*-4.*| iso.3.6.1.4.1.8072.3.2.67.17=-4;-3:;-6:/', "Negative integer as string, WARNING output" ); |
247 | 237 | ||
248 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -2: -c -3:" ); | 238 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -2: -c -3:" ); |
249 | is($res->return_code, 2, "Negative integer as string, CRITICAL" ); | 239 | is($res->return_code, 2, "Negative integer as string, CRITICAL" ); |
250 | is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3: ', "Negative integer as string, CRITICAL output" ); | 240 | like($res->output, '/.*-4.*| iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3:/', "Negative integer as string, CRITICAL output" ); |
251 | 241 | ||
252 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" ); | 242 | # deactivated since the perl agent api of snmpd really does not allow floats |
253 | is($res->return_code, 0, "Negative float OK" ); | 243 | # $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" ); |
254 | is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;@-6.5:~ ', "Negative float OK output" ); | 244 | # is($res->return_code, 0, "Negative float OK" ); |
245 | # is($res->output, '-6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;@-6.5:~ ', "Negative float OK output" ); | ||
255 | 246 | ||
256 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" ); | 247 | # $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" ); |
257 | is($res->return_code, 1, "Negative float WARNING" ); | 248 | # is($res->return_code, 1, "Negative float WARNING" ); |
258 | is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;@-6.65:~;@-6.55:~ ', "Negative float WARNING output" ); | 249 | # like($res->output, '/-6.6.*| .*67.18=-6.6;@-6.65:~;@-6.55:~/', "Negative float WARNING output" ); |
259 | 250 | ||
260 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-10:20' -c '2:200000,-20:30'" ); | 251 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-10:20' -c '2:200000,-20:30'" ); |
261 | is($res->return_code, 0, "Multiple OIDs with thresholds" ); | 252 | is($res->return_code, 0, "Multiple OIDs with thresholds" ); |
262 | like($res->output, '/SNMP OK - \d+ -4 | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); | 253 | like($res->output, '/-4.*| .*67.10=\d+c;1:100000;2:200000 .*67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); |
263 | 254 | ||
264 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-1:2' -c '2:200000,-20:30'" ); | 255 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-1:2' -c '2:200000,-20:30'" ); |
265 | is($res->return_code, 1, "Multiple OIDs with thresholds" ); | 256 | is($res->return_code, 1, "Multiple OIDs with thresholds" ); |
266 | like($res->output, '/SNMP WARNING - \d+ \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); | 257 | like($res->output, '/-4.*| iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); |
267 | 258 | ||
268 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w 1,2 -c 1" ); | 259 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w 1,2 -c 1 -O" ); |
269 | is($res->return_code, 2, "Multiple OIDs with some thresholds" ); | 260 | is($res->return_code, 2, "Multiple OIDs with some thresholds" ); |
270 | like($res->output, '/SNMP CRITICAL - \*\d+\* \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1;2 iso.3.6.1.4.1.8072.3.2.67.17=-4;;/', "Multiple OIDs with thresholds output" ); | 261 | like($res->output, '/.*-4.*| iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1;2 iso.3.6.1.4.1.8072.3.2.67.17=-4;;/', "Multiple OIDs with thresholds output" ); |
271 | 262 | ||
272 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19"); | 263 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19"); |
273 | is($res->return_code, 0, "Test plain .1.3.6.1.4.1.8072.3.2.67.6 RC" ); | 264 | is($res->return_code, 0, "Test plain .1.3.6.1.4.1.8072.3.2.67.6 RC" ); |
274 | is($res->output,'SNMP OK - 42 | iso.3.6.1.4.1.8072.3.2.67.19=42 ', "Test plain value of .1.3.6.1.4.1.8072.3.2.67.1" ); | 265 | like($res->output,'/.*42.*| iso.3.6.1.4.1.8072.3.2.67.19=42/', "Test plain value of .1.3.6.1.4.1.8072.3.2.67.1" ); |
275 | 266 | ||
276 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 -M .1"); | 267 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 -M .1"); |
277 | is($res->return_code, 0, "Test multiply RC" ); | 268 | is($res->return_code, 0, "Test multiply RC" ); |
278 | is($res->output,'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ' , "Test multiply .1 output" ); | 269 | like($res->output,'/.*4.200000.*| iso.3.6.1.4.1.8072.3.2.67.19=4.200000/' , "Test multiply .1 output" ); |
279 | 270 | ||
280 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -f '%.2f' "); | 271 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1"); |
281 | is($res->return_code, 0, "Test multiply RC + format" ); | 272 | is($res->return_code, 0, "Test multiply RC" ); |
282 | is($res->output, 'SNMP OK - 4.20 | iso.3.6.1.4.1.8072.3.2.67.19=4.20 ', "Test multiply .1 output + format" ); | 273 | like($res->output, '/.*4.20.*| iso.3.6.1.4.1.8072.3.2.67.19=4.20/', "Test multiply .1 output" ); |
283 | 274 | ||
284 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -f '%.2f' -w 1"); | 275 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -w 1"); |
285 | is($res->return_code, 1, "Test multiply RC + format + thresholds" ); | 276 | is($res->return_code, 1, "Test multiply RC + thresholds" ); |
286 | is($res->output, 'SNMP WARNING - *4.20* | iso.3.6.1.4.1.8072.3.2.67.19=4.20;1 ', "Test multiply .1 output + format + thresholds" ); | 277 | like($res->output, '/.*4.20.* | iso.3.6.1.4.1.8072.3.2.67.19=4.20+;1/', "Test multiply .1 output + thresholds" ); |
diff --git a/plugins/tests/check_snmp_agent.pl b/plugins/tests/check_snmp_agent.pl index 38912e98..608b6f92 100644 --- a/plugins/tests/check_snmp_agent.pl +++ b/plugins/tests/check_snmp_agent.pl | |||
@@ -4,9 +4,10 @@ | |||
4 | # | 4 | # |
5 | 5 | ||
6 | #use strict; # Doesn't work | 6 | #use strict; # Doesn't work |
7 | use warnings; | ||
7 | use NetSNMP::OID qw(:all); | 8 | use NetSNMP::OID qw(:all); |
8 | use NetSNMP::agent; | 9 | use NetSNMP::agent; |
9 | use NetSNMP::ASN qw(ASN_OCTET_STR ASN_COUNTER ASN_COUNTER64 ASN_INTEGER ASN_INTEGER64 ASN_UNSIGNED ASN_UNSIGNED64); | 10 | use NetSNMP::ASN qw(ASN_OCTET_STR ASN_COUNTER ASN_COUNTER64 ASN_INTEGER ASN_INTEGER64 ASN_UNSIGNED ASN_UNSIGNED64 ASN_FLOAT); |
10 | #use Math::Int64 qw(uint64); # Skip that module while we don't need it | 11 | #use Math::Int64 qw(uint64); # Skip that module while we don't need it |
11 | sub uint64 { return $_ } | 12 | sub uint64 { return $_ } |
12 | 13 | ||
@@ -22,21 +23,82 @@ IOS (tm) Catalyst 4000 "L3" Switch Software (cat4000-I9K91S-M), Version | |||
22 | Technical Support: http://www.cisco.com/techsupport | 23 | Technical Support: http://www.cisco.com/techsupport |
23 | Copyright (c) 1986-2004 by cisco Systems, Inc. | 24 | Copyright (c) 1986-2004 by cisco Systems, Inc. |
24 | '; | 25 | '; |
25 | my $multilin2 = "Kisco Outernetwork Oserating Gystem Totware | 26 | my $multiline2 = "Kisco Outernetwork Oserating Gystem Totware |
26 | Copyleft (c) 2400-2689 by kisco Systrems, Inc."; | 27 | Copyleft (c) 2400-2689 by kisco Systrems, Inc."; |
27 | my $multilin3 = 'This should not confuse check_snmp "parser" | 28 | my $multiline3 = 'This should not confuse check_snmp "parser" |
28 | into thinking there is no 2nd line'; | 29 | into thinking there is no 2nd line'; |
29 | my $multilin4 = 'It\'s getting even harder if the line | 30 | my $multiline4 = 'It\'s getting even harder if the line |
30 | ends with with this: C:\\'; | 31 | ends with with this: C:\\'; |
31 | my $multilin5 = 'And now have fun with with this: "C:\\" | 32 | my $multiline5 = 'And now have fun with with this: "C:\\" |
32 | because we\'re not done yet!'; | 33 | because we\'re not done yet!'; |
33 | 34 | ||
34 | # Next are arrays of indexes (Type, initial value and increments) | 35 | # Next are arrays of indexes (Type, initial value and increments) |
35 | # 0..19 <---- please update comment when adding/removing fields | 36 | # 0..19 <---- please update comment when adding/removing fields |
36 | my @fields = (ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_UNSIGNED, ASN_UNSIGNED, ASN_COUNTER, ASN_COUNTER64, ASN_UNSIGNED, ASN_COUNTER, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_INTEGER, ASN_OCTET_STR, ASN_OCTET_STR, ASN_INTEGER ); | 37 | my @fields = (ASN_OCTET_STR, # 0 |
37 | my @values = ($multiline, $multilin2, $multilin3, $multilin4, $multilin5, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32)), 64000, "stringtests", "3.5", "87.4startswithnumberbutshouldbestring", '555"I said"', 'CUSTOM CHECK OK: foo is 12345', -2, '-4', '-6.6', 42 ); | 38 | ASN_OCTET_STR, # 1 |
39 | ASN_OCTET_STR, # 2 | ||
40 | ASN_OCTET_STR, # 3 | ||
41 | ASN_OCTET_STR, # 4 | ||
42 | ASN_UNSIGNED, # 5 | ||
43 | ASN_UNSIGNED, # 6 | ||
44 | ASN_COUNTER, # 7 | ||
45 | ASN_COUNTER64, # 8 | ||
46 | ASN_UNSIGNED, # 9 | ||
47 | ASN_COUNTER, # 10 | ||
48 | ASN_OCTET_STR, # 11 | ||
49 | ASN_OCTET_STR, # 12 | ||
50 | ASN_OCTET_STR, # 13 | ||
51 | ASN_OCTET_STR, # 14 | ||
52 | ASN_OCTET_STR, # 15 | ||
53 | ASN_INTEGER, # 16 | ||
54 | ASN_INTEGER, # 17 | ||
55 | ASN_FLOAT, # 18 | ||
56 | ASN_INTEGER # 19 | ||
57 | ); | ||
58 | my @values = ($multiline, # 0 | ||
59 | $multiline2, # 1 | ||
60 | $multiline3, # 2 | ||
61 | $multiline4, # 3 | ||
62 | $multiline5, # 4 | ||
63 | 4294965296, # 5 | ||
64 | 1000, # 6 | ||
65 | 4294965296, # 7 | ||
66 | uint64("18446744073709351616"), # 8 | ||
67 | int(rand(2**32)), # 9 | ||
68 | 64000, # 10 | ||
69 | "stringtests", # 11 | ||
70 | "3.5", # 12 | ||
71 | "87.4startswithnumberbutshouldbestring", # 13 | ||
72 | '555"I said"', # 14 | ||
73 | 'CUSTOM CHECK OK: foo is 12345', # 15 | ||
74 | '-2', # 16 | ||
75 | '-4', # 17 | ||
76 | '-6.6', # 18 | ||
77 | 42 # 19 | ||
78 | ); | ||
38 | # undef increments are randomized | 79 | # undef increments are randomized |
39 | my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666, undef, undef, undef, undef, undef, -1, undef, undef, 0 ); | 80 | my @incrts = ( |
81 | undef, # 0 | ||
82 | undef, # 1 | ||
83 | undef, # 2 | ||
84 | undef, # 3 | ||
85 | undef, # 4 | ||
86 | 1000, # 5 | ||
87 | -500, # 6 | ||
88 | 1000, # 7 | ||
89 | 100000, # 8 | ||
90 | undef, # 9 | ||
91 | 666, # 10 | ||
92 | undef, # 11 | ||
93 | undef, # 12 | ||
94 | undef, # 13 | ||
95 | undef, # 14 | ||
96 | undef, # 15 | ||
97 | -1, # 16 | ||
98 | 0, # 17 | ||
99 | undef, # 18 | ||
100 | 0 # 19 | ||
101 | ); | ||
40 | 102 | ||
41 | # Number of elements in our OID | 103 | # Number of elements in our OID |
42 | my $oidelts; | 104 | my $oidelts; |
diff --git a/plugins/tests/conf/snmpd.conf b/plugins/tests/conf/snmpd.conf index eff5b0b3..1724c027 100644 --- a/plugins/tests/conf/snmpd.conf +++ b/plugins/tests/conf/snmpd.conf | |||
@@ -19,5 +19,5 @@ syscontact Alice | |||
19 | # Embedded Subagents | 19 | # Embedded Subagents |
20 | ############################################################################### | 20 | ############################################################################### |
21 | 21 | ||
22 | perl do "tests/check_snmp_agent.pl"; | 22 | perl do "./tests/check_snmp_agent.pl"; |
23 | 23 | ||
diff --git a/plugins/tests/test_check_disk.c b/plugins/tests/test_check_disk.c new file mode 100644 index 00000000..32b46c2d --- /dev/null +++ b/plugins/tests/test_check_disk.c | |||
@@ -0,0 +1,213 @@ | |||
1 | /***************************************************************************** | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | * | ||
16 | * | ||
17 | *****************************************************************************/ | ||
18 | |||
19 | #include "common.h" | ||
20 | #include "../check_disk.d/utils_disk.h" | ||
21 | #include "../../tap/tap.h" | ||
22 | #include "regex.h" | ||
23 | |||
24 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, | ||
25 | int expect, char *desc); | ||
26 | |||
27 | int main(int argc, char **argv) { | ||
28 | plan_tests(35); | ||
29 | |||
30 | struct name_list *exclude_filesystem = NULL; | ||
31 | ok(np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); | ||
32 | np_add_name(&exclude_filesystem, "/var/log"); | ||
33 | ok(np_find_name(exclude_filesystem, "/var/log") == true, "is in list now"); | ||
34 | ok(np_find_name(exclude_filesystem, "/home") == false, "/home not in list"); | ||
35 | np_add_name(&exclude_filesystem, "/home"); | ||
36 | ok(np_find_name(exclude_filesystem, "/home") == true, "is in list now"); | ||
37 | ok(np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list"); | ||
38 | |||
39 | struct name_list *exclude_fstype = NULL; | ||
40 | ok(np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list"); | ||
41 | np_add_name(&exclude_fstype, "iso9660"); | ||
42 | ok(np_find_name(exclude_fstype, "iso9660") == true, "is in list now"); | ||
43 | |||
44 | ok(np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables"); | ||
45 | |||
46 | /* | ||
47 | for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { | ||
48 | printf("Name: %s\n", temp_name->name); | ||
49 | } | ||
50 | */ | ||
51 | |||
52 | struct mount_entry *dummy_mount_list; | ||
53 | struct mount_entry **mtail = &dummy_mount_list; | ||
54 | struct mount_entry *me = (struct mount_entry *)malloc(sizeof *me); | ||
55 | me->me_devname = strdup("/dev/c0t0d0s0"); | ||
56 | me->me_mountdir = strdup("/"); | ||
57 | *mtail = me; | ||
58 | mtail = &me->me_next; | ||
59 | |||
60 | me = (struct mount_entry *)malloc(sizeof *me); | ||
61 | me->me_devname = strdup("/dev/c1t0d1s0"); | ||
62 | me->me_mountdir = strdup("/var"); | ||
63 | *mtail = me; | ||
64 | mtail = &me->me_next; | ||
65 | |||
66 | me = (struct mount_entry *)malloc(sizeof *me); | ||
67 | me->me_devname = strdup("/dev/c2t0d0s0"); | ||
68 | me->me_mountdir = strdup("/home"); | ||
69 | *mtail = me; | ||
70 | mtail = &me->me_next; | ||
71 | |||
72 | int cflags = REG_NOSUB | REG_EXTENDED; | ||
73 | np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a")); | ||
74 | np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, | ||
75 | strdup("regex on dev names:")); | ||
76 | np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, | ||
77 | strdup("regex on non existent dev/path:")); | ||
78 | np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, | ||
79 | strdup("regi on non existent dev/path:")); | ||
80 | np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, | ||
81 | strdup("partial devname regex match:")); | ||
82 | np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, | ||
83 | strdup("partial devname regex match:")); | ||
84 | np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, | ||
85 | strdup("partial devname regi match:")); | ||
86 | np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, | ||
87 | strdup("partial pathname regex match:")); | ||
88 | np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, | ||
89 | strdup("partial pathname regi match:")); | ||
90 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, | ||
91 | strdup("grouped regex pathname match:")); | ||
92 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, | ||
93 | strdup("grouped regi pathname match:")); | ||
94 | |||
95 | filesystem_list test_paths = filesystem_list_init(); | ||
96 | mp_int_fs_list_append(&test_paths, "/home/groups"); | ||
97 | mp_int_fs_list_append(&test_paths, "/var"); | ||
98 | mp_int_fs_list_append(&test_paths, "/tmp"); | ||
99 | mp_int_fs_list_append(&test_paths, "/home/tonvoon"); | ||
100 | mp_int_fs_list_append(&test_paths, "/dev/c2t0d0s0"); | ||
101 | ok(test_paths.length == 5, "List counter works correctly with appends"); | ||
102 | |||
103 | mp_int_fs_list_set_best_match(test_paths, dummy_mount_list, false); | ||
104 | for (parameter_list_elem *p = test_paths.first; p; p = mp_int_fs_list_get_next(p)) { | ||
105 | struct mount_entry *temp_me; | ||
106 | temp_me = p->best_match; | ||
107 | if (!strcmp(p->name, "/home/groups")) { | ||
108 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), | ||
109 | "/home/groups got right best match: /home"); | ||
110 | } else if (!strcmp(p->name, "/var")) { | ||
111 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); | ||
112 | } else if (!strcmp(p->name, "/tmp")) { | ||
113 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); | ||
114 | } else if (!strcmp(p->name, "/home/tonvoon")) { | ||
115 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), | ||
116 | "/home/tonvoon got right best match: /home"); | ||
117 | } else if (!strcmp(p->name, "/dev/c2t0d0s0")) { | ||
118 | ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), | ||
119 | "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | for (parameter_list_elem *p = test_paths.first; p; p = mp_int_fs_list_get_next(p)) { | ||
124 | mp_int_fs_list_del(&test_paths, p); | ||
125 | } | ||
126 | ok(test_paths.length == 0, "List delete sets counter properly"); | ||
127 | |||
128 | mp_int_fs_list_append(&test_paths, "/home/groups"); | ||
129 | mp_int_fs_list_append(&test_paths, "/var"); | ||
130 | mp_int_fs_list_append(&test_paths, "/tmp"); | ||
131 | mp_int_fs_list_append(&test_paths, "/home/tonvoon"); | ||
132 | mp_int_fs_list_append(&test_paths, "/home"); | ||
133 | |||
134 | mp_int_fs_list_set_best_match(test_paths, dummy_mount_list, true); | ||
135 | for (parameter_list_elem *p = test_paths.first; p; p = mp_int_fs_list_get_next(p)) { | ||
136 | if (!strcmp(p->name, "/home/groups")) { | ||
137 | ok(!p->best_match, "/home/groups correctly not found"); | ||
138 | } else if (!strcmp(p->name, "/var")) { | ||
139 | ok(p->best_match, "/var found"); | ||
140 | } else if (!strcmp(p->name, "/tmp")) { | ||
141 | ok(!p->best_match, "/tmp correctly not found"); | ||
142 | } else if (!strcmp(p->name, "/home/tonvoon")) { | ||
143 | ok(!p->best_match, "/home/tonvoon not found"); | ||
144 | } else if (!strcmp(p->name, "/home")) { | ||
145 | ok(p->best_match, "/home found"); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | bool found = false; | ||
150 | /* test deleting first element in paths */ | ||
151 | mp_int_fs_list_del(&test_paths, NULL); | ||
152 | for (parameter_list_elem *p = test_paths.first; p; p = mp_int_fs_list_get_next(p)) { | ||
153 | if (!strcmp(p->name, "/home/groups")) { | ||
154 | found = true; | ||
155 | } | ||
156 | } | ||
157 | ok(!found, "first element successfully deleted"); | ||
158 | found = false; | ||
159 | |||
160 | parameter_list_elem *prev = NULL; | ||
161 | parameter_list_elem *p = NULL; | ||
162 | for (parameter_list_elem *path = test_paths.first; path; path = mp_int_fs_list_get_next(path)) { | ||
163 | if (!strcmp(path->name, "/tmp")) { | ||
164 | mp_int_fs_list_del(&test_paths, path); | ||
165 | } | ||
166 | p = path; | ||
167 | } | ||
168 | |||
169 | parameter_list_elem *last = NULL; | ||
170 | for (parameter_list_elem *path = test_paths.first; path; path = mp_int_fs_list_get_next(path)) { | ||
171 | if (!strcmp(path->name, "/tmp")) { | ||
172 | found = true; | ||
173 | } | ||
174 | if (path->next) { | ||
175 | prev = path; | ||
176 | } else { | ||
177 | last = path; | ||
178 | } | ||
179 | } | ||
180 | ok(!found, "/tmp element successfully deleted"); | ||
181 | |||
182 | int count = 0; | ||
183 | mp_int_fs_list_del(&test_paths, p); | ||
184 | for (p = test_paths.first; p; p = p->next) { | ||
185 | if (!strcmp(p->name, "/home")) { | ||
186 | found = true; | ||
187 | } | ||
188 | last = p; | ||
189 | count++; | ||
190 | } | ||
191 | ok(!found, "last (/home) element successfully deleted"); | ||
192 | ok(count == 2, "two elements remaining"); | ||
193 | |||
194 | return exit_status(); | ||
195 | } | ||
196 | |||
197 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, | ||
198 | int expect, char *desc) { | ||
199 | regex_t regex; | ||
200 | if (regcomp(®ex, regstr, cflags) == 0) { | ||
201 | int matches = 0; | ||
202 | for (struct mount_entry *me = dummy_mount_list; me; me = me->me_next) { | ||
203 | if (np_regex_match_mount_entry(me, ®ex)) { | ||
204 | matches++; | ||
205 | } | ||
206 | } | ||
207 | ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, | ||
208 | matches); | ||
209 | |||
210 | } else { | ||
211 | ok(false, "regex '%s' not compilable", regstr); | ||
212 | } | ||
213 | } | ||
diff --git a/plugins/tests/test_check_disk.t b/plugins/tests/test_check_disk.t new file mode 100755 index 00000000..56354650 --- /dev/null +++ b/plugins/tests/test_check_disk.t | |||
@@ -0,0 +1,6 @@ | |||
1 | #!/usr/bin/perl | ||
2 | use Test::More; | ||
3 | if (! -e "./test_check_disk") { | ||
4 | plan skip_all => "./test_check_disk not compiled - please enable libtap library to test"; | ||
5 | } | ||
6 | exec "./test_check_disk"; | ||
diff --git a/plugins/tests/test_check_snmp.c b/plugins/tests/test_check_snmp.c new file mode 100644 index 00000000..d71706d0 --- /dev/null +++ b/plugins/tests/test_check_snmp.c | |||
@@ -0,0 +1,175 @@ | |||
1 | /***************************************************************************** | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | * | ||
16 | * | ||
17 | *****************************************************************************/ | ||
18 | |||
19 | #include "tap.h" | ||
20 | #include "../../config.h" | ||
21 | |||
22 | #include <unistd.h> | ||
23 | #include <sys/types.h> | ||
24 | #include <sys/stat.h> | ||
25 | |||
26 | #include "utils_base.c" | ||
27 | #include "../check_snmp.d/check_snmp_helpers.h" | ||
28 | |||
29 | char *_np_state_generate_key(int argc, char **argv); | ||
30 | char *_np_state_calculate_location_prefix(void); | ||
31 | |||
32 | int main(int argc, char **argv) { | ||
33 | char *temp_string = (char *)_np_state_generate_key(argc, argv); | ||
34 | ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), | ||
35 | "Got hash with exe and no parameters") || | ||
36 | diag("You are probably running in wrong directory. Must run as ./test_utils"); | ||
37 | |||
38 | int fake_argc = 4; | ||
39 | char *fake_argv[] = { | ||
40 | "./test_utils", | ||
41 | "here", | ||
42 | "--and", | ||
43 | "now", | ||
44 | }; | ||
45 | temp_string = (char *)_np_state_generate_key(fake_argc, fake_argv); | ||
46 | ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), | ||
47 | "Got based on expected argv"); | ||
48 | |||
49 | unsetenv("MP_STATE_PATH"); | ||
50 | temp_string = (char *)_np_state_calculate_location_prefix(); | ||
51 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory"); | ||
52 | |||
53 | setenv("MP_STATE_PATH", "", 1); | ||
54 | temp_string = (char *)_np_state_calculate_location_prefix(); | ||
55 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string"); | ||
56 | |||
57 | setenv("MP_STATE_PATH", "/usr/local/nagios/var", 1); | ||
58 | temp_string = (char *)_np_state_calculate_location_prefix(); | ||
59 | ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory"); | ||
60 | |||
61 | fake_argc = 1; | ||
62 | fake_argv[0] = "./test_utils"; | ||
63 | state_key temp_state_key1 = np_enable_state(NULL, 51, "check_test", fake_argc, fake_argv); | ||
64 | ok(!strcmp(temp_state_key1.plugin_name, "check_test"), "Got plugin name"); | ||
65 | ok(!strcmp(temp_state_key1.name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), | ||
66 | "Got generated filename"); | ||
67 | |||
68 | state_key temp_state_key2 = | ||
69 | np_enable_state("allowedchars_in_keyname", 77, "check_snmp", fake_argc, fake_argv); | ||
70 | |||
71 | char state_path[1024]; | ||
72 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/allowedchars_in_keyname", | ||
73 | (unsigned long)geteuid()); | ||
74 | ok(!strcmp(temp_state_key2.plugin_name, "check_test"), "Got plugin name"); | ||
75 | ok(!strcmp(temp_state_key2.name, "allowedchars_in_keyname"), "Got key name with valid chars"); | ||
76 | ok(!strcmp(temp_state_key2._filename, state_path), "Got internal filename"); | ||
77 | |||
78 | /* Don't do this test just yet. Will die */ | ||
79 | /* | ||
80 | np_enable_state("bad^chars$in@here", 77); | ||
81 | temp_state_key = this_monitoring_plugin->state; | ||
82 | ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" | ||
83 | ); | ||
84 | */ | ||
85 | |||
86 | state_key temp_state_key3 = | ||
87 | np_enable_state("funnykeyname", 54, "check_snmp", fake_argc, fake_argv); | ||
88 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/funnykeyname", | ||
89 | (unsigned long)geteuid()); | ||
90 | ok(!strcmp(temp_state_key3.plugin_name, "check_test"), "Got plugin name"); | ||
91 | ok(!strcmp(temp_state_key3.name, "funnykeyname"), "Got key name"); | ||
92 | |||
93 | ok(!strcmp(temp_state_key3._filename, state_path), "Got internal filename"); | ||
94 | ok(temp_state_key3.data_version == 54, "Version set"); | ||
95 | |||
96 | state_data *temp_state_data = np_state_read(temp_state_key3); | ||
97 | ok(temp_state_data == NULL, "Got no state data as file does not exist"); | ||
98 | |||
99 | /* | ||
100 | temp_fp = fopen("var/statefile", "r"); | ||
101 | if (temp_fp==NULL) | ||
102 | printf("Error opening. errno=%d\n", errno); | ||
103 | printf("temp_fp=%s\n", temp_fp); | ||
104 | ok( _np_state_read_file(temp_fp) == true, "Can read state file" ); | ||
105 | fclose(temp_fp); | ||
106 | */ | ||
107 | |||
108 | temp_state_key3._filename = "var/statefile"; | ||
109 | temp_state_data = np_state_read(temp_state_key3); | ||
110 | ok(temp_state_data != NULL, "Got state data now") || | ||
111 | diag("Are you running in right directory? Will get coredump next if not"); | ||
112 | ok(temp_state_data->time == 1234567890, "Got time"); | ||
113 | ok(!strcmp((char *)temp_state_data->data, "String to read"), "Data as expected"); | ||
114 | |||
115 | temp_state_key3.data_version = 53; | ||
116 | temp_state_data = np_state_read(temp_state_key3); | ||
117 | ok(temp_state_data == NULL, "Older data version gives NULL"); | ||
118 | temp_state_key3.data_version = 54; | ||
119 | |||
120 | temp_state_key3._filename = "var/nonexistent"; | ||
121 | temp_state_data = np_state_read(temp_state_key3); | ||
122 | ok(temp_state_data == NULL, "Missing file gives NULL"); | ||
123 | |||
124 | temp_state_key3._filename = "var/oldformat"; | ||
125 | temp_state_data = np_state_read(temp_state_key3); | ||
126 | ok(temp_state_data == NULL, "Old file format gives NULL"); | ||
127 | |||
128 | temp_state_key3._filename = "var/baddate"; | ||
129 | temp_state_data = np_state_read(temp_state_key3); | ||
130 | ok(temp_state_data == NULL, "Bad date gives NULL"); | ||
131 | |||
132 | temp_state_key3._filename = "var/missingdataline"; | ||
133 | temp_state_data = np_state_read(temp_state_key3); | ||
134 | ok(temp_state_data == NULL, "Missing data line gives NULL"); | ||
135 | |||
136 | unlink("var/generated"); | ||
137 | temp_state_key3._filename = "var/generated"; | ||
138 | |||
139 | time_t current_time = 1234567890; | ||
140 | np_state_write_string(temp_state_key3, current_time, "String to read"); | ||
141 | ok(system("cmp var/generated var/statefile") == 0, "Generated file same as expected"); | ||
142 | |||
143 | unlink("var/generated_directory/statefile"); | ||
144 | unlink("var/generated_directory"); | ||
145 | temp_state_key3._filename = "var/generated_directory/statefile"; | ||
146 | current_time = 1234567890; | ||
147 | np_state_write_string(temp_state_key3, current_time, "String to read"); | ||
148 | ok(system("cmp var/generated_directory/statefile var/statefile") == 0, | ||
149 | "Have created directory"); | ||
150 | |||
151 | /* This test to check cannot write to dir - can't automate yet */ | ||
152 | /* | ||
153 | unlink("var/generated_bad_dir"); | ||
154 | mkdir("var/generated_bad_dir", S_IRUSR); | ||
155 | np_state_write_string(current_time, "String to read"); | ||
156 | */ | ||
157 | |||
158 | temp_state_key3._filename = "var/generated"; | ||
159 | time(¤t_time); | ||
160 | np_state_write_string(temp_state_key3, 0, "String to read"); | ||
161 | temp_state_data = np_state_read(temp_state_key3); | ||
162 | /* Check time is set to current_time */ | ||
163 | ok(system("cmp var/generated var/statefile > /dev/null") != 0, | ||
164 | "Generated file should be different this time"); | ||
165 | ok(temp_state_data->time - current_time <= 1, "Has time generated from current time"); | ||
166 | |||
167 | /* Don't know how to automatically test this. Need to be able to redefine die and catch the | ||
168 | * error */ | ||
169 | /* | ||
170 | temp_state_key->_filename="/dev/do/not/expect/to/be/able/to/write"; | ||
171 | np_state_write_string(0, "Bad file"); | ||
172 | */ | ||
173 | |||
174 | np_cleanup(); | ||
175 | } | ||
diff --git a/plugins/tests/test_check_snmp.t b/plugins/tests/test_check_snmp.t new file mode 100755 index 00000000..967633e9 --- /dev/null +++ b/plugins/tests/test_check_snmp.t | |||
@@ -0,0 +1,6 @@ | |||
1 | #!/usr/bin/perl | ||
2 | use Test::More; | ||
3 | if (! -e "./test_check_snmp") { | ||
4 | plan skip_all => "./test_check_snmp not compiled - please enable libtap library to test"; | ||
5 | } | ||
6 | exec "./test_check_snmp"; | ||
diff --git a/plugins/tests/test_check_swap.c b/plugins/tests/test_check_swap.c new file mode 100644 index 00000000..94d56ce7 --- /dev/null +++ b/plugins/tests/test_check_swap.c | |||
@@ -0,0 +1,21 @@ | |||
1 | |||
2 | #include "../check_swap.d/check_swap.h" | ||
3 | #include "../../tap/tap.h" | ||
4 | |||
5 | int verbose = 0; | ||
6 | |||
7 | void print_usage(void) {} | ||
8 | void print_help(swap_config config) { (void)config; } | ||
9 | |||
10 | const char *progname = "test_check_swap"; | ||
11 | |||
12 | int main(void) { | ||
13 | swap_result test_data = getSwapFromProcMeminfo("./var/proc_meminfo"); | ||
14 | |||
15 | plan_tests(4); | ||
16 | |||
17 | ok(test_data.errorcode == 0, "Test whether we manage to retrieve swap data"); | ||
18 | ok(test_data.metrics.total == 34233905152, "Is the total Swap correct"); | ||
19 | ok(test_data.metrics.free == 34233905152, "Is the free Swap correct"); | ||
20 | ok(test_data.metrics.used == 0, "Is the used Swap correct"); | ||
21 | } | ||
diff --git a/plugins/tests/test_check_swap.t b/plugins/tests/test_check_swap.t new file mode 100755 index 00000000..826fae01 --- /dev/null +++ b/plugins/tests/test_check_swap.t | |||
@@ -0,0 +1,6 @@ | |||
1 | #!/usr/bin/perl | ||
2 | use Test::More; | ||
3 | if (! -e "./test_check_swap") { | ||
4 | plan skip_all => "./test_check_swap not compiled - please enable libtap library to test"; | ||
5 | } | ||
6 | exec "./test_check_swap"; | ||
diff --git a/plugins/tests/var/proc_meminfo b/plugins/tests/var/proc_meminfo new file mode 100644 index 00000000..6c5a618d --- /dev/null +++ b/plugins/tests/var/proc_meminfo | |||
@@ -0,0 +1,55 @@ | |||
1 | MemTotal: 32767776 kB | ||
2 | MemFree: 1693508 kB | ||
3 | MemAvailable: 23807480 kB | ||
4 | Buffers: 438456 kB | ||
5 | Cached: 19124976 kB | ||
6 | SwapCached: 0 kB | ||
7 | Active: 7860680 kB | ||
8 | Inactive: 18886776 kB | ||
9 | Active(anon): 6108756 kB | ||
10 | Inactive(anon): 1364500 kB | ||
11 | Active(file): 1751924 kB | ||
12 | Inactive(file): 17522276 kB | ||
13 | Unevictable: 8548 kB | ||
14 | Mlocked: 8548 kB | ||
15 | SwapTotal: 33431548 kB | ||
16 | SwapFree: 33431548 kB | ||
17 | Zswap: 0 kB | ||
18 | Zswapped: 0 kB | ||
19 | Dirty: 784 kB | ||
20 | Writeback: 0 kB | ||
21 | AnonPages: 7139968 kB | ||
22 | Mapped: 1094916 kB | ||
23 | Shmem: 284160 kB | ||
24 | KReclaimable: 3303788 kB | ||
25 | Slab: 3801908 kB | ||
26 | SReclaimable: 3303788 kB | ||
27 | SUnreclaim: 498120 kB | ||
28 | KernelStack: 32992 kB | ||
29 | PageTables: 68160 kB | ||
30 | SecPageTables: 0 kB | ||
31 | NFS_Unstable: 0 kB | ||
32 | Bounce: 0 kB | ||
33 | WritebackTmp: 0 kB | ||
34 | CommitLimit: 49815436 kB | ||
35 | Committed_AS: 16888536 kB | ||
36 | VmallocTotal: 34359738367 kB | ||
37 | VmallocUsed: 91200 kB | ||
38 | VmallocChunk: 0 kB | ||
39 | Percpu: 41472 kB | ||
40 | HardwareCorrupted: 0 kB | ||
41 | AnonHugePages: 1708032 kB | ||
42 | ShmemHugePages: 0 kB | ||
43 | ShmemPmdMapped: 0 kB | ||
44 | FileHugePages: 0 kB | ||
45 | FilePmdMapped: 0 kB | ||
46 | Unaccepted: 0 kB | ||
47 | HugePages_Total: 0 | ||
48 | HugePages_Free: 0 | ||
49 | HugePages_Rsvd: 0 | ||
50 | HugePages_Surp: 0 | ||
51 | Hugepagesize: 2048 kB | ||
52 | Hugetlb: 0 kB | ||
53 | DirectMap4k: 860468 kB | ||
54 | DirectMap2M: 20023296 kB | ||
55 | DirectMap1G: 12582912 kB | ||