joe_tseng has asked for the wisdom of the Perl Monks concerning the following question:

I am working on a script that will read a MIB file and essentially bulkwalk against v1 devices. I've been using SNMP::Session->getnext() while looping through varbinds and it's been working until this point. I want to use a callback function so I can improve my script's speed for collecting and saving values to my database. Oddly enough getnext() is not doing what I thought it'd do in that it's not incrementing through my OIDs when I include the callback function; getnext() seems to get stuck in an endless loop and not proceed to the next OID. I found a link that I've included below that also describes the same problem:

https://groups.google.com/forum/#!msg/comp.lang.perl.modules/wrL1vltWg3k/W-ELFiwDrFEJ

My code right now is as follows:

sub aggr_snmp_data { my $values = shift; print "Got here too: $values\n"; SNMP::finish(); } sub fetch_snmp_data { my $hashref = shift; my $argshash_ref = $hashref->{"argshash"}; my $repliedhosts_ref = $hashref->{"repliedhosts"}; my $config_file = $hashref->{"config_file"}; my %allsnmpdata; # hash to be returned to calling function my %argshash = %$argshash_ref; my $numOfHosts = scalar(@$repliedhosts_ref); my @repliedhosts = @$repliedhosts_ref; my $oids_ref = fetch_snmp_oids($config_file); # read in OID names + from config files my %oids = %{$oids_ref}; foreach $hostnode_ref (@repliedhosts) { my %hostnode = %$hostnode_ref; # hostnode node names: "name", + "id" my %results; # results per host my $branches_ref = $oids{"branches"}; $argshash{"DestHost"} = $hostnode{"name"}; # insert hostname +to be passed as arg to SNMP session handler foreach (@{$branches_ref}) { my $sess = new SNMP::Session(%argshash); $init_vb = &SNMP::translateObj($_); # internal check due +to faulty vendor MIB file my $vb = new SNMP::Varbind([$_]); my $cnt = 0; do { print "init: ".$init_vb."\n"; my $val = $sess->getnext($vb, [\&aggr_snmp_data, "foo" +]); SNMP::MainLoop(); my @node = @{$vb}; $results{$node[0]}{$node[1]} = $val; if ($cnt % 100 == 0) { print $hostnode{"name"}." recor +ds received: ".$cnt."\n"; } $new_vb = &SNMP::translateObj(@{$vb}[0]); # internal +check due to faulty vendor MIB file print "new : ".$new_vb."\n"; $cnt++; } until ($sess->{ErrorNum} || ($new_vb !~ /^$init_vb/)); +# internal check due to faulty vendor MIB file SNMP::MainLoop(); } $allsnmpdata{$hostnode{"name"}} = \%results; } return \%allsnmpdata; }

I did briefly peruse through SNMP.pm but frankly it looked like gibberish to me. Has anyone come across this issue, and how did you solve it?

thx,

- Joe