Commit b2d10b20 authored by Mac Newbold's avatar Mac Newbold

Added vlandiff and vlansync, plus related changes to makefile, configure.

parent 4f980442
......@@ -951,7 +951,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \
tmcd/netbsd/GNUmakefile \
tmcd/tmcd.restart \
utils/GNUmakefile \
utils/GNUmakefile utils/vlandiff utils/vlansync \
www/GNUmakefile www/defs.php3 www/dbdefs.php3"
#
......
......@@ -124,7 +124,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \
tmcd/netbsd/GNUmakefile \
tmcd/tmcd.restart \
utils/GNUmakefile \
utils/GNUmakefile utils/vlandiff utils/vlansync \
www/GNUmakefile www/defs.php3 www/dbdefs.php3"
#
......
......@@ -9,7 +9,7 @@ SUBDIR = utils
include $(OBJDIR)/Makeconf
BIN_SCRIPTS = delay_config
SBIN_SCRIPTS =
SBIN_SCRIPTS = vlandiff vlansync
#
# Force dependencies on the scripts so that they will be rerun through
......
#!/usr/local/bin/perl -w
#
# vlandiff - Show differences between switch state and vlan table, if any
#
my $TBROOT = "@prefix@";
my $DBNAME = "@TBDBNAME@";
$ENV{'PATH'} = '@prefix@/sbin:@prefix@/bin:/bin';
my $debug = 0;
use Mysql;
my $dbh;
my $sth;
my %table = ();
my %switch= ();
# Get all the vlans from the table
$dbh = Mysql->connect("localhost",$DBNAME,"script","none");
$sth = $dbh->
query("select id,members from vlans");
while (@row = $sth->fetchrow_array()) {
my @list = split(" ",$row[1]);
foreach $port (@list) {
my ($node,$card) = split(":",$port);
#if ($node =~ /^(sh\d+)/) { $node = "$1-1"; }
if ($card =~ /[a-zA-Z]/) {
# specified ala ethX
my $sth2 = $dbh->
query("select card from interfaces where node_id='$node' ".
"and iface='$card'");
$card = ($sth2->fetchrow_array())[0];
print "Had '$port', changed to '$node:$card'\n" if $debug;
$port = "$node:$card";
}
}
$table{$row[0]} = join(" ",sort @list);
print "In table: vlan $row[0]: $table{$row[0]}\n" if $debug;
}
# Get all the vlans from the switch
my $list;
open(LIST,"snmpit -l |") || die ("vlandiff: couldn't run snmpit: $!\n");
while(<LIST>) {
chop;
if (/(^ID)|(^--)|(^1 )/) { next; }
s/[\t ]+/ /g;
/(\d+)\s+(\S+)(?:\s+(.*)?)?/;
if (!defined $3) { $list = ""; } else { $list = $3; }
if ($2 ne "default") {
$switch{$2} = join(" ", sort split(" ",$list));
print "On switch: vlan $2: $switch{$2}\n" if $debug;
}
}
close(LIST);
# Compare all of them...
foreach $key (sort keys %table) {
if ( defined $switch{$key} && ($switch{$key} eq $table{$key}) ) {
# If its in both lists, delete it from both
print "vlan table:$key ($table{$key}) matches switch:$key ($switch{$key})\n"
if $debug;
delete $switch{$key};
delete $table{$key};
}
}
# Print out the difference
my $rv = 0;
if (keys %table) {
print "In vlans table only:\n";
foreach $key(sort keys %table) {
print "$key\t$table{$key}\n";
}
$rv++;
}
if (keys %switch) {
print "On switch only:\n";
foreach $key(sort keys %switch) {
print "$key\t$switch{$key}\n";
}
$rv++;
}
# Return 0 if same, 1 for a one-sided diff, 2 for a two-sided diff
# (Could be changed to return total # of different vlans)
exit($rv);
#!/usr/local/bin/perl -w
#
# vlansync - Synchronize the switch vlans to what's in the vlans table
# by removing extra vlans/ports, and adding missing ones
#
die("Unimplemented so far... coming soon. - Mac\n");
my $TBROOT = "@prefix@";
my $DBNAME = "@TBDBNAME@";
$ENV{'PATH'} = '@prefix@/sbin:@prefix@/bin:/bin';
my $debug = 0;
use Mysql;
my $dbh;
my $sth;
my %table = ();
my %switch= ();
# Get all the vlans from the table
$dbh = Mysql->connect("localhost",$DBNAME,"script","none");
$sth = $dbh->
query("select id,members from vlans");
while (@row = $sth->fetchrow_array()) {
my @list = split(" ",$row[1]);
foreach $port (@list) {
my ($node,$card) = split(":",$port);
#if ($node =~ /^(sh\d+)/) { $node = "$1-1"; }
if ($card =~ /[a-zA-Z]/) {
# specified ala ethX
my $sth2 = $dbh->
query("select card from interfaces where node_id='$node' ".
"and iface='$card'");
$card = ($sth2->fetchrow_array())[0];
print "Had '$port', changed to '$node:$card'\n" if $debug;
$port = "$node:$card";
}
}
$table{$row[0]} = join(" ",sort @list);
print "In table: vlan $row[0]: $table{$row[0]}\n" if $debug;
}
# Get all the vlans from the switch
my $list;
open(LIST,"snmpit -l |") || die ("vlandiff: couldn't run snmpit: $!\n");
while(<LIST>) {
chop;
if (/(^ID)|(^--)|(^1 )/) { next; }
s/[\t ]+/ /g;
/(\d+)\s+(\S+)(?:\s+(.*)?)?/;
if (!defined $3) { $list = ""; } else { $list = $3; }
if ($2 ne "default") {
$switch{$2} = join(" ", sort split(" ",$list));
print "On switch: vlan $2: $switch{$2}\n" if $debug;
}
}
close(LIST);
# Compare all of them...
foreach $key (sort keys %table) {
if ( defined $switch{$key} && ($switch{$key} eq $table{$key}) ) {
# If its in both lists, delete it from both
print "vlan table:$key ($table{$key}) matches switch:$key ($switch{$key})\n"
if $debug;
delete $switch{$key};
delete $table{$key};
}
}
# Print out the difference
my $rv = 0;
if (keys %table) {
print "In vlans table only:\n";
foreach $key(sort keys %table) {
print "$key\t$table{$key}\n";
}
$rv++;
}
if (keys %switch) {
print "On switch only:\n";
foreach $key(sort keys %switch) {
print "$key\t$switch{$key}\n";
}
$rv++;
}
# Return 0 if same, 1 for a one-sided diff, 2 for a two-sided diff
# (Could be changed to return total # of different vlans)
exit($rv);
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