diff options
Diffstat (limited to 'plugins/tests')
-rwxr-xr-x | plugins/tests/check_curl.t | 21 | ||||
-rwxr-xr-x | plugins/tests/check_http.t | 85 | ||||
-rwxr-xr-x | plugins/tests/check_procs.t | 8 | ||||
-rwxr-xr-x | plugins/tests/check_snmp.t | 22 | ||||
-rw-r--r-- | plugins/tests/check_snmp_agent.pl | 8 |
5 files changed, 130 insertions, 14 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index aa72ef6..72f2b7c 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t | |||
@@ -21,7 +21,7 @@ use FindBin qw($Bin); | |||
21 | 21 | ||
22 | $ENV{'LC_TIME'} = "C"; | 22 | $ENV{'LC_TIME'} = "C"; |
23 | 23 | ||
24 | my $common_tests = 72; | 24 | my $common_tests = 73; |
25 | my $ssl_only_tests = 8; | 25 | my $ssl_only_tests = 8; |
26 | # Check that all dependent modules are available | 26 | # Check that all dependent modules are available |
27 | eval "use HTTP::Daemon 6.01;"; | 27 | eval "use HTTP::Daemon 6.01;"; |
@@ -200,6 +200,14 @@ sub run_server { | |||
200 | $c->send_basic_header; | 200 | $c->send_basic_header; |
201 | $c->send_crlf; | 201 | $c->send_crlf; |
202 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); | 202 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); |
203 | } elsif ($r->url->path eq "/chunked") { | ||
204 | my $chunks = ["chunked", "encoding", "test\n"]; | ||
205 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, sub { | ||
206 | my $chunk = shift @{$chunks}; | ||
207 | return unless $chunk; | ||
208 | sleep(1); | ||
209 | return($chunk); | ||
210 | })); | ||
203 | } else { | 211 | } else { |
204 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | 212 | $c->send_error(HTTP::Status->RC_FORBIDDEN); |
205 | } | 213 | } |
@@ -472,7 +480,8 @@ sub run_common_tests { | |||
472 | local $SIG{ALRM} = sub { die "alarm\n" }; | 480 | local $SIG{ALRM} = sub { die "alarm\n" }; |
473 | alarm(2); | 481 | alarm(2); |
474 | $result = NPTest->testCmd( $cmd ); | 482 | $result = NPTest->testCmd( $cmd ); |
475 | alarm(0); }; | 483 | }; |
484 | alarm(0); | ||
476 | isnt( $@, "alarm\n", $cmd ); | 485 | isnt( $@, "alarm\n", $cmd ); |
477 | is( $result->return_code, 0, $cmd ); | 486 | is( $result->return_code, 0, $cmd ); |
478 | 487 | ||
@@ -482,7 +491,8 @@ sub run_common_tests { | |||
482 | local $SIG{ALRM} = sub { die "alarm\n" }; | 491 | local $SIG{ALRM} = sub { die "alarm\n" }; |
483 | alarm(2); | 492 | alarm(2); |
484 | $result = NPTest->testCmd( $cmd ); | 493 | $result = NPTest->testCmd( $cmd ); |
485 | alarm(0); }; | 494 | }; |
495 | alarm(0); | ||
486 | isnt( $@, "alarm\n", $cmd ); | 496 | isnt( $@, "alarm\n", $cmd ); |
487 | isnt( $result->return_code, 0, $cmd ); | 497 | isnt( $result->return_code, 0, $cmd ); |
488 | 498 | ||
@@ -508,4 +518,9 @@ sub run_common_tests { | |||
508 | }; | 518 | }; |
509 | is( $@, "", $cmd ); | 519 | is( $@, "", $cmd ); |
510 | 520 | ||
521 | $cmd = "$command -u /chunked -s 'chunkedencodingtest' -d 'Transfer-Encoding: chunked'"; | ||
522 | eval { | ||
523 | $result = NPTest->testCmd( $cmd, 5 ); | ||
524 | }; | ||
525 | is( $@, "", $cmd ); | ||
511 | } | 526 | } |
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index ea11b2a..6078b27 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -9,12 +9,14 @@ use strict; | |||
9 | use Test::More; | 9 | use Test::More; |
10 | use NPTest; | 10 | use NPTest; |
11 | use FindBin qw($Bin); | 11 | use FindBin qw($Bin); |
12 | use IO::Socket::INET; | ||
12 | 13 | ||
13 | $ENV{'LC_TIME'} = "C"; | 14 | $ENV{'LC_TIME'} = "C"; |
14 | 15 | ||
15 | my $common_tests = 70; | 16 | my $common_tests = 71; |
16 | my $virtual_port_tests = 8; | 17 | my $virtual_port_tests = 8; |
17 | my $ssl_only_tests = 12; | 18 | my $ssl_only_tests = 12; |
19 | my $chunked_encoding_special_tests = 1; | ||
18 | # Check that all dependent modules are available | 20 | # Check that all dependent modules are available |
19 | eval "use HTTP::Daemon 6.01;"; | 21 | eval "use HTTP::Daemon 6.01;"; |
20 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; | 22 | plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@; |
@@ -30,7 +32,7 @@ if ($@) { | |||
30 | plan skip_all => "Missing required module for test: $@"; | 32 | plan skip_all => "Missing required module for test: $@"; |
31 | } else { | 33 | } else { |
32 | if (-x "./$plugin") { | 34 | if (-x "./$plugin") { |
33 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests; | 35 | plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests + $chunked_encoding_special_tests; |
34 | } else { | 36 | } else { |
35 | plan skip_all => "No $plugin compiled"; | 37 | plan skip_all => "No $plugin compiled"; |
36 | } | 38 | } |
@@ -51,6 +53,7 @@ my $port_http = 50000 + int(rand(1000)); | |||
51 | my $port_https = $port_http + 1; | 53 | my $port_https = $port_http + 1; |
52 | my $port_https_expired = $port_http + 2; | 54 | my $port_https_expired = $port_http + 2; |
53 | my $port_https_clientcert = $port_http + 3; | 55 | my $port_https_clientcert = $port_http + 3; |
56 | my $port_hacked_http = $port_http + 4; | ||
54 | 57 | ||
55 | # This array keeps sockets around for implementing timeouts | 58 | # This array keeps sockets around for implementing timeouts |
56 | my @persist; | 59 | my @persist; |
@@ -72,6 +75,28 @@ if (!$pid) { | |||
72 | } | 75 | } |
73 | push @pids, $pid; | 76 | push @pids, $pid; |
74 | 77 | ||
78 | # Fork the hacked HTTP server | ||
79 | undef $pid; | ||
80 | $pid = fork; | ||
81 | defined $pid or die "Failed to fork"; | ||
82 | if (!$pid) { | ||
83 | # this is the fork | ||
84 | undef @pids; | ||
85 | my $socket = new IO::Socket::INET ( | ||
86 | LocalHost => '0.0.0.0', | ||
87 | LocalPort => $port_hacked_http, | ||
88 | Proto => 'tcp', | ||
89 | Listen => 5, | ||
90 | Reuse => 1 | ||
91 | ); | ||
92 | die "cannot create socket $!n" unless $socket; | ||
93 | my $local_sock = $socket->sockport(); | ||
94 | print "server waiting for client connection on port $local_sock\n"; | ||
95 | run_hacked_http_server ( $socket ); | ||
96 | die "hacked http server stopped"; | ||
97 | } | ||
98 | push @pids, $pid; | ||
99 | |||
75 | if (exists $servers->{https}) { | 100 | if (exists $servers->{https}) { |
76 | # Fork a normal HTTPS server | 101 | # Fork a normal HTTPS server |
77 | $pid = fork; | 102 | $pid = fork; |
@@ -190,6 +215,14 @@ sub run_server { | |||
190 | $c->send_basic_header; | 215 | $c->send_basic_header; |
191 | $c->send_crlf; | 216 | $c->send_crlf; |
192 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); | 217 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); |
218 | } elsif ($r->url->path eq "/chunked") { | ||
219 | my $chunks = ["chunked", "encoding", "test\n"]; | ||
220 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, sub { | ||
221 | my $chunk = shift @{$chunks}; | ||
222 | return unless $chunk; | ||
223 | sleep(1); | ||
224 | return($chunk); | ||
225 | })); | ||
193 | } else { | 226 | } else { |
194 | $c->send_error(HTTP::Status->RC_FORBIDDEN); | 227 | $c->send_error(HTTP::Status->RC_FORBIDDEN); |
195 | } | 228 | } |
@@ -199,6 +232,37 @@ sub run_server { | |||
199 | } | 232 | } |
200 | } | 233 | } |
201 | 234 | ||
235 | sub run_hacked_http_server { | ||
236 | my $socket = shift; | ||
237 | |||
238 | # auto-flush on socket | ||
239 | $| = 1; | ||
240 | |||
241 | |||
242 | while(1) | ||
243 | { | ||
244 | # waiting for a new client connection | ||
245 | my $client_socket = $socket->accept(); | ||
246 | |||
247 | # get information about a newly connected client | ||
248 | my $client_address = $client_socket->peerhost(); | ||
249 | my $client_portn = $client_socket->peerport(); | ||
250 | print "connection from $client_address:$client_portn"; | ||
251 | |||
252 | # read up to 1024 characters from the connected client | ||
253 | my $data = ""; | ||
254 | $client_socket->recv($data, 1024); | ||
255 | print "received data: $data"; | ||
256 | |||
257 | # write response data to the connected client | ||
258 | $data = "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n"; | ||
259 | $client_socket->send($data); | ||
260 | |||
261 | # notify client that response has been sent | ||
262 | shutdown($client_socket, 1); | ||
263 | } | ||
264 | } | ||
265 | |||
202 | END { | 266 | END { |
203 | foreach my $pid (@pids) { | 267 | foreach my $pid (@pids) { |
204 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } | 268 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } |
@@ -214,6 +278,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
214 | my $result; | 278 | my $result; |
215 | my $command = "./$plugin -H 127.0.0.1"; | 279 | my $command = "./$plugin -H 127.0.0.1"; |
216 | 280 | ||
281 | run_chunked_encoding_special_test( {command => "$command -p $port_hacked_http"}); | ||
217 | run_common_tests( { command => "$command -p $port_http" } ); | 282 | run_common_tests( { command => "$command -p $port_http" } ); |
218 | SKIP: { | 283 | SKIP: { |
219 | skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; | 284 | skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https}; |
@@ -497,4 +562,20 @@ sub run_common_tests { | |||
497 | }; | 562 | }; |
498 | is( $@, "", $cmd ); | 563 | is( $@, "", $cmd ); |
499 | 564 | ||
565 | $cmd = "$command -u /chunked -s 'chunkedencodingtest' -d 'Transfer-Encoding: chunked'"; | ||
566 | eval { | ||
567 | $result = NPTest->testCmd( $cmd, 5 ); | ||
568 | }; | ||
569 | is( $@, "", $cmd ); | ||
570 | } | ||
571 | |||
572 | sub run_chunked_encoding_special_test { | ||
573 | my ($opts) = @_; | ||
574 | my $command = $opts->{command}; | ||
575 | |||
576 | $cmd = "$command -u / -s 'ChunkedEncodingSpecialTest'"; | ||
577 | eval { | ||
578 | $result = NPTest->testCmd( $cmd, 5 ); | ||
579 | }; | ||
580 | is( $@, "", $cmd ); | ||
500 | } | 581 | } |
diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t index 3af218f..b3a0a30 100755 --- a/plugins/tests/check_procs.t +++ b/plugins/tests/check_procs.t | |||
@@ -8,7 +8,7 @@ use Test::More; | |||
8 | use NPTest; | 8 | use NPTest; |
9 | 9 | ||
10 | if (-x "./check_procs") { | 10 | if (-x "./check_procs") { |
11 | plan tests => 52; | 11 | plan tests => 54; |
12 | } else { | 12 | } else { |
13 | plan skip_all => "No check_procs compiled"; | 13 | plan skip_all => "No check_procs compiled"; |
14 | } | 14 | } |
@@ -34,9 +34,13 @@ is( $result->return_code, 0, "Checking no threshold breeched" ); | |||
34 | is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" ); | 34 | is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" ); |
35 | 35 | ||
36 | $result = NPTest->testCmd( "$command -C launchd -c 5" ); | 36 | $result = NPTest->testCmd( "$command -C launchd -c 5" ); |
37 | is( $result->return_code, 2, "Checking processes filtered by command name" ); | 37 | is( $result->return_code, 2, "Checking processes matched by command name" ); |
38 | is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" ); | 38 | is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" ); |
39 | 39 | ||
40 | $result = NPTest->testCmd( "$command -X bash -c 5" ); | ||
41 | is( $result->return_code, 2, "Checking processes excluded by command name" ); | ||
42 | is( $result->output, "PROCS CRITICAL: 95 processes with exclude progs 'bash' | procs=95;;5;0;", "Output correct" ); | ||
43 | |||
40 | SKIP: { | 44 | SKIP: { |
41 | skip 'user with uid 501 required', 4 unless getpwuid(501); | 45 | skip 'user with uid 501 required', 4 unless getpwuid(501); |
42 | 46 | ||
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index 0a77fa8..bc03ec6 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
@@ -9,7 +9,7 @@ use NPTest; | |||
9 | use FindBin qw($Bin); | 9 | use FindBin qw($Bin); |
10 | use POSIX qw/strftime/; | 10 | use POSIX qw/strftime/; |
11 | 11 | ||
12 | my $tests = 73; | 12 | my $tests = 81; |
13 | # Check that all dependent modules are available | 13 | # Check that all dependent modules are available |
14 | eval { | 14 | eval { |
15 | require NetSNMP::OID; | 15 | require NetSNMP::OID; |
@@ -57,9 +57,9 @@ if ($pid) { | |||
57 | exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp"); | 57 | exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp"); |
58 | } | 58 | } |
59 | 59 | ||
60 | END { | 60 | END { |
61 | foreach my $pid (@pids) { | 61 | foreach my $pid (@pids) { |
62 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } | 62 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } |
63 | } | 63 | } |
64 | }; | 64 | }; |
65 | 65 | ||
@@ -268,3 +268,19 @@ like($res->output, '/SNMP WARNING - \d+ \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d | |||
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" ); | 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" ); |
269 | is($res->return_code, 2, "Multiple OIDs with some thresholds" ); | 269 | 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" ); | 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" ); |
271 | |||
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"); | ||
273 | 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" ); | ||
275 | |||
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"); | ||
277 | 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" ); | ||
279 | |||
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' "); | ||
281 | is($res->return_code, 0, "Test multiply RC + format" ); | ||
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" ); | ||
283 | |||
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"); | ||
285 | is($res->return_code, 1, "Test multiply RC + format + 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" ); | ||
diff --git a/plugins/tests/check_snmp_agent.pl b/plugins/tests/check_snmp_agent.pl index 0e41d57..38912e9 100644 --- a/plugins/tests/check_snmp_agent.pl +++ b/plugins/tests/check_snmp_agent.pl | |||
@@ -32,11 +32,11 @@ my $multilin5 = 'And now have fun with with this: "C:\\" | |||
32 | because we\'re not done yet!'; | 32 | because we\'re not done yet!'; |
33 | 33 | ||
34 | # Next are arrays of indexes (Type, initial value and increments) | 34 | # Next are arrays of indexes (Type, initial value and increments) |
35 | # 0..16 <---- please update comment when adding/removing fields | 35 | # 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 ); | 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 @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' ); | 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 | # undef increments are randomized | 38 | # 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 ); | 39 | my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666, undef, undef, undef, undef, undef, -1, undef, undef, 0 ); |
40 | 40 | ||
41 | # Number of elements in our OID | 41 | # Number of elements in our OID |
42 | my $oidelts; | 42 | my $oidelts; |