mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-03-28 13:23:32 -04:00
lines so this new test fails on the current head.
Note: check_snmp v1.4.13 with multi-line strings return somewhat v3 output;
it's not exactly what the specs say but it doesn't appears to break them
either. The fix could eventually supports both v2 and v3 output formats.
63 lines
1.5 KiB
Perl
Executable file
63 lines
1.5 KiB
Perl
Executable file
#! /usr/bin/perl -w -I ..
|
|
#
|
|
# Test check_snmp by having an actual SNMP agent running
|
|
#
|
|
|
|
use strict;
|
|
use Test::More;
|
|
use NPTest;
|
|
use FindBin qw($Bin);
|
|
|
|
my $port_snmp = 16100 + int(rand(100));
|
|
my $running = 1;
|
|
|
|
|
|
# Start up server
|
|
my @pids;
|
|
my $pid = fork();
|
|
if ($pid) {
|
|
# Parent
|
|
push @pids, $pid;
|
|
# give our agent some time to startup
|
|
sleep(1);
|
|
} else {
|
|
# Child
|
|
#print "child\n";
|
|
|
|
print "Please contact SNMP at: $port_snmp\n";
|
|
close(STDERR); # Coment out to debug snmpd problems (most errors sent there are OK)
|
|
exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp");
|
|
}
|
|
|
|
END {
|
|
foreach my $pid (@pids) {
|
|
if ($pid) { print "Killing $pid\n"; kill "INT", $pid }
|
|
}
|
|
};
|
|
|
|
if ($ARGV[0] && $ARGV[0] eq "-d") {
|
|
while (1) {
|
|
sleep 100;
|
|
}
|
|
}
|
|
|
|
my $tests = 3;
|
|
if (-x "./check_snmp") {
|
|
plan tests => $tests;
|
|
} else {
|
|
plan skip_all => "No check_snmp compiled";
|
|
}
|
|
|
|
my $res;
|
|
|
|
$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");
|
|
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" );
|
|
like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
|
|
like($res->output, '/'.quotemeta('SNMP OK - "Cisco Internetwork Operating System SoftwareIOS (tm) Catalyst 4000 L3 Switch Software (cat4000-I9K91S-M), Version
|
|
12.2(20)EWA, RELEASE SOFTWARE (fc1)
|
|
Technical Support: http://www.cisco.com/techsupport
|
|
Copyright (c) 1986-2004 by cisco Systems, Inc.
|
|
"').'/m', "String contains all lines");
|
|
|
|
print $res->output;
|
|
|