1 #! /usr/bin/perl -w -I ..
2 #
3 # Simple Network Management Protocol (SNMP) Test via check_snmp
4 #
5 #
7 use strict;
8 use Test::More;
9 use NPTest;
11 use vars qw($tests);
12 BEGIN {$tests = 14; plan tests => $tests}
14 my $res;
16 SKIP: {
17 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");
22 my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
23 "The SNMP Community string for SNMP Testing" );
25 my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
26 "The hostname of system not responsive to network requests" );
28 my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
29 "An invalid (not known to DNS) hostname" );
31 SKIP: {
32 skip "no snmp host defined", 10 if ( ! $host_snmp );
34 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
35 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
36 like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
38 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
39 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
40 unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
42 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
43 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
44 like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
46 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
47 cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
48 like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
50 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
51 cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
52 like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and ouput format");
53 }
55 SKIP: {
56 skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
57 $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
58 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
59 like($res->output, '/SNMP problem - /', "String matches SNMP Problem");
60 }
62 SKIP: {
63 skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
64 $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
65 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
66 like($res->output, '/SNMP problem - /', "String matches SNMP Problem");
67 }
69 }