diff options
author | Matthias Eble <psychotrahe@gmx.de> | 2009-06-11 16:27:15 +0200 |
---|---|---|
committer | Matthias Eble <psychotrahe@gmx.de> | 2009-06-11 16:27:15 +0200 |
commit | e16b35b2ca960f8e56c17013a749e181d429a725 (patch) | |
tree | d6aeb7524f72587bbaf567326bc0c600dc3a4daa /plugins-scripts/t | |
parent | 0f8ef1f7802e9c47bf0ad72b17f28fa705f2a45c (diff) | |
download | monitoring-plugins-e16b35b2ca960f8e56c17013a749e181d429a725.tar.gz |
Added testcases for check_ifoperstatus
Added testcases for check_ifoperstatus. No SNMPv3 testing
included for now.
Diffstat (limited to 'plugins-scripts/t')
-rw-r--r-- | plugins-scripts/t/check_ifoperstatus.t | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/plugins-scripts/t/check_ifoperstatus.t b/plugins-scripts/t/check_ifoperstatus.t new file mode 100644 index 00000000..1267f415 --- /dev/null +++ b/plugins-scripts/t/check_ifoperstatus.t | |||
@@ -0,0 +1,73 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # SNMP Test via check_ifoperstatus | ||
4 | # | ||
5 | # | ||
6 | |||
7 | use strict; | ||
8 | use Test::More; | ||
9 | use NPTest; | ||
10 | |||
11 | my $tests = 15; | ||
12 | plan tests => $tests; | ||
13 | my $res; | ||
14 | |||
15 | my $plugin = "check_ifoperstatus"; | ||
16 | SKIP: { | ||
17 | skip "$plugin is not created", $tests if ( ! -x $plugin ); | ||
18 | |||
19 | my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost", | ||
20 | "A host providing an SNMP Service"); | ||
21 | |||
22 | my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", | ||
23 | "The SNMP Community string for SNMP Testing (assumes snmp v1)" ); | ||
24 | |||
25 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
26 | "The hostname of system not responsive to network requests" ); | ||
27 | |||
28 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
29 | "An invalid (not known to DNS) hostname" ); | ||
30 | |||
31 | $res = NPTest->testCmd( "./$plugin" ); | ||
32 | is( $res->return_code, 3, "No arguments" ); | ||
33 | like( $res->output, '/usage/', "Output contains usage" ); | ||
34 | |||
35 | $res = NPTest->testCmd( "./$plugin -H fakehostname" ); | ||
36 | is( $res->return_code, 3, "No key/descr specified" ); | ||
37 | like( $res->output, '/Either a valid snmp key/', "Output contains 'Either a valid snmp key'" ); | ||
38 | |||
39 | $res = NPTest->testCmd( "./$plugin -H fakehost -k 1 -v 3 --seclevel rubbish --secname foobar" ); | ||
40 | is( $res->return_code, 3, "invalid seclevel" ); | ||
41 | like( $res->output, "/Must define a valid security level/", "Output contains 'Must define a valid security level'" ); | ||
42 | |||
43 | SKIP: { | ||
44 | skip "no snmp host defined", 6 if ( ! $host_snmp ); | ||
45 | |||
46 | $res = NPTest->testCmd( "./$plugin -H $host_snmp -C $snmp_community -k 1"); | ||
47 | cmp_ok( $res->return_code, '==', 0, "Exit OK for ifindex 1" ); | ||
48 | like($res->output, '/^OK.*Interface.*is up/', "String contains OK Interface is up"); | ||
49 | |||
50 | $res = NPTest->testCmd( "./$plugin -H $host_snmp -C $snmp_community -d lo"); | ||
51 | cmp_ok( $res->return_code, '==', 0, "Exit OK for ifdescr lo" ); | ||
52 | like($res->output, '/^OK.*Interface.*is up/', "String contains OK Interface is up"); | ||
53 | |||
54 | $res = NPTest->testCmd( "./$plugin -H $host_snmp -C $snmp_community -k 1 -n rubbish"); | ||
55 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN if interface name doesn't match" ); | ||
56 | like($res->output, '/doesn\'t match snmp value/', "String contains 'doesn't match snmp value'"); | ||
57 | |||
58 | } | ||
59 | |||
60 | SKIP: { | ||
61 | skip "no non responsive host defined", 1 if ( ! $host_nonresponsive ); | ||
62 | $res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -C $snmp_community -k 1"); | ||
63 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING with non responsive host" ); | ||
64 | } | ||
65 | |||
66 | SKIP: { | ||
67 | skip "no invalid host defined", 2 if ( ! $hostname_invalid ); | ||
68 | $res = NPTest->testCmd( "./$plugin -H $hostname_invalid -C $snmp_community -k 1"); | ||
69 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with invalid host" ); | ||
70 | like($res->output, "/Unable to resolve.*$hostname_invalid/", "String matches unable to resolve.*$hostname_invalid"); | ||
71 | } | ||
72 | |||
73 | } | ||