diff options
author | Steinar H. Gunderson <sgunderson@bigfoot.com> | 2014-04-06 11:53:36 +0200 |
---|---|---|
committer | Steinar H. Gunderson <sgunderson@bigfoot.com> | 2014-04-06 11:55:22 +0200 |
commit | a2e48f6ed2cae97f85ef1c0ffd85be72cec89ba6 (patch) | |
tree | ccf266fe58e1a46545eaff51a1df4f61861bcf15 | |
parent | 64e1dab38b26b32c1e53605a0788b7ad49d2af09 (diff) |
Add a possibly useful little wrapper to fetch lots of different SNMP values at the same time.
-rw-r--r-- | include/nms.pm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/nms.pm b/include/nms.pm index 047c243..13689a2 100644 --- a/include/nms.pm +++ b/include/nms.pm @@ -134,4 +134,27 @@ sub snmp_open_session { return $session; } +# Not currently in use; kept around for reference. +sub fetch_multi_snmp { + my ($session, @oids) = @_; + + my %results = (); + + # Do bulk reads of 40 and 40; seems to be about the right size for 1500-byte packets. + for (my $i = 0; $i < scalar @oids; $i += 40) { + my $end = $i + 39; + $end = $#oids if ($end > $#oids); + my @oid_slice = @oids[$i..$end]; + + my $localresults = $session->get_request(-varbindlist => \@oid_slice); + return undef if (!defined($localresults)); + + while (my ($key, $value) = each %$localresults) { + $results{$key} = $value; + } + } + + return \%results; +} + 1; |