diff options
Diffstat (limited to 'plugins/tests/check_snmp.t')
-rwxr-xr-x | plugins/tests/check_snmp.t | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index 85d6bf5..bfe42e1 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 = 67; | 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; |
@@ -53,13 +53,13 @@ if ($pid) { | |||
53 | #print "child\n"; | 53 | #print "child\n"; |
54 | 54 | ||
55 | print "Please contact SNMP at: $port_snmp\n"; | 55 | print "Please contact SNMP at: $port_snmp\n"; |
56 | close(STDERR); # Coment out to debug snmpd problems (most errors sent there are OK) | 56 | close(STDERR); # Comment out to debug snmpd problems (most errors sent there are OK) |
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 | ||
@@ -227,7 +227,7 @@ is($res->output, 'SNMP OK - "555\"I said\"" | ', "Check string with a double quo | |||
227 | 227 | ||
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'" ); | 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'" ); |
229 | is($res->return_code, 0, "String check should check whole string, not a parsed number" ); | 229 | 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 witn numbers returns whole string"); | 230 | is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check with numbers returns whole string"); |
231 | 231 | ||
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:" ); | 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:" ); |
233 | is($res->return_code, 0, "Negative integer check OK" ); | 233 | is($res->return_code, 0, "Negative integer check OK" ); |
@@ -251,9 +251,36 @@ is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3: | |||
251 | 251 | ||
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'" ); | 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'" ); |
253 | is($res->return_code, 0, "Negative float OK" ); | 253 | is($res->return_code, 0, "Negative float OK" ); |
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" ); | 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" ); |
255 | 255 | ||
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'" ); | 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'" ); |
257 | is($res->return_code, 1, "Negative float WARNING" ); | 257 | 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" ); | 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" ); |
259 | 259 | ||
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'" ); | ||
261 | 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" ); | ||
263 | |||
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'" ); | ||
265 | 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" ); | ||
267 | |||
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" ); | ||
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" ); | ||