From a2e48f6ed2cae97f85ef1c0ffd85be72cec89ba6 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 6 Apr 2014 11:53:36 +0200 Subject: Add a possibly useful little wrapper to fetch lots of different SNMP values at the same time. --- include/nms.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'include') 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; -- cgit v1.2.3