mmoorreett has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I have a script that collects SNMP data from lots of devices using AnyEvent::SNMP. It works well, but I have noticed that it hangs if $session->get_table throws an error. I've tried various ways to handle the error and end the request but nothing seems to work. I'm guessing that it hangs because $cv->end is not called because the error is not handled.
Here is a snippet of code that explains it. I've trawled through many AnyEvent examples but can't seem to find anything to help so hoping someone can help. The program is complex so i've provided only the relevant blocks to illustrate:
my $cv = AnyEvent->condvar; foreach my $host (sort keys %hosts) { my ($session, $error) = Net::SNMP->session ( -hostname => $host, -community => $host_snmp_community, -version => $host_snmp_version, -nonblocking => 1, ) or $log->error("Error creating SNMP session for $host commun +ity:".$host_snmp_community." version:".$host_snmp_version); foreach my $table_oid (sort keys %snmp_tables) { $cv->begin; $session->get_table( -baseoid => $snmp_table, # can't use this option for snmp v1 #-maxrepetitions => 1, -callback => sub{ $hosts{$host}{oid_ +results_table}->{$snmp_table}= &snmp_collect(@_); $cv->end; } ) } } $cv->recv;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error handling in AnyEvent::SNMP
by bliako (Abbot) on May 28, 2021 at 04:39 UTC | |
by mmoorreett (Acolyte) on May 28, 2021 at 20:31 UTC | |
by bliako (Abbot) on Jun 01, 2021 at 04:14 UTC |