Imported Upstream version 1.4.16+git20130902

This commit is contained in:
Jan Wagner 2013-11-26 23:59:47 +01:00
parent e76be63abf
commit e70fb8c051
517 changed files with 44015 additions and 43295 deletions

90
plugins/t/check_apt.t Normal file
View file

@ -0,0 +1,90 @@
#!/usr/bin/perl -w -I ..
#
# Test check_apt using input files.
# Contributed by Alex Bradley, October 2012
#
use strict;
use Test::More;
use NPTest;
sub make_result_regexp {
my ($warning, $critical) = @_;
my $status;
if ($warning == 0 && $critical == 0) {
$status = "OK";
} elsif ($critical == 0) {
$status = "WARNING";
} else {
$status = "CRITICAL";
}
return sprintf('/^APT %s: %d packages available for upgrade \(%d critical updates\)\. |available_upgrades=%d;;;0 critical_updates=%d;;;0$/',
$status, $warning, $critical, $warning, $critical);
}
if (-x "./check_apt") {
plan tests => 28;
} else {
plan skip_all => "No check_apt compiled";
}
my $result;
my $testfile_command = "./check_apt %s --input-file=t/check_apt_input/%s";
$result = NPTest->testCmd( sprintf($testfile_command, "", "debian1") );
is( $result->return_code, 0, "No upgrades" );
like( $result->output, make_result_regexp(0, 0), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "", "debian2") );
is( $result->return_code, 1, "Debian apt output, warning" );
like( $result->output, make_result_regexp(13, 0), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") );
is( $result->return_code, 2, "Debian apt output, some critical" );
like( $result->output, make_result_regexp(19, 4), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "-c '^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)'", "debian3") );
is( $result->return_code, 2, "Debian apt output - should have same result when default security regexp specified via -c" );
like( $result->output, make_result_regexp(19, 4), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6", "debian3") );
is( $result->return_code, 1, "Debian apt output, filter for libc6" );
like( $result->output, make_result_regexp(3, 0), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen", "debian3") );
is( $result->return_code, 2, "Debian apt output, filter for libc6 and xen" );
like( $result->output, make_result_regexp(9, 4), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen -i linux", "debian3") );
is( $result->return_code, 2, "Debian apt output, filter for libc6, xen, linux" );
like( $result->output, make_result_regexp(12, 4), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6", "debian3") );
is( $result->return_code, 2, "Debian apt output, filter out libc6" );
like( $result->output, make_result_regexp(16, 4), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen", "debian3") );
is( $result->return_code, 1, "Debian apt output, filter out libc6 and xen" );
like( $result->output, make_result_regexp(10, 0), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen -e linux", "debian3") );
is( $result->return_code, 1, "Debian apt output, filter out libc6, xen, linux" );
like( $result->output, make_result_regexp(7, 0), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "-c Debian-Security -c linux", "debian3") );
is( $result->return_code, 2, "Debian apt output, critical on Debian-Security or linux" );
like( $result->output, make_result_regexp(19, 9), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "-i lib -i linux -e gc1c -c linux-image", "debian3") );
is( $result->return_code, 2, "Debian apt output, include lib and linux, exclude gc1c, critical on linux-image" );
like( $result->output, make_result_regexp(10, 2), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu1") );
is( $result->return_code, 1, "Ubuntu apt output, warning" );
like( $result->output, make_result_regexp(5, 0), "Output correct" );
$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu2") );
is( $result->return_code, 2, "Ubuntu apt output, some critical" );
like( $result->output, make_result_regexp(25, 14), "Output correct" );

View file

@ -0,0 +1,4 @@
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!

View file

@ -0,0 +1,37 @@
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
base-files debian-archive-keyring dpkg firmware-linux-free libc-bin libc-dev-bin libc6 libc6-dev linux-base
linux-image-2.6.32-5-xen-amd64 linux-libc-dev locales lockfile-progs
13 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Inst base-files [6.0squeeze5] (6.0squeeze6 Debian:6.0.6/stable [amd64])
Conf base-files (6.0squeeze6 Debian:6.0.6/stable [amd64])
Inst dpkg [1.15.8.12] (1.15.8.13 Debian:6.0.6/stable [amd64])
Conf dpkg (1.15.8.13 Debian:6.0.6/stable [amd64])
Inst linux-base [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
Inst linux-image-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64])
Inst debian-archive-keyring [2010.08.28] (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
Conf debian-archive-keyring (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
Inst libc6-dev [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) []
Inst libc-dev-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) []
Inst linux-libc-dev [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) []
Inst libc-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
Conf libc-bin (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
Inst libc6 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64])
Conf libc6 (2.11.3-4 Debian:6.0.6/stable [amd64])
Inst locales [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [all])
Inst firmware-linux-free [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
Inst lockfile-progs [0.1.15] (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
Conf linux-base (2.6.32-46 Debian:6.0.6/stable [all])
Conf linux-image-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
Conf libc-dev-bin (2.11.3-4 Debian:6.0.6/stable [amd64])
Conf linux-libc-dev (2.6.32-46 Debian:6.0.6/stable [amd64])
Conf libc6-dev (2.11.3-4 Debian:6.0.6/stable [amd64])
Conf locales (2.11.3-4 Debian:6.0.6/stable [all])
Conf firmware-linux-free (2.6.32-46 Debian:6.0.6/stable [all])
Conf lockfile-progs (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])

View file

@ -0,0 +1,42 @@
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Inst base-files [6.0squeeze5] (6.0squeeze6 Debian:6.0.6/stable [amd64])
Conf base-files (6.0squeeze6 Debian:6.0.6/stable [amd64])
Inst dpkg [1.15.8.12] (1.15.8.13 Debian:6.0.6/stable [amd64])
Conf dpkg (1.15.8.13 Debian:6.0.6/stable [amd64])
Inst linux-base [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
Inst linux-image-2.6.32-5-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64])
Inst xen-hypervisor-4.0-amd64 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
Inst xen-linux-system-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) []
Inst linux-image-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64])
Inst debian-archive-keyring [2010.08.28] (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
Conf debian-archive-keyring (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
Inst libc6-i386 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) []
Inst libc-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
Conf libc-bin (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
Inst libc6 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64])
Conf libc6 (2.11.3-4 Debian:6.0.6/stable [amd64])
Inst libgc1c2 [1:6.8-1.2] (1:6.8-2 Debian:6.0.6/stable [amd64])
Inst locales [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [all])
Inst firmware-linux-free [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
Inst libxenstore3.0 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
Inst lockfile-progs [0.1.15] (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
Inst xen-utils-4.0 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
Inst xenstore-utils [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
Inst libconfig-inifiles-perl [2.52-1] (2.52-1+squeeze1 Debian:6.0.6/stable [all])
Conf linux-base (2.6.32-46 Debian:6.0.6/stable [all])
Conf linux-image-2.6.32-5-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
Conf xen-hypervisor-4.0-amd64 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
Conf linux-image-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
Conf xen-linux-system-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
Conf libc6-i386 (2.11.3-4 Debian:6.0.6/stable [amd64])
Conf libgc1c2 (1:6.8-2 Debian:6.0.6/stable [amd64])
Conf locales (2.11.3-4 Debian:6.0.6/stable [all])
Conf firmware-linux-free (2.6.32-46 Debian:6.0.6/stable [all])
Conf libxenstore3.0 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
Conf lockfile-progs (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
Conf xen-utils-4.0 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
Conf xenstore-utils (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
Conf libconfig-inifiles-perl (2.52-1+squeeze1 Debian:6.0.6/stable [all])

View file

@ -0,0 +1,14 @@
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Also keep in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Inst grub-pc [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
Inst grub-pc-bin [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
Inst grub2-common [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
Inst grub-efi-amd64-bin [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
Inst grub-common [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
Conf grub-common (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
Conf grub2-common (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
Conf grub-pc-bin (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
Conf grub-pc (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
Conf grub-efi-amd64-bin (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])

View file

@ -0,0 +1,54 @@
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Also keep in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Inst libc6-dev [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) []
Inst libc-dev-bin [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) []
Inst linux-libc-dev [3.2.0-29.46] (3.2.0-31.50 Ubuntu:12.04/precise-security [amd64]) []
Inst tzdata [2012e-0ubuntu0.12.04] (2012e-0ubuntu0.12.04.1 Ubuntu:12.04/precise-security [all]) []
Conf tzdata (2012e-0ubuntu0.12.04.1 Ubuntu:12.04/precise-security [all]) []
Inst libc-bin [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [libc6:amd64 ]
Conf libc-bin (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [libc6:amd64 ]
Inst libc6 [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
Conf libc6 (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
Inst libapt-pkg4.12 [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
Conf libapt-pkg4.12 (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
Inst ubuntu-keyring [2011.11.21] (2011.11.21.1 Ubuntu:12.04/precise-updates [all])
Conf ubuntu-keyring (2011.11.21.1 Ubuntu:12.04/precise-updates [all])
Inst gpgv [1.4.11-3ubuntu2] (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
Conf gpgv (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
Inst gnupg [1.4.11-3ubuntu2] (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
Conf gnupg (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
Inst apt [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
Conf apt (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
Inst libssl1.0.0 [1.0.1-4ubuntu5.3] (1.0.1-4ubuntu5.5 Ubuntu:12.04/precise-updates [amd64])
Conf libssl1.0.0 (1.0.1-4ubuntu5.5 Ubuntu:12.04/precise-updates [amd64])
Inst libapt-inst1.4 [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
Inst resolvconf [1.63ubuntu15] (1.63ubuntu16 Ubuntu:12.04/precise-updates [all])
Inst libdbus-1-3 [1.4.18-1ubuntu1] (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
Inst libxml2 [2.7.8.dfsg-5.1ubuntu4.1] (2.7.8.dfsg-5.1ubuntu4.2 Ubuntu:12.04/precise-security [amd64])
Inst multiarch-support [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
Conf multiarch-support (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
Inst apt-utils [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
Inst isc-dhcp-client [4.1.ESV-R4-0ubuntu5.2] (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64]) []
Inst isc-dhcp-common [4.1.ESV-R4-0ubuntu5.2] (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64])
Inst dbus [1.4.18-1ubuntu1] (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
Inst linux-firmware [1.79] (1.79.1 Ubuntu:12.04/precise-updates [all])
Inst xserver-common [2:1.11.4-0ubuntu10.7] (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [all])
Inst xserver-xorg-core [2:1.11.4-0ubuntu10.7] (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [amd64])
Inst xserver-xorg-input-synaptics [1.6.2-1ubuntu1~precise1] (1.6.2-1ubuntu1~precise2 Ubuntu:12.04/precise-updates [amd64])
Conf libc-dev-bin (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
Conf linux-libc-dev (3.2.0-31.50 Ubuntu:12.04/precise-security [amd64])
Conf libc6-dev (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
Conf libapt-inst1.4 (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
Conf resolvconf (1.63ubuntu16 Ubuntu:12.04/precise-updates [all])
Conf libdbus-1-3 (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
Conf libxml2 (2.7.8.dfsg-5.1ubuntu4.2 Ubuntu:12.04/precise-security [amd64])
Conf apt-utils (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
Conf isc-dhcp-common (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64])
Conf isc-dhcp-client (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64])
Conf dbus (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
Conf linux-firmware (1.79.1 Ubuntu:12.04/precise-updates [all])
Conf xserver-common (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [all])
Conf xserver-xorg-core (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [amd64])
Conf xserver-xorg-input-synaptics (1.6.2-1ubuntu1~precise2 Ubuntu:12.04/precise-updates [amd64])

103
plugins/t/check_dbi.t Normal file
View file

@ -0,0 +1,103 @@
#! /usr/bin/perl -w -I ..
#
# Database Server Tests via check_dbi
#
#
# Uses the 'sqlite3' DBD driver and command line utility.
use strict;
use Test::More;
use NPTest;
use File::Temp;
use vars qw($tests);
plan skip_all => "check_dbi not compiled" unless (-x "check_dbi");
$tests = 20;
plan tests => $tests;
my $missing_driver_output = "failed to open DBI driver 'sqlite3'";
my $bad_driver_output = "/failed to open DBI driver 'nodriver'/";
my $conn_time_output = "/OK - connection time: [0-9\.]+s \|/";
my $missing_query_output = "/Must specify a query to execute/";
my $no_rows_output = "/WARNING - no rows returned/";
my $not_numeric_output = "/CRITICAL - result value is not a numeric:/";
my $query_time_output = "/OK - connection time: [0-9\.]+s, 'SELECT 1' returned 1.000000 in [0-9\.]+s \|/";
my $syntax_error_output = "/CRITICAL - failed to execute query 'GET ALL FROM test': 1: near \"GET\": syntax error/";
my $result;
SKIP: {
my $sqlite3 = qx(which sqlite3 2> /dev/null);
chomp($sqlite3);
skip "No Sqlite3 found", $tests unless $sqlite3;
my $sqlite3_check = qx(./check_dbi -d sqlite3 -q '');
if ($sqlite3_check =~ m/$missing_driver_output/) {
skip "No 'sqlite3' DBD driver found", $tests;
}
my $fh = File::Temp->new(
TEMPLATE => "/tmp/check_dbi_sqlite3.XXXXXXX",
UNLINK => 1,
);
my $filename = $fh->filename;
$filename =~ s/^\/tmp\///;
system("$sqlite3 /tmp/$filename 'CREATE TABLE test(a INT, b TEXT)'");
system("$sqlite3 /tmp/$filename 'INSERT INTO test VALUES (1, \"text1\")'");
system("$sqlite3 /tmp/$filename 'INSERT INTO test VALUES (2, \"text2\")'");
my $check_cmd = "./check_dbi -d sqlite3 -o sqlite3_dbdir=/tmp -o dbname=$filename";
$result = NPTest->testCmd("$check_cmd -q 'SELECT 1'");
cmp_ok($result->return_code, '==', 0, "Sqlite3 login okay and can run query");
$result = NPTest->testCmd("$check_cmd");
cmp_ok($result->return_code, '==', 3, "Missing query parameter");
like($result->output, $missing_query_output, "Missing query parameter error message");
$result = NPTest->testCmd("$check_cmd -q 'GET ALL FROM test'");
cmp_ok($result->return_code, '==', 2, "Invalid query");
like($result->output, $syntax_error_output, "Syntax error message");
$result = NPTest->testCmd("$check_cmd -q 'SELECT 2.71828' -w 2 -c 3");
cmp_ok($result->return_code, '==', 1, "Got warning");
$result = NPTest->testCmd("$check_cmd -q 'SELECT 3.1415' -w 2 -c 3");
cmp_ok($result->return_code, '==', 2, "Got critical");
$result = NPTest->testCmd("$check_cmd -q ''");
cmp_ok($result->return_code, '==', 1, "No rows returned");
like($result->output, $no_rows_output, "Now rows returned warning message");
$result = NPTest->testCmd("$check_cmd -q 'SELECT b FROM test'");
cmp_ok($result->return_code, '==', 2, "Value is not a numeric");
like($result->output, $not_numeric_output, "Value is not a numeric error message");
$result = NPTest->testCmd("$check_cmd -m QUERY_RESULT -q 'SELECT b FROM test' -e text1");
cmp_ok($result->return_code, '==', 0, "Query result string comparison okay");
$result = NPTest->testCmd("$check_cmd -q 'SELECT b FROM test' -r 'eXt[0-9]'");
cmp_ok($result->return_code, '==', 2, "Query result case-insensitive regex failure");
$result = NPTest->testCmd("$check_cmd -q 'SELECT b FROM test' -R 'eXt[0-9]'");
cmp_ok($result->return_code, '==', 0, "Query result case-sensitive regex okay");
$result = NPTest->testCmd("$check_cmd -m CONN_TIME -w 0.5 -c 0.7");
cmp_ok($result->return_code, '==', 0, "CONN_TIME metric okay");
like($result->output, $conn_time_output, "CONN_TIME metric output okay");
$result = NPTest->testCmd("$check_cmd -m QUERY_TIME -q 'SELECT 1'");
cmp_ok($result->return_code, '==', 0, "QUERY_TIME metric okay");
like($result->output, $query_time_output, "QUERY_TIME metric output okay");
$result = NPTest->testCmd("./check_dbi -d nodriver -q ''");
cmp_ok($result->return_code, '==', 3, "Unknown DBI driver");
like($result->output, $bad_driver_output, "Correct error message");
}

View file

@ -10,30 +10,30 @@ use NPTest;
plan skip_all => "check_dig not compiled" unless (-x "check_dig");
plan tests => 12;
plan tests => 16;
my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/';
my $hostname_valid = getTestParameter(
my $hostname_valid = getTestParameter(
"NP_HOSTNAME_VALID",
"A valid (known to DNS) hostname",
"nagios.com"
"nagiosplugins.org"
);
my $hostname_valid_ip = getTestParameter(
"NP_HOSTNAME_VALID_IP",
"The IP address of the valid hostname $hostname_valid",
"66.118.156.50",
"67.207.143.200",
);
my $hostname_valid_reverse = getTestParameter(
"NP_HOSTNAME_VALID_REVERSE",
"The hostname of $hostname_valid_ip",
"66-118-156-50.static.sagonet.net.",
"nagiosplugins.org.",
);
my $hostname_invalid = getTestParameter(
"NP_HOSTNAME_INVALID",
my $hostname_invalid = getTestParameter(
"NP_HOSTNAME_INVALID",
"An invalid (not known to DNS) hostname",
"nosuchhost.altinity.com",
);
@ -69,6 +69,14 @@ SKIP: {
cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
like ( $res->output, $successOutput, "Output OK" );
$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -4");
cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
like ( $res->output, $successOutput, "Output OK for IPv4" );
$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -6");
cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
like ( $res->output, $successOutput, "Output OK for IPv6" );
$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5");
cmp_ok( $res->return_code, '==', 0, "Got expected address");

View file

@ -8,22 +8,22 @@ use strict;
use Test::More;
use NPTest;
plan tests => 28;
plan tests => 30;
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)",
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",
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 $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
@ -32,8 +32,8 @@ my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
my $host_tcp_http2;
if ($internet_access eq "no") {
$host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
"A host providing an index page containing the string 'nagios'",
$host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
"A host providing an index page containing the string 'nagios'",
"www.nagios.com" );
}
@ -45,14 +45,9 @@ 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'"
"./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'"
);
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" );
like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" );
$res = NPTest->testCmd(
"./check_http $host_nonresponsive -wt 1 -ct 2"
@ -123,6 +118,10 @@ SKIP: {
$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.verisign.com -E" );
like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' );
$res = NPTest->testCmd(
"./check_http --ssl www.e-paycobalt.com"
);
@ -131,4 +130,7 @@ SKIP: {
$res = NPTest->testCmd( "./check_http -H www.mozilla.com -u /firefox -f follow" );
is( $res->return_code, 0, "Redirection based on location is okay");
$res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" );
like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
}

View file

@ -20,7 +20,7 @@ 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" );
like( $result->output, '/^PROCS OK: [0-9]+ process(es)? | procs=[0-9]+;100000;100000;0;$/', "Output correct" );
$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" );
is( $result->return_code, 0, "Checking less than 100000 zombie processes" );
@ -28,11 +28,11 @@ 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" );
like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "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" );
like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? | procs=[0-9]+;0;0;0;$/', "Output correct" );
$result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" );
is( $result->return_code, 2, "Checking critical if sleeping processes" );

View file

@ -8,145 +8,164 @@ use strict;
use Test::More;
use NPTest;
my $tests = 8+42+2+2;
plan tests => $tests;
BEGIN {
plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp";
plan tests => 60;
}
my $res;
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 (assumes snmp v1)" );
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" );
$res = NPTest->testCmd( "./check_snmp -t 1" );
is( $res->return_code, 3, "No host name" );
is( $res->output, "No host specified" );
$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" );
is( $res->return_code, 3, "Invalid seclevel" );
like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" );
$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" );
is( $res->return_code, 3, "Invalid protocol" );
like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
SKIP: {
skip "check_snmp is not compiled", $tests if ( ! -x "./check_snmp" );
skip "no snmp host defined", 38 if ( ! $host_snmp );
my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost",
"A host providing an SNMP Service");
$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" );
like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK");
$res->output =~ /^SNMP OK - (\d+)/;
my $value = $1;
cmp_ok( $value, ">", 0, "Got a time value" );
like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it");
my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
"The SNMP Community string for SNMP Testing (assumes snmp v1)" );
my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
"The hostname of system not responsive to network requests" );
# some more threshold tests
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1");
cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" );
my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
"An invalid (not known to DNS) hostname" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:");
cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" );
$res = NPTest->testCmd( "./check_snmp -t 1" );
is( $res->return_code, 3, "No host name" );
is( $res->output, "No host specified" );
$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 $host_snmp -C $snmp_community -o system.sysUpTime.0 -c ~:1");
cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" );
$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 --seclevel=rubbish" );
is( $res->return_code, 3, "Invalid seclevel" );
like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:10");
cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" );
$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" );
is( $res->return_code, 3, "Invalid protocol" );
like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c \@1:10");
cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" );
SKIP: {
skip "no snmp host defined", 38 if ( ! $host_snmp );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 10:1");
cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" );
$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" );
like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK");
$res->output =~ /^SNMP OK - (\d+)/;
my $value = $1;
cmp_ok( $value, ">", 0, "Got a time value" );
like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" );
like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" );
like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" );
like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" );
like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" );
like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" );
like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2");
cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" );
like($res->output, "/^SNMP OK - 2 1/", "Got two values back" );
like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2");
cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" );
like($res->output, "/^SNMP OK - 2 1/", "Got two values back" );
like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2");
cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" );
like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" );
like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2");
cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" );
like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" );
like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses");
like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses");
like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0");
cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds");
like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0");
cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds");
like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3");
$res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/;
my $lower = $1 - 0.05;
my $higher = $1 + 0.05;
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher");
cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3");
$res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/;
my $lower = $1 - 0.05;
my $higher = $1 + 0.05;
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher");
cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2");
cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold");
like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2");
cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold");
like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''");
cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''");
cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2");
cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check");
like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2");
cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check");
like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,");
cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds");
like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,");
cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds");
like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'");
cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold");
like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0");
cmp_ok( $res->return_code, '==', 0, "Timetick used as a string");
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");
}
# 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: {
skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
$res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem");
}
SKIP: {
skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
$res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host");
}
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'");
cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold");
like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0");
cmp_ok( $res->return_code, '==', 0, "Timetick used as a string");
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");
}
# 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: {
skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
$res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem");
}
SKIP: {
skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
$res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host");
}

View file

@ -9,7 +9,7 @@ use Test;
use NPTest;
use vars qw($tests);
BEGIN {$tests = 7; plan tests => $tests}
BEGIN {$tests = 14; 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)" );
@ -27,13 +27,15 @@ my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on po
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 80 -wt 300 -ct 600 -6 ", 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", 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 );
$t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 );
# 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