Commit 4d2c3a77 authored by Robert Ricci's avatar Robert Ricci

Add a column to switch_stack_types that allows you to override the

default SNMP community string (from configure) for individual
switch stacks.
parent 8fec9ba3
......@@ -940,6 +940,7 @@ CREATE TABLE switch_stack_types (
stack_type varchar(10) default NULL,
supports_private tinyint(1) NOT NULL default '0',
single_domain tinyint(1) NOT NULL default '1',
snmp_community varchar(32) default NULL,
PRIMARY KEY (stack_id)
) TYPE=MyISAM;
......
......@@ -407,7 +407,7 @@ foreach my $command (@commands) {
#
my @stacks;
foreach my $stack_id (keys %stacks) {
my ($stack_type, $supports_private, $single_domain)
my ($stack_type, $supports_private, $single_domain, $community)
= getStackType($stack_id);
#
# Safety check - make sure the stack supports private VLANs if -y was
......@@ -416,18 +416,27 @@ foreach my $command (@commands) {
if ($opt{y} && !$supports_private) {
die "Switch stack $stack_id does not support private VLANs\n";
}
#
# If we got back a special community to use for this switch, use it -
# otherwise, use the default we got from configure
#
if (!$community) {
$community = $COMMUNITY;
}
my $stack;
debug("Stack $stack_id has type $stack_type\n");
SWITCH: for ($stack_type) {
/cisco/ && do {
require snmpit_cisco_stack;
$stack = new snmpit_cisco_stack($stack_id,$debug,$COMMUNITY,
$stack = new snmpit_cisco_stack($stack_id,$debug,$community,
$supports_private, $single_domain, @{$stacks{$stack_id}});
last;
}; # /cisco/
/intel/ && do {
require snmpit_intel_stack;
$stack = new snmpit_intel_stack($stack_id,$debug,$COMMUNITY,
$stack = new snmpit_intel_stack($stack_id,$debug,$community,
@{$stacks{$stack_id}});
last;
};
......
......@@ -332,20 +332,22 @@ sub getSwitchStack($) {
#
# Returns the type of the given stack_id. If called in list context, also
# returns whether or not the stack supports private VLANs, and whether it
# uses a single VLAN domain
# returns whether or not the stack supports private VLANs, whether it
# uses a single VLAN domain, and the SNMP community to use.
#
sub getStackType($) {
my $stack = shift;
my $result = DBQueryFatal("SELECT stack_type, supports_private, " .
" single_domain FROM switch_stack_types WHERE stack_id='$stack'");
"single_domain, snmp_community FROM switch_stack_types " .
"WHERE stack_id='$stack'");
if (!$result->numrows()) {
print STDERR "No stack found called $stack\n";
return undef;
} else {
my ($stack_type,$supports_private,$single_domain) = ($result->fetchrow());
my ($stack_type,$supports_private,$single_domain,$community)
= ($result->fetchrow());
if (defined wantarray) {
return ($stack_type,$supports_private,$single_domain);
return ($stack_type,$supports_private,$single_domain, $community);
} else {
return $stack_type;
}
......
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