Commit 7c3853c8 authored by Robert Ricci's avatar Robert Ricci

Added a new function, getFields, which can be used to get

information about a large number of ports in bulk.

Also added the RMON MIB.
parent c9c4c702
......@@ -75,6 +75,7 @@ sub new($$;$) {
$self->{DEBUG} = 0;
}
$self->{BLOCK} = 1;
$self->{BULK} = 1;
$self->{NAME} = $name;
if ($self->{DEBUG}) {
......@@ -90,7 +91,8 @@ sub new($$;$) {
&SNMP::addMibFiles("$mibpath/CISCO-STACK-MIB.txt",
"$mibpath/CISCO-VTP-MIB.txt",
"$mibpath/CISCO-VLAN-MEMBERSHIP-MIB.txt",
"$mibpath/CISCO-PAGP-MIB.txt");
"$mibpath/CISCO-PAGP-MIB.txt",
"$mibpath/RMON-MIB.txt");
$SNMP::save_descriptions = 1; # must be set prior to mib initialization
SNMP::initMib(); # parses default list of Mib modules
......@@ -202,7 +204,7 @@ sub convertPortFormat($$@) {
# We determine the type by sampling the first port given
#
my $sample = $ports[0];
if (!$sample) {
if (!defined($sample)) {
warn "convertPortFormat: Given a bad list of ports\n";
return undef;
}
......@@ -1013,6 +1015,60 @@ sub readifIndex($) {
}
}
#
# Read a set of values for all given ports.
#
# usage: getFields(self,ports,oids)
# ports: Reference to a list of ports, in any allowable port format
# oids: A list of OIDs to reteive values for
#
# On sucess, returns a two-dimensional list indexed by port,oid
#
sub getFields($$$) {
my $self = shift;
my ($ports,$oids) = @_;
my @ifindicies = $self->convertPortFormat($PORT_FORMAT_IFINDEX,@$ports);
my @oids = @$oids;
#
# Put together an SNMP::VarList for all the values we want to get
#
my @vars = ();
foreach my $ifindex (@ifindicies) {
foreach my $oid (@oids) {
push @vars, ["$oid","$ifindex"];
}
}
#
# If we try to ask for too many things at once, we get back really bogus
# errors. So, we limit ourselves to an arbitrary number that, by
# experimentation, works.
#
my $maxvars = 16;
my @results = ();
while (@vars) {
my $varList = new SNMP::VarList(splice(@vars,0,$maxvars));
my $rv = $self->{SESS}->get($varList);
push @results, @$varList;
}
#
# Build up the two-dimensional list for returning
#
my @return = ();
foreach my $i (0 .. $#ifindicies) {
foreach my $j (0 .. $#oids) {
my $val = shift @results;
$return[$i][$j] = $$val[2];
}
}
return @return;
}
#
# Prints out a debugging message, but only if debugging is on. If a level is
# given, the debuglevel must be >= that level for the message to print. If
......@@ -1024,7 +1080,7 @@ sub debug($$:$) {
my $self = shift;
my $string = shift;
my $debuglevel = shift;
if (!(defined $debuglevel)) {
if (!(defined $debuglevel)) {
$debuglevel = 1;
}
if ($self->{DEBUG} >= $debuglevel) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment