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 community:".$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;