X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Ftests%2Fcheck_snmp.t;h=b978a8591cc881007209950c1312d7de6eee4f17;hb=c49fed07c3837fb7590bd05d192d6b6f6c4ae5d4;hp=a7a8d2cfc04a2bfe7a5f38ee02e4398cf93f4a13;hpb=b8e2850c1add8031a11d951bec1459b203582299;p=nagiosplug.git diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index a7a8d2c..b978a85 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t @@ -8,6 +8,7 @@ use Test::More; use NPTest; use FindBin qw($Bin); +my $tests = 39; # Check that all dependent modules are available eval { require NetSNMP::OID; @@ -17,6 +18,12 @@ eval { if ($@) { plan skip_all => "Missing required module for test: $@"; +} else { + if (-x "./check_snmp") { + plan tests => $tests; + } else { + plan skip_all => "No check_snmp compiled"; + } } my $port_snmp = 16100 + int(rand(100)); @@ -51,12 +58,8 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { } } -my $tests = 29; -if (-x "./check_snmp") { - plan tests => $tests; -} else { - plan skip_all => "No check_snmp compiled"; -} +# We should merge that with $ENV{'NPTEST_CACHE'}, use one dir for all test data +$ENV{'NAGIOS_PLUGIN_STATE_DIRECTORY'} ||= "/var/tmp"; my $res; @@ -106,7 +109,7 @@ like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C "And now have fun with with this: \"C:\\\\\" because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); -system("rm /usr/local/nagios/var/check_snmp/*"); +system("rm -f ".$ENV{'NAGIOS_PLUGIN_STATE_DIRECTORY'}."/check_snmp/*"); $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 --rate -w 600" ); is($res->return_code, 0, "Returns OK"); is($res->output, "No previous data to calculate rate - assume okay"); @@ -116,7 +119,7 @@ sleep 1; $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 --rate -w 600" ); is($res->return_code, 1, "WARNING - due to going above rate calculation" ); -is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10-rate=666 "); +is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666 "); $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 --rate -w 600" ); is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); @@ -132,13 +135,26 @@ sleep 1; $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 --rate -l inoctets" ); is($res->return_code, 0, "OK as no thresholds" ); -is($res->output, "SNMP RATE OK - inoctets 666 | inoctets-rate=666 ", "Check label"); +is($res->output, "SNMP RATE OK - inoctets 666 | inoctets=666 ", "Check label"); sleep 2; $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 --rate -l inoctets" ); is($res->return_code, 0, "OK as no thresholds" ); -is($res->output, "SNMP RATE OK - inoctets 333 | inoctets-rate=333 ", "Check rate decreases due to longer interval"); +is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); + + + +$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 --rate -l inoctets_per_minute --rate-multiplier=60" ); +is($res->return_code, 0, "OK for first call" ); +is($res->output, "No previous data to calculate rate - assume okay" ); + +# Need to sleep, otherwise duration=0 +sleep 1; + +$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 --rate -l inoctets_per_minute --rate-multiplier=60" ); +is($res->return_code, 0, "OK as no thresholds" ); +is($res->output, "SNMP RATE OK - inoctets_per_minute 39960 | inoctets_per_minute=39960 ", "Checking multiplier"); $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\"'" ); @@ -157,5 +173,16 @@ $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1 is($res->return_code, 0, "OK as string doesn't match but inverted" ); is($res->output, 'SNMP OK - "stringtests" | ', "OK as inverted string no match" ); +$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" ); +is($res->return_code, 1, "Numeric in string test" ); +is($res->output, 'SNMP WARNING - *3.5* | iso.3.6.1.4.1.8072.3.2.67.12=3.5 ', "WARNING threshold checks for string masquerading as number" ); + +$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" ); +is($res->return_code, 0, "Not really numeric test" ); +is($res->output, 'SNMP OK - "87.4startswithnumberbutshouldbestring" | ', "Check string with numeric start is still string" ); + +$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" ); +is($res->return_code, 0, "Not really numeric test (trying best to fool it)" ); +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)" );