From 18f6835edaf7d640a2c9e476cb1babdbdadbfd9b Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 17 Jun 2010 10:16:43 +0100 Subject: Added state retention APIs. Implemented for check_snmp with --rate option. See http://nagiosplugin.org/c-api-private for more details on the API. Also updated check_snmp -l option to change the perfdata label. --- plugins/tests/check_snmp.t | 39 ++++++++++++++++++++++++++++++++++++++- plugins/tests/check_snmp_agent.pl | 6 +++--- 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'plugins/tests') diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index b5f3f89e..17420792 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t @@ -51,7 +51,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { } } -my $tests = 9; +my $tests = 21; if (-x "./check_snmp") { plan tests => $tests; } else { @@ -106,3 +106,40 @@ 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/*"); +$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"); + +# 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 -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 "); + +$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" ); +is($res->output, "Time duration between plugin calls is invalid"); + + +$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 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" ); +is($res->return_code, 0, "OK as no thresholds" ); +is($res->output, "SNMP RATE OK - inoctets 666 | inoctets-rate=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"); + + + + diff --git a/plugins/tests/check_snmp_agent.pl b/plugins/tests/check_snmp_agent.pl index 302ba6e7..425caeb3 100644 --- a/plugins/tests/check_snmp_agent.pl +++ b/plugins/tests/check_snmp_agent.pl @@ -33,9 +33,9 @@ ends with with this: C:\\'; my $multilin5 = 'And now have fun with with this: "C:\\" because we\'re not done yet!'; -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); -my @values = ($multiline, $multilin2, $multilin3, $multilin4, $multilin5, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32))); -my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef); +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); +my @values = ($multiline, $multilin2, $multilin3, $multilin4, $multilin5, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32)), 64000); +my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666); # Number of elements in our OID my $oidelts; -- cgit v1.2.3