Code

Update libtool
[nagiosplug.git] / plugins-scripts / t / check_ifstatus.t
1 #! /usr/bin/perl -w -I ..
2 #
3 # SNMP Test via check_ifoperstatus
4 #
5 #
7 use strict;
8 use Test::More;
9 use NPTest;
11 my $tests = 9;
12 plan tests => $tests;
13 my $res;
15 my $plugin = "check_ifstatus";
16 SKIP: {
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",
23                                                "public");
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",
30                                                    "nosuchhost" );
33         $res = NPTest->testCmd( "./$plugin" );
34         is( $res->return_code, 3, "No arguments" );
35         like( $res->output, '/usage/', "Output contains usage" );
36         
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'" );
41         SKIP: {
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'" ); 
50         }
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
54         SKIP: {
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" ); 
58         }
60         SKIP: {
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");
65         }
67 }