Imported Upstream version 1.4.13+git200906171200
This commit is contained in:
		
							parent
							
								
									4ab9f0d24c
								
							
						
					
					
						commit
						d0b8ab8112
					
				
					 362 changed files with 34110 additions and 10773 deletions
				
			
		| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# check_by_ssh tests
 | 
			
		||||
#
 | 
			
		||||
# $Id$
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			@ -92,7 +91,7 @@ $result = NPTest->testCmd(
 | 
			
		|||
	);
 | 
			
		||||
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");
 | 
			
		||||
cmp_ok(scalar(@lines), '==', 8, "Correct number of output lines for multiple checks");
 | 
			
		||||
my %linemap = (
 | 
			
		||||
               '0' => '1',
 | 
			
		||||
               '2' => '0',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# check_cluster tests
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_cluster.t 1702 2007-04-28 21:57:17Z psychotrahe $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										84
									
								
								plugins/t/check_dig.t
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								plugins/t/check_dig.t
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,84 @@
 | 
			
		|||
#! /usr/bin/perl -w -I ..
 | 
			
		||||
#
 | 
			
		||||
# Domain Name Server (DNS) Tests via check_dig
 | 
			
		||||
#
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
use Test::More;
 | 
			
		||||
use NPTest;
 | 
			
		||||
 | 
			
		||||
plan skip_all => "check_dig not compiled" unless (-x "check_dig");
 | 
			
		||||
 | 
			
		||||
plan tests => 12;
 | 
			
		||||
 | 
			
		||||
my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/';
 | 
			
		||||
 | 
			
		||||
my $hostname_valid = getTestParameter( 
 | 
			
		||||
			"NP_HOSTNAME_VALID",
 | 
			
		||||
			"A valid (known to DNS) hostname",
 | 
			
		||||
			"nagios.com"
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
my $hostname_valid_ip = getTestParameter(
 | 
			
		||||
			"NP_HOSTNAME_VALID_IP",
 | 
			
		||||
			"The IP address of the valid hostname $hostname_valid",
 | 
			
		||||
			"66.118.156.50",
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
my $hostname_valid_reverse = getTestParameter(
 | 
			
		||||
			"NP_HOSTNAME_VALID_REVERSE",
 | 
			
		||||
			"The hostname of $hostname_valid_ip",
 | 
			
		||||
			"66-118-156-50.static.sagonet.net.",
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
SKIP: {
 | 
			
		||||
        skip "check_dig.t: not enough parameters given",
 | 
			
		||||
	12 unless ($hostname_valid && $hostname_valid_ip && $hostname_valid_reverse && $hostname_invalid && $dns_server);
 | 
			
		||||
 | 
			
		||||
	$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5");
 | 
			
		||||
	cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid");
 | 
			
		||||
	like  ( $res->output, $successOutput, "Output OK" );
 | 
			
		||||
 | 
			
		||||
	$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 0.00001");
 | 
			
		||||
	cmp_ok( $res->return_code, '==', 2, "Critical threshold passed");
 | 
			
		||||
 | 
			
		||||
	$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -w 0.000001 -c 5");
 | 
			
		||||
	cmp_ok( $res->return_code, '==', 1, "Warning threshold passed");
 | 
			
		||||
 | 
			
		||||
	$res = NPTest->testCmd("./check_dig -H $dns_server -t 1");
 | 
			
		||||
	cmp_ok( $res->return_code, '==', 3, "Invalid command line -l missing");
 | 
			
		||||
 | 
			
		||||
	$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_invalid -t 1");
 | 
			
		||||
	cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid");
 | 
			
		||||
 | 
			
		||||
	$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid  -t 5");
 | 
			
		||||
	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 -a $hostname_valid_ip -t 5");
 | 
			
		||||
	cmp_ok( $res->return_code, '==', 0, "Got expected address");
 | 
			
		||||
 | 
			
		||||
	$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a 10.10.10.10 -t 5");
 | 
			
		||||
	cmp_ok( $res->return_code, '==', 1, "Got wrong address");
 | 
			
		||||
 | 
			
		||||
	my $ip_reverse = $hostname_valid_ip;
 | 
			
		||||
	$ip_reverse =~ s/(\d+)\.(\d+)\.(\d+)\.(\d+)/$4.$3.$2.$1.in-addr.arpa/;
 | 
			
		||||
	$res = NPTest->testCmd("./check_dig -H $dns_server -l $ip_reverse -a $hostname_valid_reverse -T PTR -t 5");
 | 
			
		||||
	cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
 | 
			
		||||
	like  ( $res->output, $successOutput, "Output OK");
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Disk Space Tests via check_disk
 | 
			
		||||
#
 | 
			
		||||
# $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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Domain Name Server (DNS) Tests via check_dns
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_dns.t 1902 2008-01-08 16:05:36Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# check_dummy tests
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_dummy.t 1716 2007-05-24 08:35:53Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# FPing Tests via check_fping
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_fping.t 1207 2005-07-25 01:47:15Z illumino $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# File Transfer Protocol (FTP) Test via check_ftp
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_ftp.t 1901 2008-01-08 11:57:24Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# HP JetDirect Test via check_hpjd
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_hpjd.t 1354 2006-03-24 16:13:40Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# HyperText Transfer Protocol (HTTP) Test via check_http
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_http.t 1669 2007-04-01 14:21:09Z psychotrahe $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +34,7 @@ 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'", 
 | 
			
		||||
            "altinity.com" );
 | 
			
		||||
            "www.nagios.com" );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +73,7 @@ SKIP: {
 | 
			
		|||
        skip "No internet access and no host serving nagios in index file",
 | 
			
		||||
              7 if $internet_access eq "no" && ! $host_tcp_http2;
 | 
			
		||||
 | 
			
		||||
        $host_tcp_http2 = "altinity.com" if (! $host_tcp_http2);
 | 
			
		||||
        $host_tcp_http2 = "www.nagios.com" if (! $host_tcp_http2);
 | 
			
		||||
 | 
			
		||||
        $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'nagios'" );
 | 
			
		||||
        cmp_ok( $res->return_code, "==", 0, "Got a reference to 'nagios'");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Internet Mail Access Protocol (IMAP) Server Tests via check_imap
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_imap.t 1901 2008-01-08 11:57:24Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Jabber Server Tests via check_jabber
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_jabber.t 1901 2008-01-08 11:57:24Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Load Average Tests via check_load
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_load.t 1851 2007-12-10 00:19:27Z psychotrahe $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# MySQL Database Server Tests via check_mysql
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_mysql.t 1988 2008-04-30 12:50:52Z dermoth $
 | 
			
		||||
#
 | 
			
		||||
#
 | 
			
		||||
# These are the database permissions required for this test:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# MySQL Database Server Tests via check_mysql
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_mysql_query.t 1315 2006-02-01 13:23:38Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
#
 | 
			
		||||
# These are the database permissions required for this test:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# check_nagios tests
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_nagios.t 1953 2008-03-17 23:08:21Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Testing NTP
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_ntp.t 1865 2007-12-11 13:54:23Z dermoth $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Ping Response Tests via check_ping
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_ping.t 1639 2007-03-12 10:51:06Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Post Office Protocol (POP) Server Tests via check_pop
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_pop.t 1901 2008-01-08 11:57:24Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Process Tests via check_procs
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_procs.t 1937 2008-02-28 16:21:59Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			@ -11,7 +10,7 @@ use NPTest;
 | 
			
		|||
 | 
			
		||||
my $t;
 | 
			
		||||
 | 
			
		||||
if (`uname -s` eq "SunOS\n") {
 | 
			
		||||
if (`uname -s` eq "SunOS\n" && ! -x "/usr/local/nagios/libexec/pst3") {
 | 
			
		||||
	plan skip_all => "Ignoring tests on solaris because of pst3";
 | 
			
		||||
} else {
 | 
			
		||||
	plan tests => 12;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Simple Mail Transfer Protocol (SMTP) Test via check_smtp
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_smtp.t 1500 2006-10-19 11:56:34Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,56 +2,132 @@
 | 
			
		|||
#
 | 
			
		||||
# Simple Network Management Protocol (SNMP) Test via check_snmp
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_snmp.t 1557 2006-12-23 18:59:36Z dermoth $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
use Test;
 | 
			
		||||
use Test::More;
 | 
			
		||||
use NPTest;
 | 
			
		||||
 | 
			
		||||
use vars qw($tests);
 | 
			
		||||
BEGIN {$tests = 12; plan tests => $tests}
 | 
			
		||||
my $tests = 44;
 | 
			
		||||
plan tests => $tests;
 | 
			
		||||
my $res;
 | 
			
		||||
 | 
			
		||||
my $t;
 | 
			
		||||
SKIP: {
 | 
			
		||||
	skip "check_snmp is not compiled", $tests if ( ! -x "./check_snmp" );
 | 
			
		||||
 | 
			
		||||
if ( -x "./check_snmp" )
 | 
			
		||||
{
 | 
			
		||||
  my $host_snmp          = getTestParameter( "host_snmp",          "NP_HOST_SNMP",      "localhost",
 | 
			
		||||
					     "A host providing an SNMP Service");
 | 
			
		||||
	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 $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 $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 $hostname_invalid   = getTestParameter( "hostname_invalid",   "NP_HOSTNAME_INVALID",   "nosuchhost",
 | 
			
		||||
	                                           "An invalid (not known to DNS) hostname" );
 | 
			
		||||
 | 
			
		||||
  my %exceptions = ( 3 => "No SNMP Server present?" );
 | 
			
		||||
	$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/" );
 | 
			
		||||
 | 
			
		||||
  $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 );
 | 
			
		||||
	$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/" );
 | 
			
		||||
 | 
			
		||||
  $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 );
 | 
			
		||||
	SKIP: {
 | 
			
		||||
		skip "no snmp host defined", 32 if ( ! $host_snmp );
 | 
			
		||||
 | 
			
		||||
  $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 );
 | 
			
		||||
		$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");
 | 
			
		||||
 | 
			
		||||
  $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 );
 | 
			
		||||
		$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");
 | 
			
		||||
 | 
			
		||||
  $t += checkCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' );
 | 
			
		||||
		$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");
 | 
			
		||||
 | 
			
		||||
  $t += checkCmd( "./check_snmp -H $hostname_invalid   -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' );
 | 
			
		||||
		$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 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 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 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 arcuments");
 | 
			
		||||
 | 
			
		||||
		$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.*,\s.*\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.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");
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	# 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");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
else
 | 
			
		||||
{
 | 
			
		||||
  $t += skipMissingCmd( "./check_snmp", $tests );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exit(0) if defined($Test::Harness::VERSION);
 | 
			
		||||
exit($tests - $t);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# Swap Space Tests via check_swap
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_swap.t 1279 2005-11-09 16:40:12Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# TCP Connection Based Tests via check_tcp
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_tcp.t 1901 2008-01-08 11:57:24Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# System Time Tests via check_time
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_time.t 1270 2005-11-03 15:04:16Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#
 | 
			
		||||
# UDP Connection Based Tests via check_udp
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_udp.t 1459 2006-07-28 22:44:11Z tonvoon $
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,8 +2,11 @@
 | 
			
		|||
#
 | 
			
		||||
# Logged in Users Tests via check_users
 | 
			
		||||
#
 | 
			
		||||
# $Id: check_users.t 1207 2005-07-25 01:47:15Z illumino $
 | 
			
		||||
# Trick: This ckeck requires at least 1 user logged in. These commands should
 | 
			
		||||
#        leave a session open forever in the background:
 | 
			
		||||
#
 | 
			
		||||
#   $ ssh -tt localhost </dev/null >/dev/null 2>/dev/null &
 | 
			
		||||
#   $ disown %1
 | 
			
		||||
 | 
			
		||||
use strict;
 | 
			
		||||
use Test;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,15 +3,13 @@
 | 
			
		|||
# 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;
 | 
			
		||||
# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops
 | 
			
		||||
plan tests => 88;
 | 
			
		||||
 | 
			
		||||
my $res;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -55,18 +53,37 @@ is( $res->output, "No data returned from command", "Bad command, as expected (tr
 | 
			
		|||
$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)) {
 | 
			
		||||
 | 
			
		||||
# Timeout tests
 | 
			
		||||
$res = NPTest->testCmd( "./negate -t 2 /bin/sh -c 'sleep 5'" );
 | 
			
		||||
is( $res->output, 'CRITICAL - Plugin timed out after 2 seconds' );
 | 
			
		||||
 | 
			
		||||
foreach my $state (keys(%state)) {
 | 
			
		||||
	$res = NPTest->testCmd( "./negate -t 2 -T $state /bin/sh -c 'sleep 5'" );
 | 
			
		||||
	is( $res->return_code, $state{$state}, "Got timeout state $state" );
 | 
			
		||||
	is( $res->output,  uc($state)." - Plugin timed out after 2 seconds", "Timeout state $state output");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
foreach my $current_state (keys(%state)) {
 | 
			
		||||
	foreach my $new_state (keys(%state)) {
 | 
			
		||||
		$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" );
 | 
			
		||||
		is( $res->output, uc($current_state).": Fake $new_state", "Fake $new_state output");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Same as aboce with substitute
 | 
			
		||||
foreach my $current_state (keys(%state)) {
 | 
			
		||||
	foreach my $new_state (keys(%state)) {
 | 
			
		||||
		$res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
 | 
			
		||||
		is( $res->return_code, $state{$new_state}, "Got fake $new_state (with substitute)" );
 | 
			
		||||
		is( $res->output, uc($new_state).": Fake $new_state", "Substitued fake $new_state output");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue