You will need to read the Net::SNMP documentation several times before it sinks in properly, I found. Here's a quick example of how to get the IfInOctets and IfOutOctets for interface number 1 on multiple hosts in one hit. It's not much different from the examples in the docs, though:
use warnings; use strict; use Net::SNMP; my $community="public"; # community string for devices my $interface_number=1; # interface number to poll my @ip_addresses=("192.168.5.242","192.168.11.34"); # Queue up a request to each host. foreach (@ip_addresses) { my ($session,$error)=Net::SNMP->session(-hostname=>"$_", -nonblocking=>1, -community=>"$community", -timeout=>2, -retries=>3, ); if (defined($session)) { my $in_oid=".1.3.6.1.2.1.2.2.1.10."."$interface_number"; # +OIDs to poll. my $out_oid=".1.3.6.1.2.1.2.2.1.16."."$interface_number"; my $uptime_oid=".1.3.6.1.2.1.1.3.0"; my @oids=($in_oid,$out_oid,$uptime_oid); my $result=$session->get_request( -varbindlist=>\@oids, callback=>[\&reply,$interface_number,$_] ); } else { print "Session not defined! $error\n"; } } # All requests are queued. Now dispatch them. snmp_dispatcher(); exit; # Sub "reply" is executed for each response from remote hosts. sub reply { my $obj=shift; my $interface=shift; my $ip_address=shift; if (!defined($obj->var_bind_list)) { warn "$ip_address SNMP Error.",$obj->error(),"\n"; return; } my $in_oid=".1.3.6.1.2.1.2.2.1.10."."$interface"; my $out_oid =".1.3.6.1.2.1.2.2.1.16."."$interface"; my $uptime_oid=".1.3.6.1.2.1.1.3.0"; my $uptime=$obj->var_bind_list->{$uptime_oid}; my $in=$obj->var_bind_list->{$in_oid}; my $out=$obj->var_bind_list->{$out_oid}; print "$ip_address interface number $interface bytes in: $in bytes + out: $out Uptime $uptime\n"; }

Keep these things in mind when designing this:
In non-blocking mode, it will queue all requests without actually dispatching them until you execute the snmp_dispatcher.
At that point, your program will block until all requests have been finished.
Each time a response is recieved, it will call the 'reply' subroutine.
You only get control back to the main program after all requests have either completed or timed out.
Good luck.

In reply to Re^3: threads and SNMP Session by leighsharpe
in thread threads and SNMP Session by Otogi

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.