1 #! /usr/bin/perl -w -I ..
3 # SNMP Test via check_ifoperstatus
15 my $plugin = "check_ifstatus";
17 skip
"$plugin is not created", $tests if ( ! -x
$plugin );
19 my $host_snmp = getTestParameter
( "NP_HOST_SNMP", "A host providing an SNMP Service", "localhost");
21 my $snmp_community = getTestParameter
( "NP_SNMP_COMMUNITY",
22 "The SNMP Community string for SNMP Testing",
25 my $host_nonresponsive = getTestParameter
( "NP_HOST_NONRESPONSIVE",
26 "The hostname of system not responsive to network requests", "10.0.0.1" );
28 my $hostname_invalid = getTestParameter
( "NP_HOSTNAME_INVALID",
29 "An invalid (not known to DNS) hostname",
33 $res = NPTest
->testCmd( "./$plugin" );
34 is
( $res->return_code, 3, "No arguments" );
35 like
( $res->output, '/usage/', "Output contains usage" );
37 $res = NPTest
->testCmd( "./$plugin -H fakehost -v 3 --seclevel rubbish --secname foobar" );
38 is
( $res->return_code, 3, "invalid seclevel" );
39 like
( $res->output, "/Must define a valid security level/", "Output contains 'Must define a valid security level'" );
42 skip
"no snmp host defined", 2 if ( ! $host_snmp );
44 $res = NPTest
->testCmd( "./$plugin -H $host_snmp -C $snmp_community ");
45 like
($res->output, '/^.*host.*interfaces up/', "String contains host.*interfaces up");
47 $res = NPTest
->testCmd( "./$plugin -H $host_snmp -C rubbish");
48 cmp_ok
( $res->return_code, '==', 2, "Exit CRITICAL for community 'rubbish'" );
52 # These checks need a complete command line. An invalid community is used so
53 # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway
55 skip
"no non responsive host defined", 1 if ( ! $host_nonresponsive );
56 $res = NPTest
->testCmd( "./$plugin -H $host_nonresponsive -C np_foobar");
57 cmp_ok
( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" );
61 skip
"no invalid host defined", 2 if ( ! $hostname_invalid );
62 $res = NPTest
->testCmd( "./$plugin -H $hostname_invalid -C np_foobar");
63 cmp_ok
( $res->return_code, '==', 3, "Exit UNKNOWN with invalid host" );
64 like
($res->output, "/Unable to resolve.*$hostname_invalid/", "String matches unable to resolve.*$hostname_invalid");