http://qs321.pair.com?node_id=1026031


in reply to Net::SNMP ignoring retries & timeouts

Well, no wonder nobody answered. The actual bug was using this piece of code immediately after that above, which I never questioned:

if (!defined($snmpsession)) { #whatever code here, doesn't matter }

I see that snippet above all over the web in perl tutorials and the O'Reilly perl network management book. However, it's baaaaaad. As $snmpsession has not been returned a session handle, calling the defined on it simply tries the session recursively, until (some yet unknown)breaking point is reached, and the program dies, several minutes later.

A better way is to test success of the handle by reading some OID, like the snmp mgmt server status. If that is undefined, move on to the next interface.

sub muli_interface_snmp { my ($host,$community) = @_; # assumes a mib of interfaces, more likely you will have DNS d +efined for each interface my $hostip1 = $hostints{$host}{interface one}; my $hostip2 = $hostints{$host}{interface two}; my $hostip3 = $hostints{$host}{interface three}; my $hostip1 = $hostints{$host}{interface four}; my $stimeout = 5; my $sretries = 2; ## mgmt server status for your device ## don't use this one, it is bogus $MGMTSTATE = ".1.3.6.1.4.1.2666.2.1.1.1.1.7.1.12.1.1"; my $snmpsession, $test, $error; ($snmpsession,$error) = Net::SNMP->session( -hostname=>$hostip1, -timeout =>$stimeout, -retries => $sretries, -community=>$community, -version=>'snmpv2c'); $test = $snmpsession->get_request (-varbindlist => [$MGMTSTATE +]); if (!defined($test)) { ($snmpsession,$error) = Net::SNMP->session( -hostname=>$hostip2, -timeout => $stimeout, -retries => $sretries, -community=>$community, -version=>'snmpv2c'); $test = $snmpsession->get_request (-varbindlist => [$M +GMTSTATE]); if (!defined($test)) { ($snmpsession,$error) = Net::SNMP->session( -hostname=>$hostip3, -timeout => $stimeout, -retries => $sretries, -community=>$community, -version=>'snmpv2c'); $test = $snmpsession->get_request (-varbindlis +t => [$MGMTSTATE]); if ( !defined($test)) { $snmpsession = Net::SNMP->session( -hostname=>$hostip4, -timeout => $stimeout, -retries => $sretries, -community=>$community, -version=>'snmpv2c'); $test = $snmpsession->get_request (-va +rbindlist => [$MGMTSTATE]); if (!defined($test)) { # It's actually down, not just + on a standby mgmt card print DEBUGFILE $error; return; } } } } # we got a good session to the active mgmt card return $snmpsession; }

I answered myself for posterity; any other poor fools who believe what they read in books, to verify this is your problem, stop using !defined($snmpsession)... test the session with an actual OID, and good luck to you!