Imported Upstream version 1.4.10

This commit is contained in:
Jan Wagner 2013-11-26 23:54:42 +01:00
parent 6dd54dd8e2
commit cff68b4c0a
203 changed files with 15026 additions and 8063 deletions

View file

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

83
plugins/t/check_cluster.t Normal file
View file

@ -0,0 +1,83 @@
#! /usr/bin/perl -w -I ..
#
# check_cluster tests
#
# $Id: check_cluster.t 1702 2007-04-28 21:57:17Z psychotrahe $
#
use strict;
use Test::More tests => 15;
use NPTest;
my $result;
$result = NPTest->testCmd(
"./check_cluster -s -w 0:0 -c 0:0 -d 0,0,0,0"
);
cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok services are inside critical and warning ranges" );
like( $result->output, qr/service/i, "Output contains the word 'service' (case insensitive)");
$result = NPTest->testCmd(
"./check_cluster -l LABEL -s -w 0:0 -c 0:0 -d 0,0,0,0"
);
like( $result->output, qr/LABEL/, "Output contains the defined label 'LABEL' (case sensitive)");
$result = NPTest->testCmd(
"./check_cluster -s -w 0:0 -c 0:1 -d 0,0,0,1"
);
cmp_ok( $result->return_code, '==', 1, "Exit WARNING if non-ok services are inside critical and outside warning ranges" );
$result = NPTest->testCmd(
"./check_cluster -s -w 0:0 -c 0:1 -d 0,0,1,1"
);
cmp_ok( $result->return_code, '==', 2, "Exit CRITICAL if non-ok services are inside critical and outside warning ranges" );
$result = NPTest->testCmd(
"./check_cluster -s -w 0 -c 0 -d 0,0,0,0"
);
cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok services are inside critical and warning (no ranges)" );
$result = NPTest->testCmd(
"./check_cluster -s -w 0 -c 1 -d 0,0,1,0"
);
cmp_ok( $result->return_code, '==', 1, "Exit WARNING if number of non-ok services exceed warning (no ranges)" );
$result = NPTest->testCmd(
"./check_cluster -s -w 0 -c 1 -d 0,0,1,1"
);
cmp_ok( $result->return_code, '==', 2, "Exit Critical if non-ok services exceed critical warning (no ranges)" );
#
# And for hosts..
#
$result = NPTest->testCmd(
"./check_cluster -h -w 0:0 -c 0:0 -d 0,0,0,0"
);
cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok hosts are inside critical and warning ranges" );
like( $result->output, qr/host/i, "Output contains the word 'host' (case insensitive)");
$result = NPTest->testCmd(
"./check_cluster -h -w 0:0 -c 0:1 -d 0,0,0,1"
);
cmp_ok( $result->return_code, '==', 1, "Exit WARNING if non-ok hosts are inside critical and outside warning ranges" );
$result = NPTest->testCmd(
"./check_cluster -h -w 0:0 -c 0:1 -d 0,0,1,1"
);
cmp_ok( $result->return_code, '==', 2, "Exit CRITICAL if non-ok hosts are inside critical and outside warning ranges" );
$result = NPTest->testCmd(
"./check_cluster -h -w 0 -c 0 -d 0,0,0,0"
);
cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok hosts are inside critical and warning (no ranges)" );
$result = NPTest->testCmd(
"./check_cluster -h -w 0 -c 1 -d 0,0,1,0"
);
cmp_ok( $result->return_code, '==', 1, "Exit WARNING if number of non-ok hosts exceed warning (no ranges)" );
$result = NPTest->testCmd(
"./check_cluster -h -w 0 -c 1 -d 0,0,1,1"
);
cmp_ok( $result->return_code, '==', 2, "Exit Critical if non-ok hosts exceed critical warning (no ranges)" );

View file

@ -2,7 +2,7 @@
#
# Disk Space Tests via check_disk
#
# $Id: check_disk.t,v 1.20 2007/03/30 09:00:06 psychotrahe Exp $
# $Id: check_disk.t 1786 2007-09-22 17:40:35Z psychotrahe $
#
# TODO: Add in tests for perf data. Need to beef up Nagios::Plugin::Performance to cater for max, min, etc
@ -24,7 +24,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
plan skip_all => "Need 2 mountpoints to test";
} else {
plan tests => 68;
plan tests => 78;
}
$result = NPTest->testCmd(
@ -114,10 +114,8 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text");
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" );
cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free");
$_ = $result->output;
print $result->output."\n";
my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g);
my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
print "$free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2\n";
@ -255,6 +253,7 @@ 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");
like ( $result->only_output, qr(^[^;]*;[^;]*$), "Select only one path with positional arguments");
$result = NPTest->testCmd( "./check_disk 100 100 $mountpoint_valid" );
cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" );
@ -276,7 +275,7 @@ TODO: {
$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');
like( $result->output, '/^DISK CRITICAL - /bob is not accessible:.*$/', 'Output OK');
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /" );
my $root_output = $result->output;
@ -285,9 +284,15 @@ $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" );
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -E -p /etc " );
cmp_ok( $result->return_code, '==', 2, "... unless -E/--exact-match is specified");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc -E " );
cmp_ok( $result->return_code, '==', 3, "-E/--exact-match must be specified before -p");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -r /etc -E " );
cmp_ok( $result->return_code, '==', 3, "-E/--exact-match must be specified before -r");
$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");
@ -319,3 +324,24 @@ cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after grou
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" );
cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable");
# ignore: exit unknown, if all pathes are deselected using -i
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '$mountpoint_valid' -i '$mountpoint2_valid'" );
cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case sensitive)");
# ignore: exit unknown, if all pathes are deselected using -I
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -I '".uc($mountpoint_valid)."' -I '".uc($mountpoint2_valid)."'" );
cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case insensitive)");
# ignore: exit unknown, if all pathes are deselected using -i
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '.*'" );
cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored using -i '.*'");
# ignore: test if ignored path is actually ignored
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^$mountpoint2_valid\$'");
like( $result->output, qr/$mountpoint_valid/, "output data does have $mountpoint_valid in it");
unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mountpoint2_valid in it");
# ignore: test if all pathes are listed when ignore regex doesn't match
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'");
like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match");
like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match");

View file

@ -2,7 +2,7 @@
#
# Domain Name Server (DNS) Tests via check_dns
#
# $Id: check_dns.t,v 1.7 2006/03/29 08:13:29 tonvoon Exp $
# $Id: check_dns.t 1361 2006-03-29 08:13:29Z tonvoon $
#
use strict;

55
plugins/t/check_dummy.t Normal file
View file

@ -0,0 +1,55 @@
#! /usr/bin/perl -w -I ..
#
# check_dummy tests
#
# $Id: check_dummy.t 1716 2007-05-24 08:35:53Z tonvoon $
#
use strict;
use Test::More;
use NPTest;
plan tests => 20;
my $res;
$res = NPTest->testCmd("./check_dummy");
is( $res->return_code, 3, "No args" );
like( $res->output, "/Could not parse arguments/", "Correct usage message");
$res = NPTest->testCmd("./check_dummy 0");
is( $res->return_code, 0, "OK state returned");
is( $res->output, "OK", "Says 'OK'");
$res = NPTest->testCmd("./check_dummy 0 'some random data'");
is( $res->return_code, 0, "Still OK");
is( $res->output, "OK: some random data", "Sample text okay");
$res = NPTest->testCmd("./check_dummy 1");
is( $res->return_code, 1, "Warning okay");
is( $res->output, "WARNING", "Says 'WARNING'");
$res = NPTest->testCmd("./check_dummy 1 'more stuff'");
is( $res->return_code, 1, "Still warning");
is( $res->output, "WARNING: more stuff", "optional text okay" );
$res = NPTest->testCmd("./check_dummy 2");
is( $res->return_code, 2, "Critical ok" );
is( $res->output, "CRITICAL", "Says 'CRITICAL'");
$res = NPTest->testCmd("./check_dummy 2 'roughly drafted'");
is( $res->return_code, 2, "Still critical");
is( $res->output, "CRITICAL: roughly drafted", "optional text okay" );
$res = NPTest->testCmd("./check_dummy 3");
is( $res->return_code, 3, "Unknown ok" );
is( $res->output, "UNKNOWN", "Says 'UNKNOWN'");
$res = NPTest->testCmd("./check_dummy 3 'daringfireball'");
is( $res->return_code, 3, "Still unknown");
is( $res->output, "UNKNOWN: daringfireball", "optional text okay" );
$res = NPTest->testCmd("./check_dummy 4");
is( $res->return_code, 3, "Invalid error code" );
is( $res->output, "UNKNOWN: Status 4 is not a supported error state", "With appropriate error message");

View file

@ -2,7 +2,7 @@
#
# FPing Tests via check_fping
#
# $Id: check_fping.t,v 1.2 2005/07/25 01:47:14 illumino Exp $
# $Id: check_fping.t 1207 2005-07-25 01:47:15Z illumino $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# File Transfer Protocol (FTP) Test via check_ftp
#
# $Id: check_ftp.t,v 1.3 2005/07/25 01:47:14 illumino Exp $
# $Id: check_ftp.t 1207 2005-07-25 01:47:15Z illumino $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# HP JetDirect Test via check_hpjd
#
# $Id: check_hpjd.t,v 1.3 2006/03/24 16:13:40 tonvoon Exp $
# $Id: check_hpjd.t 1354 2006-03-24 16:13:40Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# HyperText Transfer Protocol (HTTP) Test via check_http
#
# $Id: check_http.t,v 1.14 2007/04/01 14:21:09 psychotrahe Exp $
# $Id: check_http.t 1669 2007-04-01 14:21:09Z psychotrahe $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# 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 $
# $Id: check_imap.t 1279 2005-11-09 16:40:12Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Jabber Server Tests via check_jabber
#
# $Id: check_jabber.t,v 1.3 2007/02/01 06:53:12 dermoth Exp $
# $Id: check_jabber.t 1604 2007-02-01 06:53:12Z dermoth $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Load Average Tests via check_load
#
# $Id: check_load.t,v 1.6 2006/10/02 12:09:18 tonvoon Exp $
# $Id: check_load.t 1700 2007-04-25 22:10:13Z tonvoon $
#
use strict;
@ -14,7 +14,7 @@ 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;
plan tests => 6;
$res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" );
cmp_ok( $res->return_code, 'eq', 0, "load not over 100");
@ -24,3 +24,7 @@ $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");
$res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" );
cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division");
like( $res->output, $failureOutput, "Output OK");

View file

@ -2,7 +2,7 @@
#
# MySQL Database Server Tests via check_mysql
#
# $Id: check_mysql.t,v 1.8 2006/03/17 14:07:34 tonvoon Exp $
# $Id: check_mysql.t 1327 2006-03-17 14:07:34Z tonvoon $
#
#
# These are the database permissions required for this test:

View file

@ -2,7 +2,7 @@
#
# MySQL Database Server Tests via check_mysql
#
# $Id: check_mysql_query.t,v 1.2 2006/02/01 13:23:38 tonvoon Exp $
# $Id: check_mysql_query.t 1315 2006-02-01 13:23:38Z tonvoon $
#
#
# These are the database permissions required for this test:

View file

@ -2,7 +2,7 @@
#
# check_nagios tests
#
# $Id: check_nagios.t,v 1.2 2006/04/19 09:33:44 tonvoon Exp $
# $Id: check_nagios.t 1382 2006-04-19 09:33:44Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Testing NTP
#
# $Id: check_ntp.t,v 1.2 2006/08/14 08:42:23 tonvoon Exp $
# $Id: check_ntp.t 1468 2006-08-14 08:42:23Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Ping Response Tests via check_ping
#
# $Id: check_ping.t,v 1.5 2007/03/12 10:51:06 tonvoon Exp $
# $Id: check_ping.t 1639 2007-03-12 10:51:06Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Post Office Protocol (POP) Server Tests via check_pop
#
# $Id: check_pop.t,v 1.3 2006/03/22 15:45:49 tonvoon Exp $
# $Id: check_pop.t 1345 2006-03-22 15:45:49Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Process Tests via check_procs
#
# $Id: check_procs.t,v 1.5 2005/11/03 15:13:13 tonvoon Exp $
# $Id: check_procs.t 1271 2005-11-03 15:13:13Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Simple Mail Transfer Protocol (SMTP) Test via check_smtp
#
# $Id: check_smtp.t,v 1.4 2006/10/19 11:56:34 tonvoon Exp $
# $Id: check_smtp.t 1500 2006-10-19 11:56:34Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Simple Network Management Protocol (SNMP) Test via check_snmp
#
# $Id: check_snmp.t,v 1.3 2006/12/23 18:59:36 dermoth Exp $
# $Id: check_snmp.t 1557 2006-12-23 18:59:36Z dermoth $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Swap Space Tests via check_swap
#
# $Id: check_swap.t,v 1.3 2005/11/09 16:40:12 tonvoon Exp $
# $Id: check_swap.t 1279 2005-11-09 16:40:12Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# TCP Connection Based Tests via check_tcp
#
# $Id: check_tcp.t,v 1.5 2007/02/14 10:11:07 tonvoon Exp $
# $Id: check_tcp.t 1714 2007-05-18 07:17:59Z dermoth $
#
use strict;
@ -34,7 +34,7 @@ $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 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
$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -E -s ".'"GET /\r\n\r\n"'." -e 'ThisShouldntMatch' -j", 1, $failedExpect );
$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -E -s ".'"GET / HTTP/1.1\r\n\r\n"'." -e 'ThisShouldntMatch' -j", 1, $failedExpect );
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

View file

@ -2,7 +2,7 @@
#
# System Time Tests via check_time
#
# $Id: check_time.t,v 1.3 2005/11/03 15:04:16 tonvoon Exp $
# $Id: check_time.t 1270 2005-11-03 15:04:16Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# UDP Connection Based Tests via check_udp
#
# $Id: check_udp.t,v 1.6 2006/07/28 22:44:11 tonvoon Exp $
# $Id: check_udp.t 1459 2006-07-28 22:44:11Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Logged in Users Tests via check_users
#
# $Id: check_users.t,v 1.2 2005/07/25 01:47:15 illumino Exp $
# $Id: check_users.t 1207 2005-07-25 01:47:15Z illumino $
#
use strict;

72
plugins/t/negate.t Normal file
View file

@ -0,0 +1,72 @@
#! /usr/bin/perl -w -I ..
#
# negate checks
# Need check_dummy to work for testing
#
# $Id: negate.pl 1717 2007-05-24 08:53:50Z tonvoon $
#
use strict;
use Test::More;
use NPTest;
# 15 tests in the first part and 32 in the last loop
plan tests => 47;
my $res;
my $PWD = $ENV{PWD};
$res = NPTest->testCmd( "./negate" );
is( $res->return_code, 3, "Not enough parameters");
like( $res->output, "/Could not parse arguments/", "Could not parse arguments");
$res = NPTest->testCmd( "./negate bobthebuilder" );
is( $res->return_code, 3, "Require full path" );
like( $res->output, "/Require path to command/", "Appropriate error message");
$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" );
is( $res->return_code, 2, "OK changed to CRITICAL" );
is( $res->output, "OK: a dummy okay", "Output as expected" );
$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0 redsweaterblog'");
is( $res->return_code, 2, "OK => CRIT with a single quote for command to run" );
is( $res->output, "OK: redsweaterblog", "Output as expected" );
$res = NPTest->testCmd( "./negate $PWD/check_dummy 1 'a warn a day keeps the managers at bay'" );
is( $res->return_code, 1, "WARN stays same" );
$res = NPTest->testCmd( "./negate $PWD/check_dummy 3 mysterious");
is( $res->return_code, 3, "UNKNOWN stays same" );
$res = NPTest->testCmd( "./negate \"$PWD/check_dummy 0 'a dummy okay'\"" );
is( $res->output, "OK: a dummy okay", "Checking slashed quotes - the single quotes are re-evaluated at shell" );
# Output is "OK: a" because check_dummy only returns the first arg
$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 a dummy okay" );
is( $res->output, "OK: a", "Multiple args passed as arrays" );
$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" );
is( $res->output, "OK: a dummy okay", "The quoted string is passed through to subcommand correctly" );
$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" );
is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')");
$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' );
is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' );
my %state = (
ok => 0,
warning => 1,
critical => 2,
unknown => 3,
);
foreach my $current_state (qw(ok warning critical unknown)) {
foreach my $new_state (qw(ok warning critical unknown)) {
$res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
is( $res->return_code, $state{$new_state}, "Got fake $new_state" );
is( $res->output, uc($current_state).": Fake $new_state" );
}
}