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!


In reply to Re: Net::SNMP ignoring retries & timeouts by Mickey_C
in thread Net::SNMP ignoring retries & timeouts by Mickey_C

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.