Commit 96ce1770 authored by Robert Ricci's avatar Robert Ricci

Add support for Cisco IOS-based switches, which support a slightly different

set of MIBs, and index some of the tables differently.

This requires some more information to be passed when switch and stack objects
are created.

Also, make the SNMP community to use overridable in the defs file.
parent 31d1db9a
......@@ -857,6 +857,7 @@ fi
#
......@@ -1201,7 +1202,7 @@ fi
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
# ./install, which can be erroneously created by make from ./install.sh.
echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
echo "configure:1205: checking for a BSD compatible install" >&5
echo "configure:1206: checking for a BSD compatible install" >&5
if test -z "$INSTALL"; then
if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
......@@ -1514,6 +1515,7 @@ s%@DISABLE_EVENT_SCHED@%$DISABLE_EVENT_SCHED%g
s%@CLIENT_ETCDIR@%$CLIENT_ETCDIR%g
s%@CLIENT_BINDIR@%$CLIENT_BINDIR%g
s%@CLIENT_VARDIR@%$CLIENT_VARDIR%g
s%@SNMP_RW_COMMUNITY@%$SNMP_RW_COMMUNITY%g
s%@LEDA@%$LEDA%g
s%@ASSIGN@%$ASSIGN%g
s%@SSH_ARGS@%$SSH_ARGS%g
......
......@@ -48,6 +48,7 @@ AC_SUBST(DISABLE_EVENT_SCHED)
AC_SUBST(CLIENT_ETCDIR)
AC_SUBST(CLIENT_BINDIR)
AC_SUBST(CLIENT_VARDIR)
AC_SUBST(SNMP_RW_COMMUNITY)
#
# Defaults for for above variables.
......
......@@ -18,6 +18,7 @@
use lib '@prefix@/lib';
my $TESTMODE = @TESTMODE@;
my $TB = '@prefix@';
my $COMMUNITY ='@SNMP_RW_COMMUNITY@';
use libdb;
use snmpit_lib;
......@@ -31,6 +32,10 @@ use strict;
#
my $debug = 0;
if (!$COMMUNITY) {
$COMMUNITY = "public";
}
######################################################################
# Step 1 - Process command-line arguments
#
......@@ -334,14 +339,14 @@ foreach my $command (@commands) {
SWITCH: for ($stack_type) {
/cisco/ && do {
require snmpit_cisco_stack;
$stack = new snmpit_cisco_stack($stack_id,$debug,
@{$stacks{$stack_id}});
$stack = new snmpit_cisco_stack($stack_id,$debug,$COMMUNITY,
@{$stacks{$stack_id}});
last;
}; # /cisco/
/intel/ && do {
require snmpit_intel_stack;
$stack = new snmpit_intel_stack($stack_id,$debug,
@{$stacks{$stack_id}});
$stack = new snmpit_intel_stack($stack_id,$debug,$COMMUNITY,
@{$stacks{$stack_id}});
last;
};
......
......@@ -59,7 +59,7 @@ my $PORT_FORMAT_NODEPORT = 3;
# usage: new($classname,$devicename,$debuglevel)
# returns a new object, blessed into the snmpit_cisco class.
#
sub new($$;$) {
sub new($$$$;$) {
# The next two lines are some voodoo taken from perltoot(1)
my $proto = shift;
......@@ -67,6 +67,8 @@ sub new($$;$) {
my $name = shift;
my $debugLevel = shift;
my $switchtype = shift;
my $community = shift;
#
# Create the actual object
......@@ -84,6 +86,16 @@ sub new($$;$) {
$self->{BLOCK} = 1;
$self->{BULK} = 1;
$self->{NAME} = $name;
$self->{COMMUNITY} = $community;
# Figure out some stuff about this switch
$switchtype =~ /^(\w+)(-ios)?$/;
$self->{SWITHCTYPE} = $1;
if ($2) {
$self->{OSTYPE} = "IOS";
} else {
$self->{OSTYPE} = "CatOS";
}
if ($self->{DEBUG}) {
print "snmpit_cisco module initializing... debug level $self->{DEBUG}\n";
......@@ -95,10 +107,23 @@ sub new($$;$) {
$SNMP::debugging = ($self->{DEBUG} - 2) if $self->{DEBUG} > 2;
my $mibpath = '/usr/local/share/snmp/mibs';
&SNMP::addMibDirs($mibpath);
&SNMP::addMibFiles("$mibpath/CISCO-STACK-MIB.txt",
"$mibpath/CISCO-VTP-MIB.txt",
"$mibpath/CISCO-PAGP-MIB.txt",
"$mibpath/RMON-MIB.txt");
# We list all MIBs we use, so that we don't depend on a correct .index file
my @mibs = ("$mibpath/SNMPv2-SMI.txt", "$mibpath/SNMPv2-TC.txt",
"$mibpath/SNMPv2-MIB.txt", "$mibpath/IANAifType-MIB.txt",
"$mibpath/IF-MIB.txt", "$mibpath/RMON-MIB.txt",
"$mibpath/CISCO-SMI.txt", "$mibpath/CISCO-TC.txt",
"$mibpath/CISCO-VTP-MIB.txt", "$mibpath/CISCO-PAGP-MIB.txt");
if ($self->{OSTYPE} eq "CatOS") {
push @mibs, "$mibpath/CISCO-STACK-MIB.txt";
} elsif ($self->{OSTYPE} eq "IOS") {
push @mibs, "$mibpath/CISCO-VLAN-MEMBERSHIP-MIB.txt";
} else {
warn "ERROR: Unsupported switch OS $self->{OSTYPE}\n";
return undef;
}
&SNMP::addMibFiles(@mibs);
$SNMP::save_descriptions = 1; # must be set prior to mib initialization
SNMP::initMib(); # parses default list of Mib modules
......@@ -106,7 +131,8 @@ sub new($$;$) {
warn ("Opening SNMP session to $self->{NAME}...") if ($self->{DEBUG});
$self->{SESS} =
new SNMP::Session(DestHost => $self->{NAME},Version => "2c");
new SNMP::Session(DestHost => $self->{NAME},Version => "2c",
Community => $self->{COMMUNITY});
if (!$self->{SESS}) {
#
# Bomb out if the session could not be established
......@@ -574,7 +600,12 @@ sub setPortVlan($$@) {
my $vlan_id = shift;
my @ports = @_;
my $PortVlanMemb = "vlanPortVlan"; #index is ifIndex
my $PortVlanMemb;
if ($self->{OSTYPE} eq "CatOS") {
$PortVlanMemb = "vlanPortVlan"; #index is ifIndex
} elsif ($self->{OSTYPE} eq "IOS") {
$PortVlanMemb = "vmVlan"; #index is ifIndex
}
my $errors = 0;
......@@ -589,9 +620,16 @@ sub setPortVlan($$@) {
$self->debug("Found VLAN with ID $vlan_id: $vlan_number\n");
#
# Convert ports from the format the were passed in to IfIndex format
# Convert ports from the format the were passed in to the correct format
#
my @portlist = $self->convertPortFormat($PORT_FORMAT_MODPORT,@ports);
my $format;
if ($self->{OSTYPE} eq "CatOS") {
$format = $PORT_FORMAT_MODPORT;
} elsif ($self->{OSTYPE} eq "IOS") {
$format = $PORT_FORMAT_IFINDEX;
}
my @portlist = $self->convertPortFormat($format,@ports);
#
# We'll keep track of which ports suceeded, so that we don't try to
......@@ -674,7 +712,12 @@ sub removePortsFromVlan($@) {
#
# Get a list of the ports in the VLAN
#
my $VlanPortVlan = ["vlanPortVlan"]; # index by module.port, gives vlan
my $VlanPortVlan;
if ($self->{OSTYPE} eq "CatOS") {
$VlanPortVlan = "vlanPortVlan"; #index is ifIndex
} elsif ($self->{OSTYPE} eq "IOS") {
$VlanPortVlan = "vmVlan"; #index is ifIndex
}
my @ports;
#
......@@ -831,7 +874,13 @@ sub listVlans($) {
$self->debug("Getting VLAN info...\n");
# We don't need VlanIndex really...
my $VlanName = ["vtpVlanName"]; # index by 1.vlan #
my $VlanPortVlan = ["vlanPortVlan"]; # index by module.port, gives vlan #
my $VlanPortVlan;
if ($self->{OSTYPE} eq "CatOS") {
$VlanPortVlan = "vlanPortVlan"; #index is ifIndex
} elsif ($self->{OSTYPE} eq "IOS") {
$VlanPortVlan = "vmVlan"; #index is ifIndex
}
#
# Walk the tree to find the VLAN names
......@@ -860,8 +909,10 @@ sub listVlans($) {
foreach my $rowref (@$rows) {
my ($name,$modport,$vlan_number) = @$rowref;
$self->debug("Got $name $modport $vlan_number\n",3);
my $node;
($node = portnum("$self->{NAME}:$modport")) || ($node = "port$modport");
my ($node) = $self->convertPortFormat($PORT_FORMAT_NODEPORT,$modport);
if (!$node) {
$node = "port$modport";
}
push @{$Members{$vlan_number}}, $node;
}
......@@ -1064,15 +1115,40 @@ sub readifIndex($) {
my $self = shift;
#
# Walk the tree for portIfIndex
# How we fill this table is highly dependant on which OS the switch
# is running - CatOS provides a convenient table to convert from
# node/port to ifindex, but under IOS, we have to infer it from the
# port description
#
my ($rows) = $self->{SESS}->bulkwalk(0,32,["portIfIndex"]);
if ($self->{OSTYPE} eq "CatOS") {
my ($rows) = $self->{SESS}->bulkwalk(0,32,["portIfIndex"]);
foreach my $rowref (@$rows) {
my ($name,$modport,$ifindex) = @$rowref;
$self->{IFINDEX}{$modport} = $ifindex;
$self->{IFINDEX}{$ifindex} = $modport;
}
} elsif ($self->{OSTYPE} eq "IOS") {
my ($rows) = $self->{SESS}->bulkwalk(0,32,["ifDescr"]);
foreach my $rowref (@$rows) {
my ($name,$modport,$ifindex) = @$rowref;
foreach my $rowref (@$rows) {
my ($name,$iid,$descr) = @$rowref;
if ($descr =~ /(\d+)\/(\d+)$/) {
my $modport = "$1.$2";
my $ifindex;
if (defined($iid) && ($iid ne "")) {
$ifindex = $iid;
} else {
$name =~ /(\d+)$/;
$ifindex = $1;
}
$self->{IFINDEX}{$modport} = $ifindex;
$self->{IFINDEX}{$ifindex} = $modport;
$self->{IFINDEX}{$modport} = $ifindex;
$self->{IFINDEX}{$ifindex} = $modport;
}
}
}
}
......
......@@ -35,7 +35,7 @@ use libdb;
# usage: new(string name, string stack_id, int debuglevel, list of devicenames)
# returns a new object blessed into the snmpit_cisco_stack class
#
sub new($$#@) {
sub new($$$#@) {
# The next two lines are some voodoo taken from perltoot(1)
my $proto = shift;
......@@ -43,6 +43,7 @@ sub new($$#@) {
my $stack_id = shift;
my $debuglevel = shift;
my $community = shift;
my @devicenames = @_;
#
......@@ -93,7 +94,8 @@ sub new($$#@) {
SWITCH: for ($type) {
(/cisco6509/ || /cisco4006/) && do {
use snmpit_cisco;
$device = new snmpit_cisco($devicename,$self->{DEBUG});
$device = new snmpit_cisco($devicename,$self->{DEBUG},$type,
$community);
if (!$device) {
die "Failed to create a device object for $devicename\n";
} else {
......
......@@ -59,6 +59,7 @@ sub new {
my $name = shift;
my $debugLevel = shift;
my $community = shift;
#
# Create the actual object
......@@ -76,6 +77,7 @@ sub new {
$self->{BLOCK} = 1;
$self->{CONFIRM} = 1;
$self->{NAME} = $name;
$self->{COMMUNITY} = $community;
if ($self->{DEBUG}) {
print "snmpit_intel module initializing... debug level $self->{DEBUG}\n"
......@@ -105,7 +107,8 @@ sub new {
warn ("Opening SNMP session to $self->{NAME}...") if ($self->{DEBUG});
$self->{SESS} = new SNMP::Session(DestHost => $self->{NAME});
$self->{SESS} = new SNMP::Session(DestHost => $self->{NAME},
Community => $self->{COMMUNITY});
if (!$self->{SESS}) {
#
......
......@@ -37,7 +37,7 @@ use libdb;
# returns a new object blessed into the snmpit_intel_stack class
#
sub new($$#@) {
sub new($$$#@) {
# The next two lines are some voodoo taken from perltoot(1)
my $proto = shift;
......@@ -45,6 +45,7 @@ sub new($$#@) {
my $stack_id = shift;
my $debuglevel = shift;
my $community = shift;
my @devicenames = @_; # Devicenames are not presently needed for Intel
# stacks
......@@ -73,7 +74,7 @@ sub new($$#@) {
# talk to one (for now) to do all the setup we need.
#
use snmpit_intel;
$self->{LEADER} = new snmpit_intel($stack_id,$self->{DEBUG});
$self->{LEADER} = new snmpit_intel($stack_id,$self->{DEBUG},$community);
#
# Check for failed object creation
......
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