X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Ft%2Fcheck_snmp.t;h=acd122014137866eb667d1a5fe17168ffb3d4082;hb=e6d99d8ec38cc7bfd5d7021e102bdc8da7033dc0;hp=162b0b9baa31e2bf00ddeab592a8d5e34e7c9c1d;hpb=44a321cb8a42d6c0ea2d96a1086a17f2134c89cc;p=nagiosplug.git diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index 162b0b9..acd1220 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t @@ -1,52 +1,57 @@ -#! /usr/bin/perl -w +#! /usr/bin/perl -w -I .. +# +# Simple Network Management Protocol (SNMP) Test via check_snmp +# +# $Id$ +# use strict; -use Helper; -use Cache; use Test; -use vars qw($tests); +use NPTest; -BEGIN {$tests = 8; plan tests => $tests} +use vars qw($tests); +BEGIN {$tests = 12; plan tests => $tests} -my $null = ''; -my $cmd; -my $str; my $t; -my $community=get_option("snmp_community","SNMP community name"); - -exit(0) unless (-x "./check_snmp"); - -$cmd = "./check_snmp -H 127.0.0.1 -C $community -o system.sysUpTime.0 -w 1: -c 1:"; -$str = `$cmd`; -$t += ok $?>>8,0; -print "Test was: $cmd\n" if ($?); -chomp $str; -$t += ok $str, '/^SNMP OK - \d+/'; - -$cmd = "./check_snmp -H 127.0.0.1 -C $community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"; -$str = `$cmd`; -$t += ok $?>>8,0; -print "Test was: $cmd\n" if ($?); -chomp $str; -$t += ok $str, '/^SNMP OK - 1\s*$/'; - -$cmd = "./check_snmp -H 127.0.0.1 -C $community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"; -$str = `$cmd`; -$t += ok $?>>8,1; -print "Test was: $cmd\n" unless ($?); -chomp $str; -$t += ok $str, '/^SNMP WARNING - \*1\*\s*$/'; - -$cmd = "./check_snmp -H 127.0.0.1 -C $community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"; -$str = `$cmd`; -$t += ok $?>>8,2; -print "Test was: $cmd\n" unless ($?); -chomp $str; -$t += ok $str, '/^SNMP CRITICAL - \*1\*\s*$/'; - -#host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 = 1 -#enterprises.ucdavis.memory.memAvailSwap.0 -#./check_snmp 127.0.0.1 -C staff -o enterprises.ucdavis.diskTable.dskEntry.dskAvail.1,enterprises.ucdavis.diskTable.dskEntry.dskPercent.1 -w 100000: -c 50000: -l Space on root -u 'bytes free (','% used)' + +if ( -x "./check_snmp" ) +{ + my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost", + "A host providing an SNMP Service"); + + my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", + "The SNMP Community string for SNMP Testing" ); + + my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", + "The hostname of system not responsive to network requests" ); + + my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", + "An invalid (not known to DNS) hostname" ); + + my %exceptions = ( 3 => "No SNMP Server present?" ); + + + $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", + { 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - \d+/', %exceptions ); + + $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1", + { 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - 1\s.*$/', %exceptions ); + + $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:", + { 1 => 'continue', 3 => 'skip' }, '/^SNMP WARNING - \*1\*\s.*$/', %exceptions ); + + $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0", + { 2 => 'continue', 3 => 'skip' }, '/^SNMP CRITICAL - \*1\*\s.*$/', %exceptions ); + + $t += checkCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' ); + + $t += checkCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' ); + +} +else +{ + $t += skipMissingCmd( "./check_snmp", $tests ); +} exit(0) if defined($Test::Harness::VERSION); exit($tests - $t);