From: Sorrell, A. <Al_...@tr...> - 2002-02-08 14:50:17
|
Here's a brief snippet: sub bulkget { # # Called with 3 or 4 arguments to retrieve a series of instances of # an oid. If using SNMP version >1, will use s 'getbulk' method, # otherwise uses repeated 'getnext' # The instances are returned as a hash indexed by the # instance number, and further indexed by $new if specified # $sess is the SNMP session handle returned by SNMP::Session # $oid is the object identifier to fetch # $n is the maximum number of repetitions to fetch # $new is a second index for the returned hash, if present # my ($sess,$oid,$n,$new)=@_; my %b; my $vars = new SNMP::VarList ( [$oid]); print "In bulkget, \$sess->Version=$sess->{Version} oid=$oid, n=$n\n" if($DEBUG); if($sess->{Version} ne '1') { while(1) { $sess->getbulk(0,$n,$vars); warn "Getting $oid, $sess->{ErrorStr}\n" if $sess->{ErrorNum}; foreach (@$vars) { $tag=$_->tag; $iid=$_->iid; $val=$_->val; last if ($tag !~ /$oid/); print " $tag $iid = $val\n" if($DEBUG>2); if(defined($new)) { $b{$iid}{$new}=$val; } else { $b{$iid}=$val; } } last if($tag !~ /$oid/); $vars = new SNMP::VarList ( [$oid]); foreach (@$vars) { $_->[1]=$iid; } print " using getbulk again from iid=$iid\n" if($DEBUG); } } else { print "bulkget using getnexts :oid=$oid, n=$n\n" if($DEBUG>1); while (1) { my($val)=$sess->getnext($vars); last if($$vars[0]->tag ne $oid || $sess->{ErrorStr}); $iid=$$vars[0]->iid; $tag=$$vars[0]->tag; print "bulkget:$tag $iid = $val\n" if($DEBUG>2); if(defined($new)) { $b{$iid}{$new}=$val; } else { $b{$iid}=$val; } } } return %b; } -----Original Message----- From: Eric Greenwood [mailto:eri...@im...] Sent: Thursday, February 07, 2002 10:16 PM To: net...@li... Subject: net::snmp bulkwalk perl example I would appreciate an example in perl of a bulkwalk function that will return a table of values from a snmp agent. for example, the shell script ./snmpbulkwalk -v 2c host community rttMonStatsCaptureTable will return an arbitray number of named values, I would like to do this using the perl API and save the results in rrdtool. Eric |