Imported Upstream version 2.0

This commit is contained in:
Jan Wagner 2014-07-11 21:01:00 +02:00
parent c89ccc3c74
commit 0841b5c7c7
165 changed files with 25440 additions and 4442 deletions

View file

@ -0,0 +1,54 @@
{
'MYSQL_LOGIN_DETAILS' => '-u root -d test',
'NP_ALLOW_SUDO' => 'yes',
'NP_DNS_SERVER' => '8.8.8.8',
'NP_GOOD_NTP_SERVICE' => '',
'NP_HOSTNAME_INVALID' => 'nosuchhost',
'NP_HOSTNAME_VALID' => 'monitoringplugins.org',
'NP_HOSTNAME_VALID_IP' => '130.133.8.40',
'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.',
'NP_HOST_DHCP_RESPONSIVE' => '',
'NP_HOST_NONRESPONSIVE' => '10.0.0.1',
'NP_HOST_RESPONSIVE' => 'localhost',
'NP_HOST_SMB' => '',
'NP_HOST_SNMP' => '',
'NP_HOST_TCP_FTP' => '',
'NP_HOST_TCP_HPJD' => '',
'NP_HOST_TCP_HTTP' => 'localhost',
'NP_HOST_TCP_HTTP2' => 'labs.consol.de',
'NP_HOST_TCP_IMAP' => 'imap.web.de',
'NP_HOST_TCP_POP' => 'pop.web.de',
'NP_HOST_TCP_SMTP' => 'localhost',
'NP_HOST_TCP_SMTP_NOTLS' => '',
'NP_HOST_TCP_SMTP_TLS' => '',
'NP_INTERNET_ACCESS' => 'yes',
'NP_MOUNTPOINT2_VALID' => '',
'NP_MOUNTPOINT_VALID' => '/',
'NP_MYSQL_SERVER' => 'localhost',
'NP_HOST_UDP_TIME' => 'localhost',
'NP_MYSQL_SOCKET' => '/var/run/mysqld/mysqld.sock',
'NP_MYSQL_WITH_SLAVE' => '',
'NP_MYSQL_WITH_SLAVE_LOGIN' => '',
'NP_NO_NTP_SERVICE' => 'localhost',
'NP_SMB_SHARE' => '',
'NP_SMB_SHARE_DENY' => '',
'NP_SMB_SHARE_SPC' => '',
'NP_SMB_VALID_USER' => '',
'NP_SMB_VALID_USER_PASS' => '',
'NP_SNMP_COMMUNITY' => '',
'NP_SSH_CONFIGFILE' => '~/.ssh/config',
'NP_SSH_HOST' => 'localhost',
'NP_SSH_IDENTITY' => '~/.ssh/id_dsa',
'NP_HOST_TCP_JABBER' => 'jabber.org',
'host_nonresponsive' => '10.0.0.1',
'host_responsive' => 'localhost',
'host_snmp' => '',
'host_tcp_ftp' => '',
'host_tcp_http' => 'localhost',
'host_tcp_imap' => 'imap.nierlein.de',
'host_tcp_smtp' => 'localhost',
'hostname_invalid' => 'nosuchhost',
'snmp_community' => '',
'user_snmp' => '',
'host_udp_time' => 'none',
}

View file

@ -4,7 +4,7 @@
#
#
# TODO: Add in tests for perf data. Need to beef up Nagios::Plugin::Performance to cater for max, min, etc
# TODO: Add in tests for perf data. Need to beef up Monitoring::Plugin::Performance to cater for max, min, etc
use strict;
use Test::More;
@ -37,7 +37,7 @@ cmp_ok( $c, '==', 2, "Got two mountpoints in output");
# Get perf data
# Should use Nagios::Plugin
# Should use Monitoring::Plugin
my @perf_data = sort(split(/ /, $result->perf_output));

View file

@ -10,14 +10,14 @@ use NPTest;
plan skip_all => "check_dns not compiled" unless (-x "check_dns");
plan tests => 13;
plan tests => 14;
my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
my $hostname_valid = getTestParameter(
"NP_HOSTNAME_VALID",
"A valid (known to DNS) hostname",
"nagios.com"
"monitoring-plugins.org"
);
my $hostname_valid_ip = getTestParameter(
@ -54,6 +54,7 @@ cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 5");
cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
like( $res->output, "/\|time=[\d\.]+s;0.0*;5\.0*;0\.0*/", "Output performance data OK" );
$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");

View file

@ -27,16 +27,18 @@ my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_IN
my $t;
if ( -x "./check_fping" )
{
my $fping = qx(which fping 2> /dev/null);
chomp($fping);
if( ! -x "./check_fping") {
$t += skipMissingCmd( "./check_fping", $tests );
}
elsif ( $> != 0 && (!$fping || ! -u $fping)) {
$t += skipMsg( "./check_fping", $tests );
} else {
$t += checkCmd( "./check_fping $host_responsive", 0, $successOutput );
$t += checkCmd( "./check_fping $host_nonresponsive", [ 1, 2 ] );
$t += checkCmd( "./check_fping $hostname_invalid", [ 1, 2 ] );
}
else
{
$t += skipMissingCmd( "./check_fping", $tests );
}
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

View file

@ -31,8 +31,8 @@ my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
"yes");
my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
"A host providing an index page containing the string 'nagios'",
"nagios.org" );
"A host providing an index page containing the string 'monitoring'",
"test.monitoring-plugins.org" );
$res = NPTest->testCmd(
@ -62,27 +62,27 @@ cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" );
like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK");
SKIP: {
skip "No host serving nagios in index file", 7 unless $host_tcp_http2;
skip "No host serving monitoring in index file", 7 unless $host_tcp_http2;
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'nagios'" );
cmp_ok( $res->return_code, "==", 0, "Got a reference to 'nagios'");
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'monitoring'" );
cmp_ok( $res->return_code, "==", 0, "Got a reference to 'monitoring'");
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'nAGiOs'" );
cmp_ok( $res->return_code, "==", 2, "Not got 'nAGiOs'");
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'mONiTORing'" );
cmp_ok( $res->return_code, "==", 2, "Not got 'mONiTORing'");
like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'");
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -R 'nAGiOs'" );
cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'nAGiOs'");
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -R 'mONiTORing'" );
cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'mONiTORing'");
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'nagios' --invert-regex" );
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'monitoring' --invert-regex" );
cmp_ok( $res->return_code, "==", 2, "Invert results work when found");
like ( $res->output, "/pattern found/", "Error message says 'pattern found'");
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'nAGiOs' --invert-regex" );
$res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'mONiTORing' --invert-regex" );
cmp_ok( $res->return_code, "==", 0, "And also when not found");
}
SKIP: {
skip "No internet access", 11 if $internet_access eq "no";
skip "No internet access", 16 if $internet_access eq "no";
$res = NPTest->testCmd(
"./check_http --ssl www.verisign.com"

View file

@ -29,7 +29,7 @@ my $hostname_invalid = getTestParameter(
);
my $jabberOK = '/JABBER OK\s-\s\d+\.\d+\ssecond response time on port 5222/';
my $jabberOK = '/JABBER OK\s-\s\d+\.\d+\ssecond response time on '.$host_tcp_jabber.' port 5222/';
my $jabberUnresponsive = '/CRITICAL\s-\sSocket timeout after\s\d+\sseconds/';
@ -40,7 +40,7 @@ my $r;
SKIP: {
skip "No jabber server defined", 6 unless $host_tcp_jabber;
$r = NPTest->testCmd( "./check_jabber $host_tcp_jabber" );
$r = NPTest->testCmd( "./check_jabber -H $host_tcp_jabber" );
is( $r->return_code, 0, "Connected okay");
like( $r->output, $jabberOK, "Output as expected" );
@ -48,7 +48,7 @@ SKIP: {
is( $r->return_code, 0, "Connected okay, within limits" );
like( $r->output, $jabberOK, "Output as expected" );
$r = NPTest->testCmd( "./check_jabber $host_tcp_jabber -wt 9 -ct 9 -to 10" );
$r = NPTest->testCmd( "./check_jabber -H $host_tcp_jabber -wt 9 -ct 9 -to 10" );
is( $r->return_code, 0, "Old syntax okay" );
like( $r->output, $jabberOK, "Output as expected" );

View file

@ -21,27 +21,29 @@ plan skip_all => "check_mysql not compiled" unless (-x "check_mysql");
plan tests => 15;
my $bad_login_output = '/Access denied for user /';
my $mysqlserver = getTestParameter(
"NP_MYSQL_SERVER",
my $mysqlserver = getTestParameter(
"NP_MYSQL_SERVER",
"A MySQL Server hostname or IP with no slaves setup"
);
my $mysqlsocket = getTestParameter(
"NP_MYSQL_SOCKET",
"A MySQL Server socket with no slaves setup"
my $mysqlsocket = getTestParameter(
"NP_MYSQL_SOCKET",
"Full path to a MySQL Server socket with no slaves setup"
);
my $mysql_login_details = getTestParameter(
"MYSQL_LOGIN_DETAILS",
"Command line parameters to specify login access",
"-u user -ppw -d db",
my $mysql_login_details = getTestParameter(
"MYSQL_LOGIN_DETAILS",
"Command line parameters to specify login access (requires " .
"REPLICATION CLIENT privleges)",
"-u test -ptest",
);
my $with_slave = getTestParameter(
"NP_MYSQL_WITH_SLAVE",
my $with_slave = getTestParameter(
"NP_MYSQL_WITH_SLAVE",
"MySQL server with slaves setup"
);
my $with_slave_login = getTestParameter(
"NP_MYSQL_WITH_SLAVE_LOGIN",
"Login details for server with slave",
"-uroot -ppw"
my $with_slave_login = getTestParameter(
"NP_MYSQL_WITH_SLAVE_LOGIN",
"Login details for server with slave (requires REPLICATION CLIENT " .
"privleges)",
$mysql_login_details || "-u test -ptest"
);
my $result;

View file

@ -23,12 +23,12 @@ my $no_ntp_service = getTestParameter( "NP_NO_NTP_SERVICE",
"A host NOT providing the NTP service",
"localhost" );
my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
"The hostname of system not responsive to network requests",
"10.0.0.1" );
my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
"An invalid (not known to DNS) hostname",
my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
"An invalid (not known to DNS) hostname",
"nosuchhost");
my $ntp_okmatch1 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
@ -43,7 +43,7 @@ my $ntp_nosuchhost = '/^check_ntp.*: Invalid hostname/address - ' . $hostname_in
foreach my $plugin (@PLUGINS1) {
SKIP: {
skip "No NTP server defined", 1 unless $ntp_service;
skip "No NTP server defined", 6 unless $ntp_service;
$res = NPTest->testCmd(
"./$plugin -H $ntp_service -w 1000 -c 2000"
);
@ -88,7 +88,7 @@ foreach my $plugin (@PLUGINS1) {
foreach my $plugin (@PLUGINS2) {
SKIP: {
skip "No NTP server defined", 1 unless $ntp_service;
skip "No NTP server defined", 6 unless $ntp_service;
$res = NPTest->testCmd(
"./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k 200000 -m 1: -n 0:"
);

View file

@ -13,7 +13,7 @@ my $t;
if (`uname -s` eq "SunOS\n" && ! -x "/usr/local/nagios/libexec/pst3") {
plan skip_all => "Ignoring tests on solaris because of pst3";
} else {
plan tests => 12;
plan tests => 14;
}
my $result;
@ -26,6 +26,11 @@ $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" );
is( $result->return_code, 0, "Checking less than 100000 zombie processes" );
like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" );
if(fork() == 0) { exec("sleep 7"); } else { sleep(1) } # fork a test process in child and give child time to fork in parent
$result = NPTest->testCmd( "./check_procs -a 'sleep 7'" );
is( $result->return_code, 0, "Parent process is ignored" );
like( $result->output, '/^PROCS OK: 1 process?/', "Output correct" );
$result = NPTest->testCmd( "./check_procs -w 0 -c 100000" );
is( $result->return_code, 1, "Checking warning if processes > 0" );
like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "Output correct" );

View file

@ -10,7 +10,7 @@ use NPTest;
BEGIN {
plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp";
plan tests => 60;
plan tests => 61;
}
my $res;
@ -26,6 +26,7 @@ my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRES
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
my $user_snmp = getTestParameter( "user_snmp", "NP_SNMP_USER", "auth_md5", "An SNMP user");
$res = NPTest->testCmd( "./check_snmp -t 1" );
is( $res->return_code, 3, "No host name" );
@ -35,7 +36,7 @@ $res = NPTest->testCmd( "./check_snmp -H fakehostname" );
is( $res->return_code, 3, "No OIDs specified" );
is( $res->output, "No OIDs specified" );
$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 --seclevel=rubbish" );
$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 -U not_a_user --seclevel=rubbish" );
is( $res->return_code, 3, "Invalid seclevel" );
like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" );
@ -44,7 +45,7 @@ is( $res->return_code, 3, "Invalid protocol" );
like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
SKIP: {
skip "no snmp host defined", 38 if ( ! $host_snmp );
skip "no snmp host defined", 48 if ( ! $host_snmp );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
@ -154,6 +155,12 @@ SKIP: {
like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed");
}
SKIP: {
skip "no SNMP user defined", 1 if ( ! $user_snmp );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -o HOST-RESOURCES-MIB::hrSystemUptime.0 -P 3 -U $user_snmp -L noAuthNoPriv");
like( $res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "noAuthNoPriv security level works properly" );
}
# These checks need a complete command line. An invalid community is used so
# the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway
SKIP: {

View file

@ -12,7 +12,6 @@ BEGIN {
use NPTest;
$has_ipv6 = NPTest::has_ipv6();
$tests = $has_ipv6 ? 14 : 11;
plan tests => $tests;
}
@ -25,20 +24,29 @@ my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRES
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
"Is this system directly connected to the internet?",
"yes");
my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/';
my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on port [0-9]+/';
my $t;
$tests = $tests - 4 if $internet_access eq "no";
plan tests => $tests;
$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput );
$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test
$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 );
$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 );
$t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 );
$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 1 );
$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 );
$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 );
if($internet_access ne "no") {
$t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 );
$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 1 );
$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 );
$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 );
}
# Need the \r\n to make it more standards compliant with web servers. Need the various quotes
# so that perl doesn't interpret the \r\n and is passed onto command line correctly

View file

@ -62,7 +62,7 @@ SKIP: {
cmp_ok( $res->return_code, '==', '2', "Hung waiting for response");
like ( $res->output, '/Socket timeout after 5 seconds/', "Timeout message");
like ( $duration, '/^[56]$/', "Timeout after 5 (possibly 6) seconds");
my $read_nc = <NC>;
my $read_nc = <NC> || '';
close NC;
cmp_ok( $read_nc, 'eq', "foofoo", "Data received correctly" );
}

View file

@ -78,7 +78,7 @@ foreach my $current_state (keys(%state)) {
}
}
# Same as aboce with substitute
# Same as above with substitute
foreach my $current_state (keys(%state)) {
foreach my $new_state (keys(%state)) {
$res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );