From c35bf8966a593d7926470121269b08ec00883593 Mon Sep 17 00:00:00 2001 From: Wolfgang Nieder Date: Sat, 7 Jul 2018 09:12:44 +0200 Subject: add 'multiplier' to modify current value --- plugins/tests/check_snmp.t | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'plugins/tests') diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index 0a77fa8a..e9cc0213 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t @@ -9,7 +9,7 @@ use NPTest; use FindBin qw($Bin); use POSIX qw/strftime/; -my $tests = 73; +my $tests = 75; # Check that all dependent modules are available eval { require NetSNMP::OID; @@ -57,9 +57,9 @@ if ($pid) { exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp"); } -END { +END { foreach my $pid (@pids) { - if ($pid) { print "Killing $pid\n"; kill "INT", $pid } + if ($pid) { print "Killing $pid\n"; kill "INT", $pid } } }; @@ -268,3 +268,9 @@ like($res->output, '/SNMP WARNING - \d+ \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d $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" ); is($res->return_code, 2, "Multiple OIDs with some thresholds" ); 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" ); + +$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.2.1.25.2.2.0 -M .125 "); +is($res->return_code, 0, "Multiply OK" ); + +$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.2.1.25.2.2.0 --multiplier=.0009765625 -f '%.3f' "); +is($res->return_code, 0, "Multiply format OK" ); -- cgit v1.2.3-74-g34f1 From def946bd9792ffff34b865449b18eea6e8f116af Mon Sep 17 00:00:00 2001 From: Robert Bohne Date: Fri, 11 Nov 2022 11:10:44 +0100 Subject: Improve tests for check_snmp & multiply option --- plugins/tests/check_snmp.t | 20 +++++++++++++++----- plugins/tests/check_snmp_agent.pl | 8 ++++---- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'plugins/tests') diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index e9cc0213..bb5b8db6 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t @@ -9,7 +9,7 @@ use NPTest; use FindBin qw($Bin); use POSIX qw/strftime/; -my $tests = 75; +my $tests = 81; # Check that all dependent modules are available eval { require NetSNMP::OID; @@ -269,8 +269,18 @@ $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1 is($res->return_code, 2, "Multiple OIDs with some thresholds" ); 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" ); -$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.2.1.25.2.2.0 -M .125 "); -is($res->return_code, 0, "Multiply OK" ); +$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"); +is($res->return_code, 0, "Test plain .1.3.6.1.4.1.8072.3.2.67.6 RC" ); +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" ); -$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.2.1.25.2.2.0 --multiplier=.0009765625 -f '%.3f' "); -is($res->return_code, 0, "Multiply format OK" ); +$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"); +is($res->return_code, 0, "Test multiply RC" ); +is($res->output,'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ' , "Test multiply .1 output" ); + +$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' "); +is($res->return_code, 0, "Test multiply RC + format" ); +is($res->output, 'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ', "Test multiply .1 output + format" ); + +$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"); +is($res->return_code, 1, "Test multiply RC + format + thresholds" ); +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 0e41d575..38912e98 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:\\" because we\'re not done yet!'; # Next are arrays of indexes (Type, initial value and increments) -# 0..16 <---- please update comment when adding/removing fields -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 ); -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' ); +# 0..19 <---- please update comment when adding/removing fields +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 ); +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 ); # undef increments are randomized -my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666, undef, undef, undef, undef, undef, -1, undef, undef ); +my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666, undef, undef, undef, undef, undef, -1, undef, undef, 0 ); # Number of elements in our OID my $oidelts; -- cgit v1.2.3-74-g34f1 From 9ba8f5ed66004c102bb626e47bb36dc9d0388632 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 22 Dec 2022 12:02:52 +0100 Subject: check_snmp: always apply format when applying multiplier --- plugins/check_snmp.c | 6 +++++- plugins/tests/check_snmp.t | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'plugins/tests') diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index d407609f..56bad880 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -1167,10 +1167,14 @@ multiply (char *str) { double val = strtod (str, NULL); val *= multiplier; + char *conv = "%f"; + if (fmtstr != "") { + conv = fmtstr; + } if (val == (int)val) { sprintf(str, "%.0f", val); } else { - sprintf(str, "%f", val); + sprintf(str, conv, val); } return str; } diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index bb5b8db6..bc03ec60 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t @@ -279,7 +279,7 @@ is($res->output,'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ' , $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' "); is($res->return_code, 0, "Test multiply RC + format" ); -is($res->output, 'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ', "Test multiply .1 output + format" ); +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" ); $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"); is($res->return_code, 1, "Test multiply RC + format + thresholds" ); -- cgit v1.2.3-74-g34f1 From c256af44fb23a4749faa5f3fce167a9d9a4367d7 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 22 Dec 2022 14:06:08 +0100 Subject: check_http/check_curl: add chunked encoding test --- plugins/tests/check_curl.t | 18 +++++++++++++++++- plugins/tests/check_http.t | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'plugins/tests') diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index aa72ef67..86bfb538 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t @@ -21,7 +21,7 @@ use FindBin qw($Bin); $ENV{'LC_TIME'} = "C"; -my $common_tests = 72; +my $common_tests = 74; my $ssl_only_tests = 8; # Check that all dependent modules are available eval "use HTTP::Daemon 6.01;"; @@ -200,6 +200,17 @@ sub run_server { $c->send_basic_header; $c->send_crlf; $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); + } elsif ($r->url->path eq "/chunked") { + $c->send_basic_header; + $c->send_header('Transfer-Encoding', "chunked"); + $c->send_crlf; + my $chunks = ["chunked", "encoding", "test\n"]; + $c->send_response(HTTP::Response->new( 200, 'OK', undef, sub { + my $chunk = shift @{$chunks}; + return unless $chunk; + sleep(1); + return($chunk); + })); } else { $c->send_error(HTTP::Status->RC_FORBIDDEN); } @@ -508,4 +519,9 @@ sub run_common_tests { }; is( $@, "", $cmd ); + $cmd = "$command -u /chunked -s 'chunkedencodingtest'"; + eval { + $result = NPTest->testCmd( $cmd, 5 ); + }; + is( $@, "", $cmd ); } diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index ea11b2ac..132c6659 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t @@ -12,7 +12,7 @@ use FindBin qw($Bin); $ENV{'LC_TIME'} = "C"; -my $common_tests = 70; +my $common_tests = 72; my $virtual_port_tests = 8; my $ssl_only_tests = 12; # Check that all dependent modules are available @@ -190,6 +190,17 @@ sub run_server { $c->send_basic_header; $c->send_crlf; $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); + } elsif ($r->url->path eq "/chunked") { + $c->send_basic_header; + $c->send_header('Transfer-Encoding', "chunked"); + $c->send_crlf; + my $chunks = ["chunked", "encoding", "test\n"]; + $c->send_response(HTTP::Response->new( 200, 'OK', undef, sub { + my $chunk = shift @{$chunks}; + return unless $chunk; + sleep(1); + return($chunk); + })); } else { $c->send_error(HTTP::Status->RC_FORBIDDEN); } @@ -497,4 +508,9 @@ sub run_common_tests { }; is( $@, "", $cmd ); + $cmd = "$command -u /chunked -s 'chunkedencodingtest'"; + eval { + $result = NPTest->testCmd( $cmd, 5 ); + }; + is( $@, "", $cmd ); } -- cgit v1.2.3-74-g34f1 From 07561a67abb02688955433db5b4a38b23523a754 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 22 Dec 2022 14:58:01 +0100 Subject: tests: fix chunked encoding test server --- plugins/tests/check_curl.t | 29 ++++++++++++++--------------- plugins/tests/check_http.t | 7 ++----- 2 files changed, 16 insertions(+), 20 deletions(-) (limited to 'plugins/tests') diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index 86bfb538..72f2b7c2 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t @@ -21,7 +21,7 @@ use FindBin qw($Bin); $ENV{'LC_TIME'} = "C"; -my $common_tests = 74; +my $common_tests = 73; my $ssl_only_tests = 8; # Check that all dependent modules are available eval "use HTTP::Daemon 6.01;"; @@ -200,17 +200,14 @@ sub run_server { $c->send_basic_header; $c->send_crlf; $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); - } elsif ($r->url->path eq "/chunked") { - $c->send_basic_header; - $c->send_header('Transfer-Encoding', "chunked"); - $c->send_crlf; - my $chunks = ["chunked", "encoding", "test\n"]; - $c->send_response(HTTP::Response->new( 200, 'OK', undef, sub { - my $chunk = shift @{$chunks}; - return unless $chunk; - sleep(1); - return($chunk); - })); + } elsif ($r->url->path eq "/chunked") { + my $chunks = ["chunked", "encoding", "test\n"]; + $c->send_response(HTTP::Response->new( 200, 'OK', undef, sub { + my $chunk = shift @{$chunks}; + return unless $chunk; + sleep(1); + return($chunk); + })); } else { $c->send_error(HTTP::Status->RC_FORBIDDEN); } @@ -483,7 +480,8 @@ sub run_common_tests { local $SIG{ALRM} = sub { die "alarm\n" }; alarm(2); $result = NPTest->testCmd( $cmd ); - alarm(0); }; + }; + alarm(0); isnt( $@, "alarm\n", $cmd ); is( $result->return_code, 0, $cmd ); @@ -493,7 +491,8 @@ sub run_common_tests { local $SIG{ALRM} = sub { die "alarm\n" }; alarm(2); $result = NPTest->testCmd( $cmd ); - alarm(0); }; + }; + alarm(0); isnt( $@, "alarm\n", $cmd ); isnt( $result->return_code, 0, $cmd ); @@ -519,7 +518,7 @@ sub run_common_tests { }; is( $@, "", $cmd ); - $cmd = "$command -u /chunked -s 'chunkedencodingtest'"; + $cmd = "$command -u /chunked -s 'chunkedencodingtest' -d 'Transfer-Encoding: chunked'"; eval { $result = NPTest->testCmd( $cmd, 5 ); }; diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 132c6659..d766ac37 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t @@ -12,7 +12,7 @@ use FindBin qw($Bin); $ENV{'LC_TIME'} = "C"; -my $common_tests = 72; +my $common_tests = 71; my $virtual_port_tests = 8; my $ssl_only_tests = 12; # Check that all dependent modules are available @@ -191,9 +191,6 @@ sub run_server { $c->send_crlf; $c->send_response(HTTP::Response->new( 200, 'OK', undef, $r->header ('Host'))); } elsif ($r->url->path eq "/chunked") { - $c->send_basic_header; - $c->send_header('Transfer-Encoding', "chunked"); - $c->send_crlf; my $chunks = ["chunked", "encoding", "test\n"]; $c->send_response(HTTP::Response->new( 200, 'OK', undef, sub { my $chunk = shift @{$chunks}; @@ -508,7 +505,7 @@ sub run_common_tests { }; is( $@, "", $cmd ); - $cmd = "$command -u /chunked -s 'chunkedencodingtest'"; + $cmd = "$command -u /chunked -s 'chunkedencodingtest' -d 'Transfer-Encoding: chunked'"; eval { $result = NPTest->testCmd( $cmd, 5 ); }; -- cgit v1.2.3-74-g34f1