Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Since your problem has specifically to do with SNMP polling, you probably ought to have a look at the callback function in the SNMP.pm module that comes with Net-SNMP (NOT the Net::SNMP module from CPAN). With it, you can set up several (more than 100) concurrent SNMP sessions at once. I use this to scan my network for new devices. Here's the code:
... # Open the SNMP session and query in the background. $sess = new SNMP::Session(DestHost => $thisip, Community => $$optionsref{community}, Retries => $$optionsref{retries}, Timeout => $$optionsref{timeout}, Version => '1'); $mib = 'sysDescr'; $vb = new SNMP::Varbind([$mib]); # The responses to our queries are stored in %list. $var = $sess->getnext($vb, [ \&gotit, $thisip, \%list ]); # Update the rate limiting counter. $count++; # After every 100 IP's, wait for the timeout period (default is two se +conds) to keep from overwhelming routers with ARP queries. if ( $count > '100' ) { &SNMP::MainLoop($looptimer); $count = 0; } # Increment the IP address for the next pass. $intip++; ... # This is the little function called by SNMP::MainLoop when a callback + comes in. It just stuffs the value of the response (if any) into th +e appropriate place in %list and returns. sub gotit { my $myip = shift; my $listref = shift; my $vl = shift; if ( defined $$vl[0] ) { $$listref{$myip}{desc} = $$vl[0]->val; } return(); }
You then set your "connection" limit however you want. I used 100 as an arbitrary limit above. Since IP addresses are accepted by inet_aton($someint), you can just convert IPs to integers and increment them to step through a subnet or range of IP addresses. Here's the conversion:
($octet1, $octet2, $octet3, $octet4) = split /\./, $$argsref{ip}; $intip = ($octet1 * (256 ** 3)) + ($octet2 * (256 ** 2)) + ($octet3 * +256) + $octet4;
Probably a little kludgy, but it works. There's probably a more elegant way to do it using inet_aton() and then converting directly from the 32-bit packed value to an int, but I haven't worked it out yet.

Anyway, hopefully the callback stuff above will help you out. See 'perldoc SNMP' for more info on that.

--Rhys


In reply to Re: Fork Pool? by Rhys
in thread Fork Pool? by crackotter

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 perusing the Monastery: (5)
As of 2024-04-19 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found