there are a couple examples in the net-snmp/perl/SNMP/examples directory. there's also a bit in the SNMP perldoc. for the most part you just add a callback to the get command (which will get called when the reply comes back) and then call SNMP::MainLoop.
use SNMP;
my $session = SNMP::Session->new( ... );
sub callback {
if ( !defined( $_[0] ) {
warn "request timed out: $session->{ErrorStr}\n";
}
# do something with VarbindList $_[0]
}
$session->get( [[ $oid ]], \&callback );
SNMP::MainLoop();
my code is a bit more complex, taking a list of hosts, a number of outstanding reqests and a set of OIDs. it returns all of the info in a hash. i'll see if i can clean it up a bit for posting. |