Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-16 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found