diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-07-31 06:45:30 (GMT) |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-07-31 07:07:38 (GMT) |
commit | 8a96ee4741633cf8e832903f7ce0f542a77dbed8 (patch) | |
tree | 5d237bbcca8f3c4007ead8d71170b8cd1c895408 /plugins/tests/check_snmp.t | |
parent | e0be2e6094a54771a7a310eea5853d2e05edf480 (diff) | |
download | monitoring-plugins-8a96ee4741633cf8e832903f7ce0f542a77dbed8.tar.gz |
Add tests using custom snmp agent
Only multi-line string test for now (regression test), counter rollover
tests planed with my snmp_counters_new branch.
NB: 64bit counters are broken in NetSNMP::agent from NetSNMP version 5.4.1
and lower, but might come in handy one day
Diffstat (limited to 'plugins/tests/check_snmp.t')
-rwxr-xr-x | plugins/tests/check_snmp.t | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t new file mode 100755 index 0000000..fcd15ea --- /dev/null +++ b/plugins/tests/check_snmp.t | |||
@@ -0,0 +1,56 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # Test check_snmp by having an actual SNMP agent running | ||
4 | # | ||
5 | |||
6 | use strict; | ||
7 | use Test::More; | ||
8 | use NPTest; | ||
9 | use FindBin qw($Bin); | ||
10 | |||
11 | my $port_snmp = 16100 + int(rand(100)); | ||
12 | my $running = 1; | ||
13 | |||
14 | |||
15 | # Start up server | ||
16 | my @pids; | ||
17 | my $pid = fork(); | ||
18 | if ($pid) { | ||
19 | # Parent | ||
20 | push @pids, $pid; | ||
21 | # give our agent some time to startup | ||
22 | sleep(1); | ||
23 | } else { | ||
24 | # Child | ||
25 | #print "child\n"; | ||
26 | |||
27 | print "Please contact SNMP at: $port_snmp\n"; | ||
28 | close(STDERR); # Coment out to debug snmpd problems (most errors sent there are OK) | ||
29 | exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp"); | ||
30 | } | ||
31 | |||
32 | END { | ||
33 | foreach my $pid (@pids) { | ||
34 | if ($pid) { print "Killing $pid\n"; kill "INT", $pid } | ||
35 | } | ||
36 | }; | ||
37 | |||
38 | if ($ARGV[0] && $ARGV[0] eq "-d") { | ||
39 | while (1) { | ||
40 | sleep 100; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | my $tests = 2; | ||
45 | if (-x "./check_snmp") { | ||
46 | plan tests => $tests; | ||
47 | } else { | ||
48 | plan skip_all => "No check_snmp compiled"; | ||
49 | } | ||
50 | |||
51 | my $res; | ||
52 | |||
53 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0"); | ||
54 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" ); | ||
55 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
56 | |||