Code

5605b003294e20e90c93c7f510a8380ab9a56bdd
[nagiosplug.git] / plugins / tests / check_snmp.t
1 #! /usr/bin/perl -w -I ..
2 #
3 # Test check_snmp by having an actual SNMP agent running
4 #
6 use strict;
7 use Test::More;
8 use NPTest;
9 use FindBin qw($Bin);
11 my $port_snmp = 16100 + int(rand(100));
12 my $running = 1;
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";
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 }
32 END { 
33         foreach my $pid (@pids) {
34                 if ($pid) { print "Killing $pid\n"; kill "INT", $pid } 
35         }
36 };
38 if ($ARGV[0] && $ARGV[0] eq "-d") {
39         while (1) {
40                 sleep 100;
41         }
42 }
44 my $tests = 3;
45 if (-x "./check_snmp") {
46         plan tests => $tests;
47 } else {
48         plan skip_all => "No check_snmp compiled";
49 }
51 my $res;
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 like($res->output, '/'.quotemeta('SNMP OK - "Cisco Internetwork Operating System SoftwareIOS (tm) Catalyst 4000 L3 Switch Software (cat4000-I9K91S-M), Version
57 12.2(20)EWA, RELEASE SOFTWARE (fc1)
58 Technical Support: http://www.cisco.com/techsupport
59 Copyright (c) 1986-2004 by cisco Systems, Inc.
60 "').'/m', "String contains all lines");
62 print $res->output;