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



  • 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.