Imported Upstream version 1.4.12

This commit is contained in:
Jan Wagner 2013-11-26 23:55:28 +01:00
parent 1d1585cd09
commit 4ab9f0d24c
291 changed files with 27277 additions and 11364 deletions

147
plugins/t/check_by_ssh.t Normal file
View file

@ -0,0 +1,147 @@
#! /usr/bin/perl -w -I ..
#
# check_by_ssh tests
#
# $Id$
#
use strict;
use Test::More;
use NPTest;
# Required parameters
my $ssh_service = getTestParameter( "NP_SSH_HOST",
"A host providing SSH service",
"localhost");
my $ssh_key = getTestParameter( "NP_SSH_IDENTITY",
"A key allowing access to NP_SSH_HOST",
"~/.ssh/id_dsa");
plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key);
plan tests => 40;
# Some random check strings/response
my @responce = ('OK: Everything is fine!',
'WARNING: Hey, pick me, pick me!',
'CRITICAL: Shit happens...',
'UNKNOWN: What can I do for ya?',
'WOOPS: What did I smoke?',
);
my @responce_re;
my @check;
for (@responce) {
push(@check, "echo $_");
my $re_str = $_;
$re_str =~ s{(.)} { "\Q$1" }ge;
push(@responce_re, $re_str);
}
my $result;
## Single active checks
for (my $i=0; $i<4; $i++) {
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'"
);
cmp_ok($result->return_code, '==', $i, "Exit with return code $i");
is($result->output, $responce[$i], "Status text is correct for check $i");
}
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 0'"
);
cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)");
is($result->output, 'OK - check_by_ssh: Remote command \'exit 0\' returned status 0', "Status text if command returned none (OK)");
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 1'"
);
cmp_ok($result->return_code, '==', 1, "Exit with return code 1 (WARNING)");
is($result->output, 'WARNING - check_by_ssh: Remote command \'exit 1\' returned status 1', "Status text if command returned none (WARNING)");
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 2'"
);
cmp_ok($result->return_code, '==', 2, "Exit with return code 2 (CRITICAL)");
is($result->output, 'CRITICAL - check_by_ssh: Remote command \'exit 2\' returned status 2', "Status text if command returned none (CRITICAL)");
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 3'"
);
cmp_ok($result->return_code, '==', 3, "Exit with return code 3 (UNKNOWN)");
is($result->output, 'UNKNOWN - check_by_ssh: Remote command \'exit 3\' returned status 3', "Status text if command returned none (UNKNOWN)");
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -C 'exit 7'"
);
cmp_ok($result->return_code, '==', 7, "Exit with return code 7 (out of bounds)");
is($result->output, 'UNKNOWN - check_by_ssh: Remote command \'exit 7\' returned status 7', "Status text if command returned none (out of bounds)");
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'"
);
cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)");
is($result->output, $responce[4], "Return proper status text even with unknown status codes");
# Multiple active checks
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[1]; sh -c exit\\ 1' -C '$check[0]; sh -c exit\\ 0' -C '$check[3]; sh -c exit\\ 3' -C '$check[2]; sh -c exit\\ 2'"
);
cmp_ok($result->return_code, '==', 0, "Multiple checks always return OK");
my @lines = split(/\n/, $result->output);
cmp_ok(scalar(@lines), '==', 8, "Correct number of output lined for multiple checks");
my %linemap = (
'0' => '1',
'2' => '0',
'4' => '3',
'6' => '2',
);
foreach my $line (0, 2, 4, 6) {
my $code = $linemap{$line};
my $statline = $line+1;
is($lines[$line], "$responce[$code]", "multiple checks status text is correct for line $line");
is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line");
}
# Passive checks
unlink("/tmp/check_by_ssh.$$");
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -n flint -s serv -C '$check[2]; sh -c exit\\ 2' -O /tmp/check_by_ssh.$$"
);
cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks");
open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!");
my @pasv = <PASV>;
close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!");
cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed');
for (0) {
if ($pasv[$_]) {
like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $responce_re[2] . '$/', 'proper result for passive check');
} else {
fail('proper result for passive check');
}
}
unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!");
undef @pasv;
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -n flint -s c0:c1:c2:c3:c4 -C '$check[0];sh -c exit\\ 0' -C '$check[1];sh -c exit\\ 1' -C '$check[2];sh -c exit\\ 2' -C '$check[3];sh -c exit\\ 3' -C '$check[4];sh -c exit\\ 9' -O /tmp/check_by_ssh.$$"
);
cmp_ok($result->return_code, '==', 0, "Exit always ok on passive checks");
open(PASV, "/tmp/check_by_ssh.$$") or die("Unable to open '/tmp/check_by_ssh.$$': $!");
@pasv = <PASV>;
close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!");
cmp_ok(scalar(@pasv), '==', 5, 'Five passive result for five checks performed');
for (0, 1, 2, 3, 4) {
if ($pasv[$_]) {
my $ret = $_;
$ret = 9 if ($_ == 4);
like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $responce_re[$_] . '$/', "proper result for passive check $_");
} else {
fail("proper result for passive check $_");
}
}
unlink("/tmp/check_by_ssh.$$") or die("Unable to unlink '/tmp/check_by_ssh.$$': $!");

View file

@ -2,7 +2,7 @@
#
# Domain Name Server (DNS) Tests via check_dns
#
# $Id: check_dns.t 1361 2006-03-29 08:13:29Z tonvoon $
# $Id: check_dns.t 1902 2008-01-08 16:05:36Z tonvoon $
#
use strict;
@ -18,19 +18,19 @@ my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
my $hostname_valid = getTestParameter(
"NP_HOSTNAME_VALID",
"A valid (known to DNS) hostname",
"apple.com"
"nagios.com"
);
my $hostname_valid_ip = getTestParameter(
"NP_HOSTNAME_VALID_IP",
"The IP address of the valid hostname $hostname_valid",
"17.254.3.183"
"66.118.156.50",
);
my $hostname_valid_reverse = getTestParameter(
"NP_HOSTNAME_VALID_REVERSE",
"The hostname of $hostname_valid_ip",
$hostname_valid."."
"66-118-156-50.static.sagonet.net.",
);
my $hostname_invalid = getTestParameter(

View file

@ -2,7 +2,7 @@
#
# File Transfer Protocol (FTP) Test via check_ftp
#
# $Id: check_ftp.t 1207 2005-07-25 01:47:15Z illumino $
# $Id: check_ftp.t 1901 2008-01-08 11:57:24Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Internet Mail Access Protocol (IMAP) Server Tests via check_imap
#
# $Id: check_imap.t 1279 2005-11-09 16:40:12Z tonvoon $
# $Id: check_imap.t 1901 2008-01-08 11:57:24Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Jabber Server Tests via check_jabber
#
# $Id: check_jabber.t 1604 2007-02-01 06:53:12Z dermoth $
# $Id: check_jabber.t 1901 2008-01-08 11:57:24Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# MySQL Database Server Tests via check_mysql
#
# $Id: check_mysql.t 1327 2006-03-17 14:07:34Z tonvoon $
# $Id: check_mysql.t 1988 2008-04-30 12:50:52Z dermoth $
#
#
# These are the database permissions required for this test:
@ -19,12 +19,16 @@ use vars qw($tests);
plan skip_all => "check_mysql not compiled" unless (-x "check_mysql");
plan tests => 10;
plan tests => 15;
my $bad_login_output = '/Access denied for user /';
my $mysqlserver = getTestParameter(
"NP_MYSQL_SERVER",
"A MySQL Server with no slaves setup"
"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 $mysql_login_details = getTestParameter(
"MYSQL_LOGIN_DETAILS",
@ -57,6 +61,20 @@ SKIP: {
like( $result->output, "/No slaves defined/", "Correct error message");
}
SKIP: {
skip "No mysql socket defined", 5 unless $mysqlsocket;
$result = NPTest->testCmd("./check_mysql -s $mysqlsocket $mysql_login_details");
cmp_ok( $result->return_code, '==', 0, "Login okay");
$result = NPTest->testCmd("./check_mysql -s $mysqlsocket -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 -s $mysqlsocket $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");

View file

@ -2,13 +2,19 @@
#
# check_nagios tests
#
# $Id: check_nagios.t 1382 2006-04-19 09:33:44Z tonvoon $
# $Id: check_nagios.t 1953 2008-03-17 23:08:21Z tonvoon $
#
use strict;
use Test::More tests => 13;
use Test::More;
use NPTest;
if (`uname -s` eq "SunOS\n") {
plan skip_all => "Ignoring tests on solaris because of pst3";
} else {
plan tests => 13;
}
my $successOutput = '/^NAGIOS OK: /';
my $warningOutput = '/^NAGIOS WARNING: /';
my $failureOutput = '/^NAGIOS CRITICAL: /';

View file

@ -2,7 +2,7 @@
#
# Post Office Protocol (POP) Server Tests via check_pop
#
# $Id: check_pop.t 1345 2006-03-22 15:45:49Z tonvoon $
# $Id: check_pop.t 1901 2008-01-08 11:57:24Z tonvoon $
#
use strict;

View file

@ -2,24 +2,44 @@
#
# Process Tests via check_procs
#
# $Id: check_procs.t 1271 2005-11-03 15:13:13Z tonvoon $
# $Id: check_procs.t 1937 2008-02-28 16:21:59Z tonvoon $
#
use strict;
use Test;
use Test::More;
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/' );
if (`uname -s` eq "SunOS\n") {
plan skip_all => "Ignoring tests on solaris because of pst3";
} else {
plan tests => 12;
}
my $result;
$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" );
is( $result->return_code, 0, "Checking less than 10000 processes" );
like( $result->output, '/^PROCS OK: [0-9]+ process(es)?$/', "Output correct" );
$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" );
$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)?$/', "Output correct" );
$result = NPTest->testCmd( "./check_procs -w 0 -c 0" );
is( $result->return_code, 2, "Checking critical if processes > 0" );
like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)?$/', "Output correct" );
$result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" );
is( $result->return_code, 2, "Checking critical if sleeping processes" );
like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? with /', "Output correct" );
$result = NPTest->testCmd( "./check_procs -w 0 -c 100000 -p 1" );
is( $result->return_code, 1, "Checking warning for processes by parentid = 1" );
like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? with PPID = 1/', "Output correct" );
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

View file

@ -2,7 +2,7 @@
#
# TCP Connection Based Tests via check_tcp
#
# $Id: check_tcp.t 1714 2007-05-18 07:17:59Z dermoth $
# $Id: check_tcp.t 1901 2008-01-08 11:57:24Z tonvoon $
#
use strict;