summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_snmp.t
diff options
context:
space:
mode:
authorMatthias Eble <psychotrahe@users.sourceforge.net>2008-07-09 21:54:41 (GMT)
committerMatthias Eble <psychotrahe@users.sourceforge.net>2008-07-09 21:54:41 (GMT)
commit1066906a16f3a18d3cbcdb844169193032fa34de (patch)
treec130fd1884dc9580fc58c8600f8771ecdc898f02 /plugins/t/check_snmp.t
parentbe144b672094a11b6a670df9562e26e6a56ff03f (diff)
downloadmonitoring-plugins-1066906a16f3a18d3cbcdb844169193032fa34de.tar.gz
rewrote check_snmp.t to use Test::More
added perfdata checking for string values git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2022 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/t/check_snmp.t')
-rw-r--r--plugins/t/check_snmp.t75
1 files changed, 44 insertions, 31 deletions
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t
index acd1220..4e83139 100644
--- a/plugins/t/check_snmp.t
+++ b/plugins/t/check_snmp.t
@@ -6,52 +6,65 @@
6# 6#
7 7
8use strict; 8use strict;
9use Test; 9use Test::More;
10use NPTest; 10use NPTest;
11 11
12use vars qw($tests); 12use vars qw($tests);
13BEGIN {$tests = 12; plan tests => $tests} 13BEGIN {$tests = 14; plan tests => $tests}
14 14
15my $t; 15my $res;
16 16
17if ( -x "./check_snmp" ) 17SKIP: {
18{ 18 skip "check_snmp is not compiled", $tests if ( ! -x "./check_snmp" );
19 my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost",
20 "A host providing an SNMP Service");
21 19
22 my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", 20 my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost",
23 "The SNMP Community string for SNMP Testing" ); 21 "A host providing an SNMP Service");
24 22
25 my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", 23 my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
26 "The hostname of system not responsive to network requests" ); 24 "The SNMP Community string for SNMP Testing" );
27 25
28 my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", 26 my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
29 "An invalid (not known to DNS) hostname" ); 27 "The hostname of system not responsive to network requests" );
30 28
31 my %exceptions = ( 3 => "No SNMP Server present?" ); 29 my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
30 "An invalid (not known to DNS) hostname" );
32 31
32 SKIP: {
33 skip "no snmp host defined", 10 if ( ! $host_snmp );
33 34
34 $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 35 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
35 { 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - \d+/', %exceptions ); 36 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
37 like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
36 38
37 $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1", 39 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
38 { 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - 1\s.*$/', %exceptions ); 40 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
41 unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
39 42
40 $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:", 43 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
41 { 1 => 'continue', 3 => 'skip' }, '/^SNMP WARNING - \*1\*\s.*$/', %exceptions ); 44 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
45 like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
42 46
43 $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0", 47 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
44 { 2 => 'continue', 3 => 'skip' }, '/^SNMP CRITICAL - \*1\*\s.*$/', %exceptions ); 48 cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
49 like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
45 50
46 $t += checkCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' ); 51 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
52 cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
53 like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and ouput format");
54 }
47 55
48 $t += checkCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' ); 56 SKIP: {
57 skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
58 $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
59 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
60 like($res->output, '/SNMP problem - /', "String matches SNMP Problem");
61 }
49 62
50} 63 SKIP: {
51else 64 skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
52{ 65 $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
53 $t += skipMissingCmd( "./check_snmp", $tests ); 66 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
54} 67 like($res->output, '/SNMP problem - /', "String matches SNMP Problem");
68 }
55 69
56exit(0) if defined($Test::Harness::VERSION); 70}
57exit($tests - $t);