Imported Upstream version 1.4.16_pre1
This commit is contained in:
		
							parent
							
								
									047baae1ca
								
							
						
					
					
						commit
						212b4b8677
					
				
					 69 changed files with 10803 additions and 2698 deletions
				
			
		| 
						 | 
				
			
			@ -18,9 +18,24 @@ use Test::More;
 | 
			
		|||
use NPTest;
 | 
			
		||||
use FindBin qw($Bin);
 | 
			
		||||
 | 
			
		||||
use HTTP::Daemon;
 | 
			
		||||
use HTTP::Status;
 | 
			
		||||
use HTTP::Response;
 | 
			
		||||
my $common_tests = 66;
 | 
			
		||||
my $ssl_only_tests = 6;
 | 
			
		||||
# Check that all dependent modules are available
 | 
			
		||||
eval {
 | 
			
		||||
	require HTTP::Daemon;
 | 
			
		||||
	require HTTP::Status;
 | 
			
		||||
	require HTTP::Response;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
if ($@) {
 | 
			
		||||
	plan skip_all => "Missing required module for test: $@";
 | 
			
		||||
} else {
 | 
			
		||||
	if (-x "./check_http") {
 | 
			
		||||
		plan tests => $common_tests * 2 + $ssl_only_tests;
 | 
			
		||||
	} else {
 | 
			
		||||
		plan skip_all => "No check_http compiled";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my $servers = { http => 0 };	# HTTP::Daemon should always be available
 | 
			
		||||
eval { require HTTP::Daemon::SSL };
 | 
			
		||||
| 
						 | 
				
			
			@ -112,9 +127,9 @@ sub run_server {
 | 
			
		|||
				$c->send_response("slow");
 | 
			
		||||
			} elsif ($r->url->path eq "/method") {
 | 
			
		||||
				if ($r->method eq "DELETE") {
 | 
			
		||||
					$c->send_error(RC_METHOD_NOT_ALLOWED);
 | 
			
		||||
					$c->send_error(HTTP::Status->RC_METHOD_NOT_ALLOWED);
 | 
			
		||||
				} elsif ($r->method eq "foo") {
 | 
			
		||||
					$c->send_error(RC_NOT_IMPLEMENTED);
 | 
			
		||||
					$c->send_error(HTTP::Status->RC_NOT_IMPLEMENTED);
 | 
			
		||||
				} else {
 | 
			
		||||
					$c->send_status_line(200, $r->method);
 | 
			
		||||
				}
 | 
			
		||||
| 
						 | 
				
			
			@ -138,7 +153,7 @@ sub run_server {
 | 
			
		|||
				delete($persist[1000]);
 | 
			
		||||
				next MAINLOOP;
 | 
			
		||||
			} else {
 | 
			
		||||
				$c->send_error(RC_FORBIDDEN);
 | 
			
		||||
				$c->send_error(HTTP::Status->RC_FORBIDDEN);
 | 
			
		||||
			}
 | 
			
		||||
			$c->close;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -157,14 +172,6 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my $common_tests = 66;
 | 
			
		||||
my $ssl_only_tests = 6;
 | 
			
		||||
if (-x "./check_http") {
 | 
			
		||||
	plan tests => $common_tests * 2 + $ssl_only_tests;
 | 
			
		||||
} else {
 | 
			
		||||
	plan skip_all => "No check_http compiled";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
my $result;
 | 
			
		||||
my $command = "./check_http -H 127.0.0.1";
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -175,17 +182,17 @@ SKIP: {
 | 
			
		|||
	
 | 
			
		||||
	$result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
 | 
			
		||||
	is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
 | 
			
		||||
	is( $result->output, 'OK - Certificate will expire on 03/03/2019 21:41.', "output ok" );
 | 
			
		||||
	is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on 03/03/2019 21:41.', "output ok" );
 | 
			
		||||
 | 
			
		||||
	$result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
 | 
			
		||||
	is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
 | 
			
		||||
	like( $result->output, '/WARNING - Certificate expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
 | 
			
		||||
	like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(03/03/2019 21:41\)./', "output ok" );
 | 
			
		||||
 | 
			
		||||
	# Expired cert tests
 | 
			
		||||
	$result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
 | 
			
		||||
	is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
 | 
			
		||||
	is( $result->output, 
 | 
			
		||||
		'CRITICAL - Certificate expired on 03/05/2009 00:13.',
 | 
			
		||||
		'CRITICAL - Certificate \'Ton Voon\' expired on 03/05/2009 00:13.',
 | 
			
		||||
		"output ok" );
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ use Test::More;
 | 
			
		|||
use NPTest;
 | 
			
		||||
 | 
			
		||||
if (-x "./check_procs") {
 | 
			
		||||
	plan tests => 48;
 | 
			
		||||
	plan tests => 50;
 | 
			
		||||
} else {
 | 
			
		||||
	plan skip_all => "No check_procs compiled";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -113,3 +113,7 @@ $result = NPTest->testCmd( "$command --metric=RSS -c 70000 -v" );
 | 
			
		|||
is( $result->return_code, 2, "Checking against RSS > 70MB" );
 | 
			
		||||
is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowServer, SystemUIServer, Safari, Mail, Safari]', "Output correct" );
 | 
			
		||||
 | 
			
		||||
$result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" );
 | 
			
		||||
is( $result->return_code, 0, "Checking no pipe symbol in output" );
 | 
			
		||||
is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)'", "Output correct" );
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ use Test::More;
 | 
			
		|||
use NPTest;
 | 
			
		||||
use FindBin qw($Bin);
 | 
			
		||||
 | 
			
		||||
my $tests = 41;
 | 
			
		||||
# 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 = 33;
 | 
			
		||||
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");
 | 
			
		||||
| 
						 | 
				
			
			@ -170,5 +173,19 @@ $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)" );
 | 
			
		||||
 | 
			
		||||
$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'" );
 | 
			
		||||
is($res->return_code, 0, "String check should check whole string, not a parsed number" );
 | 
			
		||||
is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check witn numbers returns whole string");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,9 +33,10 @@ 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, ASN_COUNTER, ASN_OCTET_STR);
 | 
			
		||||
my @values = ($multiline, $multilin2, $multilin3, $multilin4, $multilin5, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32)), 64000, "stringtests");
 | 
			
		||||
my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666, undef);
 | 
			
		||||
# 0..15 <---- 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 );
 | 
			
		||||
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' );
 | 
			
		||||
my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666, undef, undef, undef, undef, undef );
 | 
			
		||||
 | 
			
		||||
# Number of elements in our OID
 | 
			
		||||
my $oidelts;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue