Imported Upstream version 1.4.5

This commit is contained in:
Jan Wagner 2013-11-26 23:53:19 +01:00
parent 62d1e7d5fe
commit 6a280f6f24
412 changed files with 168642 additions and 0 deletions

1
plugins/t/.cvsignore Normal file
View file

@ -0,0 +1 @@
*.tmp

26
plugins/t/CVS/Entries Normal file
View file

@ -0,0 +1,26 @@
/.cvsignore/1.1/Fri Dec 2 22:25:22 2005//Tr1_4_5
/check_disk.t/1.14/Wed Oct 18 12:12:11 2006//Tr1_4_5
/check_dns.t/1.7/Wed Mar 29 08:13:29 2006//Tr1_4_5
/check_fping.t/1.2/Mon Jul 25 01:47:14 2005//Tr1_4_5
/check_ftp.t/1.3/Mon Jul 25 01:47:14 2005//Tr1_4_5
/check_hpjd.t/1.3/Fri Mar 24 16:13:40 2006//Tr1_4_5
/check_http.t/1.12/Thu Oct 19 18:59:58 2006//Tr1_4_5
/check_imap.t/1.4/Wed Nov 9 16:40:12 2005//Tr1_4_5
/check_load.t/1.6/Mon Oct 2 12:09:18 2006//Tr1_4_5
/check_mysql.t/1.8/Fri Mar 17 14:07:34 2006//Tr1_4_5
/check_mysql_query.t/1.2/Wed Feb 1 13:23:38 2006//Tr1_4_5
/check_nagios.nagios1.status.log/1.1/Fri Dec 2 22:28:06 2005//Tr1_4_5
/check_nagios.nagios2.status.dat/1.1/Fri Dec 2 22:28:06 2005//Tr1_4_5
/check_nagios.t/1.2/Wed Apr 19 09:33:44 2006//Tr1_4_5
/check_ntp.t/1.2/Mon Aug 14 08:42:23 2006//Tr1_4_5
/check_ping.t/1.3/Thu Sep 15 08:39:23 2005//Tr1_4_5
/check_pop.t/1.3/Wed Mar 22 15:45:49 2006//Tr1_4_5
/check_procs.t/1.5/Thu Nov 3 15:13:13 2005//Tr1_4_5
/check_smtp.t/1.4/Thu Oct 19 11:56:34 2006//Tr1_4_5
/check_snmp.t/1.2/Mon Jul 25 01:47:15 2005//Tr1_4_5
/check_swap.t/1.3/Wed Nov 9 16:40:12 2005//Tr1_4_5
/check_tcp.t/1.3/Mon Jul 25 01:47:15 2005//Tr1_4_5
/check_time.t/1.3/Thu Nov 3 15:04:16 2005//Tr1_4_5
/check_udp.t/1.6/Fri Jul 28 22:44:11 2006//Tr1_4_5
/check_users.t/1.2/Mon Jul 25 01:47:15 2005//Tr1_4_5
D

1
plugins/t/CVS/Repository Normal file
View file

@ -0,0 +1 @@
nagiosplug/plugins/t

1
plugins/t/CVS/Root Normal file
View file

@ -0,0 +1 @@
:ext:tonvoon@nagiosplug.cvs.sourceforge.net:/cvsroot/nagiosplug

1
plugins/t/CVS/Tag Normal file
View file

@ -0,0 +1 @@
Nr1_4_5

194
plugins/t/check_disk.t Normal file
View file

@ -0,0 +1,194 @@
#! /usr/bin/perl -w -I ..
#
# Disk Space Tests via check_disk
#
# $Id: check_disk.t,v 1.14 2006/10/18 12:12:11 tonvoon Exp $
#
# TODO: Add in tests for perf data. Need to beef up Nagios::Plugin::Performance to cater for max, min, etc
use strict;
use Test::More;
use NPTest;
use POSIX qw(ceil floor);
my $successOutput = '/^DISK OK/';
my $failureOutput = '/^DISK CRITICAL/';
my $warningOutput = '/^DISK WARNING/';
my $result;
my $mountpoint_valid = getTestParameter( "NP_MOUNTPOINT_VALID", "Path to valid mountpoint", "/");
my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to another valid mountpoint. Must be different from 1st one", "/var");
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
plan skip_all => "Need 2 mountpoints to test";
} else {
plan tests => 42;
}
$result = NPTest->testCmd(
"./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid"
);
cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free)");
my $c = 0;
$_ = $result->output;
$c++ while /\(/g; # counts number of "(" - should be two
cmp_ok( $c, '==', 2, "Got two mountpoints in output");
# Calculate avg_free free on mountpoint1 and mountpoint2
# because if you check in the middle, you should get different errors
$_ = $result->output;
my ($free_on_mp1, $free_on_mp2) = (m/\((\d+)%.*\((\d+)%/);
die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2);
my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2);
my ($more_free, $less_free);
if ($free_on_mp1 > $free_on_mp2) {
$more_free = $mountpoint_valid;
$less_free = $mountpoint2_valid;
} elsif ($free_on_mp1 < $free_on_mp2) {
$more_free = $mountpoint2_valid;
$less_free = $mountpoint_valid;
} else {
die "Two mountpoints are the same - cannot do rest of test";
}
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free" );
cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free");
like ( $result->output, $successOutput, "OK output" );
like ( $result->only_output, qr/free space/, "Have free space text");
like ( $result->only_output, qr/$more_free/, "Have disk name in text");
$result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" );
is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs");
$result = NPTest->testCmd( "./check_disk 100 100 $more_free" );
cmp_ok( $result->return_code, '==', 0, "Old syntax okay" );
$result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" );
cmp_ok( $result->return_code, "==", 0, "At least 1% free" );
$result = NPTest->testCmd(
"./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free"
);
cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" );
like( $result->output, $failureOutput, "Right output" );
$result = NPTest->testCmd(
"./check_disk -w $avg_free% -c 0% -p $less_free"
);
cmp_ok( $result->return_code, '==', 1, "Get warning on less_free mountpoint, when checking avg_free");
$result = NPTest->testCmd(
"./check_disk -w $avg_free% -c $avg_free% -p $more_free"
);
cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free");
$result = NPTest->testCmd(
"./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free"
);
cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning");
my $all_disks = $result->output;
$result = NPTest->testCmd(
"./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free"
);
isnt( $result->output, $all_disks, "-e gives different output");
like( $result->output, qr/$less_free/, "Found problem $less_free");
unlike( $result->only_output, qr/$more_free/, "Has ignored $more_free as not a problem");
like( $result->perf_output, qr/$more_free/, "But $more_free is still in perf data");
$result = NPTest->testCmd(
"./check_disk -w $avg_free% -c 0% -p $more_free"
);
cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, checking avg_free");
$result = NPTest->testCmd(
"./check_disk -w $avg_free% -c $avg_free% -p $less_free"
);
cmp_ok( $result->return_code, '==', 2, "Get critical on less_free, checking avg_free");
$result = NPTest->testCmd(
"./check_disk -w $avg_free% -c 0% -p $more_free -w $avg_free% -c $avg_free% -p $less_free"
);
cmp_ok( $result->return_code, '==', 2, "Combining above two tests, get critical");
$result = NPTest->testCmd(
"./check_disk -w $avg_free% -c $avg_free% -p $less_free -w $avg_free% -c 0% -p $more_free"
);
cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference");
TODO: {
local $TODO = "Invalid percent figures";
$result = NPTest->testCmd(
"./check_disk -w 10% -c 15% -p $mountpoint_valid"
);
cmp_ok( $result->return_code, '==', 3, "Invalid command line options" );
}
$result = NPTest->testCmd(
"./check_disk -p $mountpoint_valid -w 10% -c 15%"
);
cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" );
$result = NPTest->testCmd( "./check_disk -w 100% -c 100% ".${mountpoint_valid} ); # 100% empty
cmp_ok( $result->return_code, "==", 2, "100% empty" );
like( $result->output, $failureOutput, "Right output" );
$result = NPTest->testCmd( "./check_disk -w 100000 -c 100000 $mountpoint_valid" );
cmp_ok( $result->return_code, '==', 2, "Check for 100GB free" );
$result = NPTest->testCmd( "./check_disk -w 100 -c 100 -u GB ".${mountpoint_valid} ); # 100 GB empty
cmp_ok( $result->return_code, "==", 2, "100 GB empty" );
# Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds
$result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} );
cmp_ok( $result->return_code, "==", 2, "Old syntax: 0% used");
$result = NPTest->testCmd( "./check_disk 100 100 $mountpoint_valid" );
cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" );
$result = NPTest->testCmd( "./check_disk 0 100 $mountpoint_valid" );
cmp_ok( $result->return_code, '==', 1, "Old syntax: warn 0% used" );
TODO: {
local $TODO = "Invalid values";
$result = NPTest->testCmd( "./check_disk 0 200 $mountpoint_valid" );
cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
$result = NPTest->testCmd( "./check_disk 200 200 $mountpoint_valid" );
cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
$result = NPTest->testCmd( "./check_disk 200 0 $mountpoint_valid" );
cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
}
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /bob" );
cmp_ok( $result->return_code, '==', 2, "Checking /bob - return error because /bob does not exist" );
cmp_ok( $result->output, 'eq', 'DISK CRITICAL - /bob does not exist', 'Output OK');
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /" );
my $root_output = $result->output;
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc" );
cmp_ok( $result->return_code, '==', 0, "Checking /etc - should return info for /" );
cmp_ok( $result->output, 'eq', $root_output, "check_disk /etc gives same as check_disk /");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc -E" );
cmp_ok( $result->return_code, '==', 2, "... unless -E/--exact-match is specified");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /bob" );
cmp_ok( $result->return_code, '==', 2, "Checking / and /bob gives critical");
unlike( $result->perf_output, '/\/bob/', "perf data does not have /bob in it");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /" );
unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice");

79
plugins/t/check_dns.t Normal file
View file

@ -0,0 +1,79 @@
#! /usr/bin/perl -w -I ..
#
# Domain Name Server (DNS) Tests via check_dns
#
# $Id: check_dns.t,v 1.7 2006/03/29 08:13:29 tonvoon Exp $
#
use strict;
use Test::More;
use NPTest;
plan skip_all => "check_dns not compiled" unless (-x "check_dns");
plan tests => 13;
my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
my $hostname_valid = getTestParameter(
"NP_HOSTNAME_VALID",
"A valid (known to DNS) hostname",
"apple.com"
);
my $hostname_valid_ip = getTestParameter(
"NP_HOSTNAME_VALID_IP",
"The IP address of the valid hostname $hostname_valid",
"17.254.3.183"
);
my $hostname_valid_reverse = getTestParameter(
"NP_HOSTNAME_VALID_REVERSE",
"The hostname of $hostname_valid_ip",
$hostname_valid."."
);
my $hostname_invalid = getTestParameter(
"NP_HOSTNAME_INVALID",
"An invalid (not known to DNS) hostname",
"nosuchhost.altinity.com",
);
my $dns_server = getTestParameter(
"NP_DNS_SERVER",
"A non default (remote) DNS server",
);
my $res;
$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5");
cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
like ( $res->output, $successOutput, "Output OK" );
$res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5 -w 0 -c 0");
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");
$res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1");
cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
$res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5");
cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
like ( $res->output, $successOutput, "Output OK" );
$res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1");
cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server");
$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5");
cmp_ok( $res->return_code, '==', 0, "Got expected address");
$res = NPTest->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5");
cmp_ok( $res->return_code, '==', 2, "Got wrong address");
like ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK");
$res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5");
cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
like ( $res->output, $successOutput, "Output OK");

43
plugins/t/check_fping.t Normal file
View file

@ -0,0 +1,43 @@
#! /usr/bin/perl -w -I ..
#
# FPing Tests via check_fping
#
# $Id: check_fping.t,v 1.2 2005/07/25 01:47:14 illumino Exp $
#
use strict;
use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 4; plan tests => $tests}
my $successOutput = '/^FPING OK - /';
my $failureOutput = '/^FPING CRITICAL - /';
my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost",
"The hostname of system responsive to network requests" );
my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
"The hostname of system not responsive to network requests" );
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
my $t;
if ( -x "./check_fping" )
{
$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);

34
plugins/t/check_ftp.t Normal file
View file

@ -0,0 +1,34 @@
#! /usr/bin/perl -w -I ..
#
# File Transfer Protocol (FTP) Test via check_ftp
#
# $Id: check_ftp.t,v 1.3 2005/07/25 01:47:14 illumino Exp $
#
use strict;
use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 4; plan tests => $tests}
my $host_tcp_ftp = getTestParameter( "host_tcp_ftp", "NP_HOST_TCP_FTP", "localhost",
"A host providing the FTP Service (an FTP server)");
my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
"The hostname of system not responsive to network requests" );
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
my $successOutput = '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/';
my $t;
$t += checkCmd( "./check_ftp $host_tcp_ftp -wt 300 -ct 600", 0, $successOutput );
$t += checkCmd( "./check_ftp $host_nonresponsive -wt 0 -ct 0 -to 1", 2 );
$t += checkCmd( "./check_ftp $hostname_invalid -wt 0 -ct 0", 2 );
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

51
plugins/t/check_hpjd.t Normal file
View file

@ -0,0 +1,51 @@
#! /usr/bin/perl -w -I ..
#
# HP JetDirect Test via check_hpjd
#
# $Id: check_hpjd.t,v 1.3 2006/03/24 16:13:40 tonvoon Exp $
#
use strict;
use Test::More;
use NPTest;
plan skip_all => "check_hpjd not compiled" unless (-x "check_hpjd");
plan tests => 5;
my $successOutput = '/^Printer ok - /';
my $failureOutput = '/Timeout: No [Rr]esponse from /';
my $host_tcp_hpjd = getTestParameter(
"NP_HOST_TCP_HPJD",
"A host (usually a printer) providing the HP-JetDirect Services"
);
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",
"nosuchhost",
);
my $res;
SKIP: {
skip "No HP JetDirect defined", 2 unless $host_tcp_hpjd;
$res = NPTest->testCmd("./check_hpjd $host_tcp_hpjd");
cmp_ok( $res->return_code, '==', 0, "Jetdirect responding" );
like ( $res->output, $successOutput, "Output correct" );
}
$res = NPTest->testCmd("./check_hpjd $host_nonresponsive");
cmp_ok( $res->return_code, 'eq', 2, "Host not responding");
like ( $res->output, $failureOutput, "Output OK" );
$res = NPTest->testCmd("./check_hpjd $hostname_invalid");
cmp_ok( $res->return_code, 'eq', 3, "Hostname invalid");

101
plugins/t/check_http.t Normal file
View file

@ -0,0 +1,101 @@
#! /usr/bin/perl -w -I ..
#
# HyperText Transfer Protocol (HTTP) Test via check_http
#
# $Id: check_http.t,v 1.12 2006/10/19 18:59:58 tonvoon Exp $
#
use strict;
use Test::More;
use NPTest;
plan tests => 22;
my $successOutput = '/OK.*HTTP.*second/';
my $res;
my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP",
"A host providing the HTTP Service (a web server)",
"localhost" );
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",
"nosuchhost");
$res = NPTest->testCmd(
"./check_http $host_tcp_http -wt 300 -ct 600"
);
cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" );
like( $res->output, $successOutput, "Output OK" );
$res = NPTest->testCmd(
"./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here'"
);
like( $res->output, '/bob:there\r\nfred:here\r\n/', "Got headers, delimited with ';'" );
$res = NPTest->testCmd(
"./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here' -k 'carl:frown'"
);
like( $res->output, '/bob:there\r\nfred:here\r\ncarl:frown\r\n/', "Got headers with multiple -k options" );
$res = NPTest->testCmd(
"./check_http $host_nonresponsive -wt 1 -ct 2"
);
cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" );
cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 10 seconds", "Output OK");
$res = NPTest->testCmd(
"./check_http $hostname_invalid -wt 1 -ct 2"
);
cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" );
# The first part of the message comes from the OS catalogue, so cannot check this.
# On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename
# Is also possible to get a socket timeout if DNS is not responding fast enough
like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK");
$res = NPTest->testCmd(
"./check_http --ssl www.verisign.com"
);
cmp_ok( $res->return_code, '==', 0, "Can read https for www.verisign.com" );
$res = NPTest->testCmd( "./check_http -C 1 --ssl www.verisign.com" );
cmp_ok( $res->return_code, '==', 0, "Checking certificate for www.verisign.com");
like ( $res->output, '/Certificate will expire on/', "Output OK" );
my $saved_cert_output = $res->output;
$res = NPTest->testCmd( "./check_http -C 1 www.verisign.com" );
cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added");
$res = NPTest->testCmd( "./check_http www.verisign.com -C 1" );
cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works");
$res = NPTest->testCmd(
"./check_http --ssl www.e-paycobalt.com"
);
cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" );
$res = NPTest->testCmd( "./check_http -H altinity.com -r 'nagios'" );
cmp_ok( $res->return_code, "==", 0, "Got a reference to 'nagios'");
$res = NPTest->testCmd( "./check_http -H altinity.com -r 'nAGiOs'" );
cmp_ok( $res->return_code, "==", 2, "Not got 'nAGiOs'");
like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'");
$res = NPTest->testCmd( "./check_http -H altinity.com -R 'nAGiOs'" );
cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'nAGiOs'");
$res = NPTest->testCmd( "./check_http -H altinity.com -r 'nagios' --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 altinity.com -r 'nAGiOs' --invert-regex" );
cmp_ok( $res->return_code, "==", 0, "And also when not found");
$res = NPTest->testCmd( "./check_http -H www.worldfirefoxday.com -f follow" );
is( $res->return_code, 0, "Redirection based on location is okay");

46
plugins/t/check_imap.t Normal file
View file

@ -0,0 +1,46 @@
#! /usr/bin/perl -w -I ..
#
# Internet Mail Access Protocol (IMAP) Server Tests via check_imap
#
# $Id: check_imap.t,v 1.4 2005/11/09 16:40:12 tonvoon Exp $
#
use strict;
use Test::More tests => 7;
use NPTest;
my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost",
"A host providing an STMP Service (a mail server)");
my $host_tcp_imap = getTestParameter( "host_tcp_imap", "NP_HOST_TCP_IMAP", $host_tcp_smtp,
"A host providing an IMAP Service (a mail server)");
my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
"The hostname of system not responsive to network requests" );
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
my $t;
$t = NPTest->testCmd( "./check_imap $host_tcp_imap" );
cmp_ok( $t->return_code, '==', 0, "Contacted imap" );
$t = NPTest->testCmd( "./check_imap -H $host_tcp_imap -p 143 -w 9 -c 9 -to 10 -e '* OK'" );
cmp_ok( $t->return_code, '==', 0, "Got right response" );
$t = NPTest->testCmd( "./check_imap $host_tcp_imap -p 143 -wt 9 -ct 9 -to 10 -e '* OK'" );
cmp_ok( $t->return_code, '==', 0, "Check old parameter options" );
$t = NPTest->testCmd( "./check_imap $host_nonresponsive" );
cmp_ok( $t->return_code, '==', 2, "Get error with non reponsive host" );
$t = NPTest->testCmd( "./check_imap $hostname_invalid" );
cmp_ok( $t->return_code, '==', 2, "Invalid hostname" );
$t = NPTest->testCmd( "./check_imap -H $host_tcp_imap -e unlikely_string");
cmp_ok( $t->return_code, '==', 1, "Got warning with bad response" );
$t = NPTest->testCmd( "./check_imap -H $host_tcp_imap -e unlikely_string -M crit");
cmp_ok( $t->return_code, '==', 2, "Got critical error with bad response" );

26
plugins/t/check_load.t Normal file
View file

@ -0,0 +1,26 @@
#! /usr/bin/perl -w -I ..
#
# Load Average Tests via check_load
#
# $Id: check_load.t,v 1.6 2006/10/02 12:09:18 tonvoon Exp $
#
use strict;
use Test::More;
use NPTest;
my $res;
my $successOutput = '/^OK - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/';
my $failureOutput = '/^CRITICAL - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/';
plan tests => 4;
$res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" );
cmp_ok( $res->return_code, 'eq', 0, "load not over 100");
like( $res->output, $successOutput, "Output OK");
$res = NPTest->testCmd( "./check_load -w 0,0,0 -c 0,0,0" );
cmp_ok( $res->return_code, 'eq', 2, "Load over 0");
like( $res->output, $failureOutput, "Output OK");

74
plugins/t/check_mysql.t Normal file
View file

@ -0,0 +1,74 @@
#! /usr/bin/perl -w -I ..
#
# MySQL Database Server Tests via check_mysql
#
# $Id: check_mysql.t,v 1.8 2006/03/17 14:07:34 tonvoon Exp $
#
#
# These are the database permissions required for this test:
# GRANT SELECT ON $db.* TO $user@$host INDENTIFIED BY '$password';
# GRANT SUPER, REPLICATION CLIENT ON *.* TO $user@$host;
# Check with:
# mysql -u$user -p$password -h$host $db
use strict;
use Test::More;
use NPTest;
use vars qw($tests);
plan skip_all => "check_mysql not compiled" unless (-x "check_mysql");
plan tests => 10;
my $bad_login_output = '/Access denied for user /';
my $mysqlserver = getTestParameter(
"NP_MYSQL_SERVER",
"A MySQL Server 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 $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 $result;
SKIP: {
skip "No mysql server defined", 5 unless $mysqlserver;
$result = NPTest->testCmd("./check_mysql -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, '==', 0, "Login okay");
$result = NPTest->testCmd("./check_mysql -H $mysqlserver -u dummy -pdummy");
cmp_ok( $result->return_code, '==', 2, "Login failure");
like( $result->output, $bad_login_output, "Expected login failure message");
$result = NPTest->testCmd("./check_mysql -S -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, "==", 1, "No slaves defined" );
like( $result->output, "/No slaves defined/", "Correct error message");
}
SKIP: {
skip "No mysql server with slaves defined", 5 unless $with_slave;
$result = NPTest->testCmd("./check_mysql -H $with_slave $with_slave_login");
cmp_ok( $result->return_code, '==', 0, "Login okay");
$result = NPTest->testCmd("./check_mysql -S -H $with_slave $with_slave_login");
cmp_ok( $result->return_code, "==", 0, "Slaves okay" );
$result = NPTest->testCmd("./check_mysql -S -H $with_slave $with_slave_login -w 60");
cmp_ok( $result->return_code, '==', 0, 'Slaves are not > 60 seconds behind');
$result = NPTest->testCmd("./check_mysql -S -H $with_slave $with_slave_login -w 60:");
cmp_ok( $result->return_code, '==', 1, 'Alert warning if < 60 seconds behind');
like( $result->output, "/^SLOW_SLAVE WARNING:/", "Output okay");
}

View file

@ -0,0 +1,66 @@
#! /usr/bin/perl -w -I ..
#
# MySQL Database Server Tests via check_mysql
#
# $Id: check_mysql_query.t,v 1.2 2006/02/01 13:23:38 tonvoon Exp $
#
#
# These are the database permissions required for this test:
# GRANT SELECT ON $db.* TO $user@$host IDENTIFIED BY '$password';
# Check with:
# mysql -u$user -p$password -h$host $db
use strict;
use Test::More;
use NPTest;
use vars qw($tests);
plan skip_all => "check_mysql_query not compiled" unless (-x "check_mysql_query");
my $mysqlserver = getTestParameter(
"NP_MYSQL_SERVER",
"A MySQL Server 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 $result;
if (! $mysqlserver) {
plan skip_all => "No mysql server defined";
} else {
plan tests => 13;
}
$result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, '==', 0, "Can run query");
$result = NPTest->testCmd("./check_mysql_query -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, '==', 3, "Missing query parmeter");
like( $result->output, "/Must specify a SQL query to run/", "Missing query error message");
$result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver -u dummy -d mysql");
cmp_ok( $result->return_code, '==', 2, "Login failure");
like( $result->output, "/Access denied for user /", "Expected login failure message");
$result = NPTest->testCmd("./check_mysql_query -q 'SELECT PI()' -w 3 -c 4 -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, '==', 1, "Got warning");
$result = NPTest->testCmd("./check_mysql_query -q 'SELECT PI()*2' -w 3 -c 4 -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, '==', 2, "Got critical");
$result = NPTest->testCmd("./check_mysql_query -q 'SELECT * FROM adsf' -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, '==', 2, "Bad query");
like( $result->output, "/Error with query/", "Bad query error message");
$result = NPTest->testCmd("./check_mysql_query -q 'SHOW VARIABLES LIKE \"bob\"' -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, '==', 1, "No rows");
like( $result->output, "/No rows returned/", "No rows error message");
$result = NPTest->testCmd("./check_mysql_query -q 'SHOW VARIABLES' -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, '==', 2, "Data not numeric");
like( $result->output, "/Is not a numeric/", "Data not numeric error message");

View file

@ -0,0 +1,5 @@
# Nagios 1.2 Status File
[1133537544] PROGRAM;1133537484;21980;1;1133537534;0;1;1;1;1;0;1;1;1
[1133537544] HOST;ADSL;PENDING;0;0;0;0;0;0;0;0;1;1;1;1;0;0.0;0;1;1;(Not enough data to determine host status yet)
[1133537544] HOST;Internet;UP;1133537486;1132135282;0;1402203;0;0;0;0;1;1;1;1;0;0.00;0;1;1;(Host assumed to be up)
[1133537544] SERVICE;Internet;TCP/IP;OK;1/3;HARD;1133537486;1133537786;ACTIVE;1;1;1;1132135282;0;OK;1402203;0;0;0;0;0;1;0;4;1;0;0.00;0;1;1;0;PING OK - Packet loss = 0%, RTA = 0.09 ms

View file

@ -0,0 +1,127 @@
########################################
# NAGIOS STATUS FILE
#
# THIS FILE IS AUTOMATICALLY GENERATED
# BY NAGIOS. DO NOT MODIFY THIS FILE!
########################################
info {
created=1133537302
version=2.0b5
}
program {
modified_host_attributes=0
modified_service_attributes=0
nagios_pid=2750
daemon_mode=1
program_start=1133537167
last_command_check=1133537297
last_log_rotation=0
enable_notifications=1
active_service_checks_enabled=1
passive_service_checks_enabled=1
active_host_checks_enabled=1
passive_host_checks_enabled=1
enable_event_handlers=1
obsess_over_services=0
obsess_over_hosts=0
check_service_freshness=1
check_host_freshness=0
enable_flap_detection=1
enable_failure_prediction=1
process_performance_data=0
global_host_event_handler=
global_service_event_handler=
}
host {
host_name=ADSL-derby-office
modified_attributes=0
check_command=check_host_alive_ping
event_handler=
has_been_checked=0
should_be_scheduled=0
check_execution_time=0.000
check_latency=0.000
check_type=0
current_state=0
last_hard_state=0
plugin_output=
performance_data=
last_check=0
next_check=0
current_attempt=1
max_attempts=3
state_type=1
last_state_change=0
last_hard_state_change=0
last_time_up=0
last_time_down=0
last_time_unreachable=0
last_notification=0
next_notification=0
no_more_notifications=0
current_notification_number=0
notifications_enabled=1
problem_has_been_acknowledged=0
acknowledgement_type=0
active_checks_enabled=1
passive_checks_enabled=1
event_handler_enabled=1
flap_detection_enabled=1
failure_prediction_enabled=1
process_performance_data=1
obsess_over_host=1
last_update=1133537302
is_flapping=0
percent_state_change=0.00
scheduled_downtime_depth=0
}
service {
host_name=ADSL-derby-office
service_description=TCP/IP
modified_attributes=0
check_command=host5_service23_check_ping
event_handler=
has_been_checked=0
should_be_scheduled=1
check_execution_time=0.000
check_latency=0.000
check_type=0
current_state=0
last_hard_state=0
current_attempt=1
max_attempts=3
state_type=1
last_state_change=0
last_hard_state_change=0
last_time_ok=0
last_time_warning=0
last_time_unknown=0
last_time_critical=0
plugin_output=(Service assumed to be ok)
performance_data=
last_check=0
next_check=1133537317
current_notification_number=0
last_notification=0
next_notification=0
no_more_notifications=0
notifications_enabled=0
active_checks_enabled=1
passive_checks_enabled=1
event_handler_enabled=1
problem_has_been_acknowledged=0
acknowledgement_type=0
flap_detection_enabled=1
failure_prediction_enabled=1
process_performance_data=1
obsess_over_service=0
last_update=1133537302
is_flapping=0
percent_state_change=0.00
scheduled_downtime_depth=0
}

87
plugins/t/check_nagios.t Normal file
View file

@ -0,0 +1,87 @@
#! /usr/bin/perl -w -I ..
#
# check_nagios tests
#
# $Id: check_nagios.t,v 1.2 2006/04/19 09:33:44 tonvoon Exp $
#
use strict;
use Test::More tests => 13;
use NPTest;
my $successOutput = '/^NAGIOS OK: /';
my $warningOutput = '/^NAGIOS WARNING: /';
my $failureOutput = '/^NAGIOS CRITICAL: /';
my $nagios1 = "t/check_nagios.nagios1.status.log";
my $nagios2 = "t/check_nagios.nagios2.status.dat";
my $result;
# Did use init, but MacOSX 10.4 replaces init with launchd
# Alternative is to insist that nagios is running to run this test
# Reasonable to expect cron because build servers will
# invoke cron to run a build
my $procname = "cron";
$result = NPTest->testCmd(
"./check_nagios -F $nagios1 -e 5 -C $procname"
);
cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" );
like ( $result->output, $warningOutput, "Output for warning correct" );
my $now = time;
# This substitution is dependant on the testcase
system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
$result = NPTest->testCmd(
"./check_nagios -F $nagios1.tmp -e 1 -C $procname"
);
cmp_ok( $result->return_code, "==", 0, "Log up to date" );
like ( $result->output, $successOutput, "Output for success correct" );
my $later = $now - 61;
system( "perl -pe 's/1133537544/$later/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
$result = NPTest->testCmd(
"./check_nagios -F $nagios1.tmp -e 1 -C $procname"
);
cmp_ok( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" );
my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
$result = NPTest->testCmd(
"./check_nagios -F $nagios1.tmp -e 5 -C unlikely_command_string"
);
cmp_ok( $result->return_code, "==", 2, "Nagios command not found" );
like ( $result->output, $failureOutput, "Output for failure correct" );
$result = NPTest->testCmd(
"./check_nagios -F $nagios2 -e 5 -C $procname"
);
cmp_ok( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" );
$now = time;
system( "perl -pe 's/1133537302/$now/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
$result = NPTest->testCmd(
"./check_nagios -F $nagios2.tmp -e 1 -C $procname"
);
cmp_ok( $result->return_code, "==", 0, "Nagios2 log up to date" );
$later = $now - 61;
system( "perl -pe 's/1133537302/$later/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
$result = NPTest->testCmd(
"./check_nagios -F $nagios2.tmp -e 1 -C $procname"
);
cmp_ok( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" );
($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
$result = NPTest->testCmd(
"./check_nagios -F t/check_nagios.t -e 1 -C $procname"
);
cmp_ok( $result->return_code, "==", 2, "Invalid log file" );

57
plugins/t/check_ntp.t Normal file
View file

@ -0,0 +1,57 @@
#! /usr/bin/perl -w -I ..
#
# Testing NTP
#
# $Id: check_ntp.t,v 1.2 2006/08/14 08:42:23 tonvoon Exp $
#
use strict;
use Test::More;
use NPTest;
plan tests => 4;
my $res;
my $ntp_service = getTestParameter( "NP_GOOD_NTP_SERVICE",
"A host providing NTP service",
"pool.ntp.org");
my $no_ntp_service = getTestParameter( "NP_NO_NTP_SERVICE",
"A host NOT providing the NTP service",
"localhost" );
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",
"nosuchhost");
SKIP: {
skip "No NTP server defined", 1 unless $ntp_service;
$res = NPTest->testCmd(
"./check_ntp -H $ntp_service"
);
cmp_ok( $res->return_code, '==', 0, "Got good NTP result");
}
SKIP: {
skip "No bad NTP server defined", 1 unless $no_ntp_service;
$res = NPTest->testCmd(
"./check_ntp -H $no_ntp_service"
);
cmp_ok( $res->return_code, '==', 2, "Got bad NTP result");
}
$res = NPTest->testCmd(
"./check_ntp -H $host_nonresponsive"
);
cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding");
$res = NPTest->testCmd(
"./check_ntp -H $hostname_invalid"
);
cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid");

37
plugins/t/check_ping.t Normal file
View file

@ -0,0 +1,37 @@
#! /usr/bin/perl -w -I ..
#
# Ping Response Tests via check_ping
#
# $Id: check_ping.t,v 1.3 2005/09/15 08:39:23 tonvoon Exp $
#
use strict;
use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 8; plan tests => $tests}
my $successOutput = '/PING (ok|OK) - Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/';
my $failureOutput = '/Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/';
my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost",
"The hostname of system responsive to network requests" );
my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
"The hostname of system not responsive to network requests" );
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
my $t;
$t += checkCmd( "./check_ping $host_responsive 100 100 1000 1000 -p 1", 0, $successOutput );
$t += checkCmd( "./check_ping $host_responsive 0 0 0 0 -p 1", 2, $failureOutput );
$t += checkCmd( "./check_ping $host_nonresponsive 0 0 0 0 -p 1 -to 1", 2 );
$t += checkCmd( "./check_ping $hostname_invalid 0 0 0 0 -p 1 -to 1", 3 );
$t += checkCmd( "./check_ping -w 100,10% -c 200,20%" , 3 , "/You must specify a server address or host name.*/");
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

56
plugins/t/check_pop.t Normal file
View file

@ -0,0 +1,56 @@
#! /usr/bin/perl -w -I ..
#
# Post Office Protocol (POP) Server Tests via check_pop
#
# $Id: check_pop.t,v 1.3 2006/03/22 15:45:49 tonvoon Exp $
#
use strict;
use Test::More;
use NPTest;
plan tests => 5;
my $host_tcp_smtp = getTestParameter(
"NP_HOST_TCP_SMTP",
"A host providing an STMP Service (a mail server)",
"mailhost"
);
my $host_tcp_pop = getTestParameter(
"NP_HOST_TCP_POP",
"A host providing a POP Service (a mail server)",
$host_tcp_smtp
);
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",
"nosuchhost",
);
my %exceptions = ( 2 => "No POP Server present?" );
my $t;
my $res;
$res = NPTest->testCmd( "./check_pop $host_tcp_pop" );
cmp_ok( $res->return_code, '==', 0, "POP server ok");
$res = NPTest->testCmd( "./check_pop -H $host_tcp_pop -p 110 -w 9 -c 9 -t 10 -e '+OK'");
cmp_ok( $res->return_code, '==', 0, "POP server returned +OK");
$res = NPTest->testCmd( "./check_pop $host_tcp_pop -p 110 -wt 9 -ct 9 -to 10 -e '+OK'");
cmp_ok( $res->return_code, '==', 0, "Old syntax");
$res = NPTest->testCmd( "./check_pop $host_nonresponsive" );
cmp_ok( $res->return_code, '==', 2, "Non responsive host");
$res = NPTest->testCmd( "./check_pop $hostname_invalid" );
cmp_ok( $res->return_code, '==', 2, "Invalid host");

25
plugins/t/check_procs.t Normal file
View file

@ -0,0 +1,25 @@
#! /usr/bin/perl -w -I ..
#
# Process Tests via check_procs
#
# $Id: check_procs.t,v 1.5 2005/11/03 15:13:13 tonvoon Exp $
#
use strict;
use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 12; plan tests => $tests}
my $t;
$t += checkCmd( "./check_procs -w 100000 -c 100000", 0, '/^PROCS OK: [0-9]+ process(es)?$/' );
$t += checkCmd( "./check_procs -w 100000 -c 100000 -s Z", 0, '/^PROCS OK: [0-9]+ process(es)? with /' );
$t += checkCmd( "./check_procs -w 0 -c 10000000", 1, '/^PROCS WARNING: [0-9]+ process(es)?$/' );
$t += checkCmd( "./check_procs -w 0 -c 0", 2, '/^PROCS CRITICAL: [0-9]+ process(es)?$/' );
$t += checkCmd( "./check_procs -w 0 -c 0 -s S", 2, '/^PROCS CRITICAL: [0-9]+ process(es)? with /' );
$t += checkCmd( "./check_procs -w 0 -c 10000000 -p 1", 1, '/^PROCS WARNING: [0-9]+ process(es)? with PPID = 1/' );
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

67
plugins/t/check_smtp.t Normal file
View file

@ -0,0 +1,67 @@
#! /usr/bin/perl -w -I ..
#
# Simple Mail Transfer Protocol (SMTP) Test via check_smtp
#
# $Id: check_smtp.t,v 1.4 2006/10/19 11:56:34 tonvoon Exp $
#
use strict;
use Test::More;
use NPTest;
my $host_tcp_smtp = getTestParameter( "NP_HOST_TCP_SMTP",
"A host providing an SMTP Service (a mail server)", "mailhost");
my $host_tcp_smtp_tls = getTestParameter( "NP_HOST_TCP_SMTP_TLS",
"A host providing SMTP with TLS", $host_tcp_smtp);
my $host_tcp_smtp_notls = getTestParameter( "NP_HOST_TCP_SMTP_NOTLS",
"A host providing SMTP without TLS", "");
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", "nosuchhost" );
my $res;
plan tests => 10;
SKIP: {
skip "No SMTP server defined", 4 unless $host_tcp_smtp;
$res = NPTest->testCmd( "./check_smtp $host_tcp_smtp" );
is ($res->return_code, 0, "OK");
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -w 9 -c 9 -t 10 -e 220" );
is ($res->return_code, 0, "OK, within 9 second response");
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -p 25 -wt 9 -ct 9 -to 10 -e 220" );
is ($res->return_code, 0, "OK, old syntax");
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp -e 221" );
is ($res->return_code, 1, "WARNING - got correct error when expecting 221 instead of 220" );
TODO: {
local $TODO = "Output is over two lines";
like ( $res->output, qr/^SMTP WARNING/, "Correct error message" );
}
}
SKIP: {
skip "No SMTP server with TLS defined", 1 unless $host_tcp_smtp_tls;
# SSL connection for TLS
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p 25 -S" );
is ($res->return_code, 0, "OK, with STARTTLS" );
}
SKIP: {
skip "No SMTP server without TLS defined", 2 unless $host_tcp_smtp_notls;
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_notls -p 25 -S" );
is ($res->return_code, 1, "OK, got warning from server without TLS");
is ($res->output, "WARNING - TLS not supported by server", "Right error message" );
}
$res = NPTest->testCmd( "./check_smtp $host_nonresponsive" );
is ($res->return_code, 2, "CRITICAL - host non responding" );
$res = NPTest->testCmd( "./check_smtp $hostname_invalid" );
is ($res->return_code, 3, "UNKNOWN - hostname invalid" );

57
plugins/t/check_snmp.t Normal file
View file

@ -0,0 +1,57 @@
#! /usr/bin/perl -w -I ..
#
# Simple Network Management Protocol (SNMP) Test via check_snmp
#
# $Id: check_snmp.t,v 1.2 2005/07/25 01:47:15 illumino Exp $
#
use strict;
use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 12; plan tests => $tests}
my $t;
if ( -x "./check_snmp" )
{
my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost",
"A host providing an SNMP Service");
my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
"The SNMP Community string for SNMP Testing" );
my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
"The hostname of system not responsive to network requests" );
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
my %exceptions = ( 3 => "No SNMP Server present?" );
$t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:",
{ 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - \d+/', %exceptions );
$t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1",
{ 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - 1\s*$/', %exceptions );
$t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:",
{ 1 => 'continue', 3 => 'skip' }, '/^SNMP WARNING - \*1\*\s*$/', %exceptions );
$t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0",
{ 2 => 'continue', 3 => 'skip' }, '/^SNMP CRITICAL - \*1\*\s*$/', %exceptions );
$t += checkCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' );
$t += checkCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' );
}
else
{
$t += skipMissingCmd( "./check_snmp", $tests );
}
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

32
plugins/t/check_swap.t Normal file
View file

@ -0,0 +1,32 @@
#! /usr/bin/perl -w -I ..
#
# Swap Space Tests via check_swap
#
# $Id: check_swap.t,v 1.3 2005/11/09 16:40:12 tonvoon Exp $
#
use strict;
use Test::More tests => 8;
use NPTest;
my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
my $result;
$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free
cmp_ok( $result->return_code, "==", 0, "At least 1MB free" );
like( $result->output, $successOutput, "Right output" );
$result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free
cmp_ok( $result->return_code, "==", 0, 'At least 1% free' );
like( $result->output, $successOutput, "Right output" );
$result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical)
cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
like( $result->output, $failureOutput, "Right output" );
$result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn)
cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
like( $result->output, $warnOutput, "Right output" );

34
plugins/t/check_tcp.t Normal file
View file

@ -0,0 +1,34 @@
#! /usr/bin/perl -w -I ..
#
# TCP Connection Based Tests via check_tcp
#
# $Id: check_tcp.t,v 1.3 2005/07/25 01:47:15 illumino Exp $
#
use strict;
use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 5; plan tests => $tests}
my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost",
"A host providing the HTTP Service (a web server)" );
my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
"The hostname of system not responsive to network requests" );
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/';
my $t;
$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 );
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

42
plugins/t/check_time.t Normal file
View file

@ -0,0 +1,42 @@
#! /usr/bin/perl -w -I ..
#
# System Time Tests via check_time
#
# $Id: check_time.t,v 1.3 2005/11/03 15:04:16 tonvoon Exp $
#
use strict;
use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 8; plan tests => $tests}
my $host_udp_time = getTestParameter( "host_udp_time", "NP_HOST_UDP_TIME", "localhost",
"A host providing the UDP Time Service" );
my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
"The hostname of system not responsive to network requests" );
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
my $successOutput = '/^TIME OK - [0-9]+ second time difference/';
my %exceptions = ( 3 => "No time server present?");
my $t;
# standard mode
$t += checkCmd( "./check_time -H $host_udp_time -w 999999,59 -c 999999,59 -t 60", 0, $successOutput, %exceptions );
$t += checkCmd( "./check_time -H $host_udp_time -w 999999 -W 59 -c 999999 -C 59 -t 60", 0, $successOutput, %exceptions );
# reverse compatibility mode
$t += checkCmd( "./check_time $host_udp_time -wt 59 -ct 59 -cd 999999 -wd 999999 -to 60", 0, $successOutput, %exceptions );
# failure mode
$t += checkCmd( "./check_time -H $host_nonresponsive -t 1", 2 );
$t += checkCmd( "./check_time -H $hostname_invalid -t 1", 3 );
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

56
plugins/t/check_udp.t Normal file
View file

@ -0,0 +1,56 @@
#! /usr/bin/perl -w -I ..
#
# UDP Connection Based Tests via check_udp
#
# $Id: check_udp.t,v 1.6 2006/07/28 22:44:11 tonvoon Exp $
#
use strict;
use Test::More;
use NPTest;
my $res;
plan tests => 14;
$res = NPTest->testCmd( "./check_udp -H localhost -p 3333" );
cmp_ok( $res->return_code, '==', 3, "Need send/expect string");
like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
$res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s send" );
cmp_ok( $res->return_code, '==', 3, "Need expect string");
like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
$res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -e expect" );
cmp_ok( $res->return_code, '==', 3, "Need send string");
like ( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
$res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s foo -e bar" );
cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" );
like ( $res->output, '/No data received from host/', "Output OK");
SKIP: {
skip "No netcat available", 6 unless (system("which nc > /dev/null") == 0);
open (NC, "echo 'barbar' | nc -l -p 3333 -u |");
sleep 1;
$res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s '' -e barbar -4" );
cmp_ok( $res->return_code, '==', 0, "Got barbar response back" );
like ( $res->output, '/\[barbar\]/', "Output OK");
close NC;
# Start up a udp server listening on port 3333, quit after 3 seconds
# Otherwise will hang at close
my $pid = open(NC, "nc -l -p 3333 -u -w 3 </dev/null |");
sleep 1; # Allow nc to startup
my $start = time;
$res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s foofoo -e barbar -t 5 -4" );
my $duration = time - $start;
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>;
close NC;
cmp_ok( $read_nc, 'eq', "foofoo", "Data received correctly" );
}

25
plugins/t/check_users.t Normal file
View file

@ -0,0 +1,25 @@
#! /usr/bin/perl -w -I ..
#
# Logged in Users Tests via check_users
#
# $Id: check_users.t,v 1.2 2005/07/25 01:47:15 illumino Exp $
#
use strict;
use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 4; plan tests => $tests}
my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/';
my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/';
my $t;
$t += checkCmd( "./check_users 1000 1000", 0, $successOutput );
$t += checkCmd( "./check_users 0 0", 2, $failureOutput );
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);