AnyEvent::SNMP breaks Net::SNMP error handling

Jafar.Aliev Jafar.Aliev at micex.com
Wed Dec 5 18:01:08 CET 2012


Good day.

While I've developed my project with Net::SNMP and AnyEvent::SNMP I've 
noticed one issue in error handling: callback function does not fire in 
error condition. In my situation one host does not answer to SNMP 
request and in pure Net::SNMP implementation callback fired after 
certain timeout. If I've used AnyEvent::SNMP, callback does not fired in 
same circumstances.

==[Working instance]======================================
use strict;
use warnings;
use utf8;
use feature ':5.10';

use Net::SNMP ':snmp';

sub someHandler {
	my $snmpSess = shift;
	if ( defined $snmpSess->var_bind_list( ) ) {
		say "OK!";
	} else {
		say "Error!";
	}
	return;
}
my ( $snmpSession, $snmpError ) = Net::SNMP->session (
	-hostname => '<some failed host>',
	-community => 'public',
	-version => 'snmpv2c',	
	-nonblocking => 1 );

$snmpResult = $snmpSession->get_bulk_request (
	-callback => \&someHandler,
	-varbindlist => '<some OID>'
);

snmp_dispatcher( );
==[/Working instance]=======================================


==[Non-working instance]====================================
use strict;
use warnings;
use utf8;
use feature ':5.10';

use AnyEvent;
use AnyEvent::Strict;
use AnyEvent::SNMP;
use Net::SNMP ':snmp';

sub someHandler {
	my $snmpSess = shift;
	if ( defined $snmpSess->var_bind_list( ) ) {
		say "OK!";
	} else {
		say "Error!";
	}
	return;
}
my $cv = AnyEvent->condvar;
my $timerW = AnyEvent->timer ( after => 10, cb => sub { exit } );

my ( $snmpSession, $snmpError ) = Net::SNMP->session (
	-hostname => '<some failed host>',
	-community => 'public',
	-version => 'snmpv2c',	
	-nonblocking => 1 );

$snmpResult = $snmpSession->get_bulk_request (
	-callback => \&someHandler,
	-varbindlist => '<some OID>'
);

my $res = $cv->recv;
==[/Non-working instance]===================================

My system:
OpenSuSE 12.1 x64
perl 5.12.4
( osname=linux, osvers=3.1.0-rc10-1-default, 
archname=x86_64-linux-thread-multi )
AnyEvent 7.04
AnyEvent::SNMP 6.0
Net::SNMP 6.0.1

Best regards and thank you in advance.

-- 
Jafar Aliev


More information about the anyevent mailing list