diff options
author | Joachim Tingvold <joachim@tingvold.com> | 2014-04-15 20:29:02 +0200 |
---|---|---|
committer | root <root@frank.tg14.gathering.org> | 2014-04-15 20:42:27 +0200 |
commit | 3b71bacda0ddb89c8ceda0ea998c1570ecb494f7 (patch) | |
tree | 90d12f6eb72a8da5155758f6f341e6affffd9f09 | |
parent | 92f3c4d782efec737c7c8c41fff79ee987b3f90e (diff) |
When adding linknets, keep existing ones unchanged (to keep historical data).
-rwxr-xr-x | clients/build-linknets.pl | 10 | ||||
-rwxr-xr-x | dlink-ng/dlink-ng.pl | 17 |
2 files changed, 24 insertions, 3 deletions
diff --git a/clients/build-linknets.pl b/clients/build-linknets.pl index bc7374c..9978ae8 100755 --- a/clients/build-linknets.pl +++ b/clients/build-linknets.pl @@ -85,6 +85,7 @@ while (my ($sysname, $ip) = each %loopbacks) { # Now go through each linknet candidate, and see if we can find any # direct LLDP neighbors. +my $qexist = $dbh->prepare('SELECT COUNT(*) AS cnt FROM linknets WHERE switch1=? AND switch2=?'); $dbh->do('DELETE FROM linknets'); while (my ($cidr, $devices) = each %map) { for (my $i = 0; $i < scalar @$devices; ++$i) { @@ -94,10 +95,15 @@ while (my ($cidr, $devices) = each %map) { next if $device_a->[0] eq $device_b->[0]; next unless exists($lldpneigh{$device_a->[0]}{$device_b->[0]}); + my $switch_a = $switch_id{$device_a->[0]}; + my $switch_b = $switch_id{$device_b->[0]}; + my $ref = $dbh->selectrow_hashref($qexist, undef, $switch_a, $switch_b); + next if ($ref->{'cnt'} != 0); + $dbh->do('INSERT INTO linknets (switch1, addr1, switch2, addr2) VALUES (?,?,?,?)', undef, - $switch_id{$device_a->[0]}, $device_a->[1], - $switch_id{$device_b->[0]}, $device_b->[1]); + $switch_a, $device_a->[1], + $switch_b, $device_b->[1]); } } } diff --git a/dlink-ng/dlink-ng.pl b/dlink-ng/dlink-ng.pl index 9d27862..8369e05 100755 --- a/dlink-ng/dlink-ng.pl +++ b/dlink-ng/dlink-ng.pl @@ -1,4 +1,17 @@ #!/usr/bin/perl +# +# USAGE: +# +# On all switches; +# dlink-ng/make-dlink-config.pl switches.txt patchlist.txt | dlink-ng/dlink-ng.pl +# +# On a specific switch; +# dlink-ng/make-dlink-config.pl switches.txt patchlist.txt | dlink-ng/dlink-ng.pl -s e11-1 +# +# On multiple switches; +# dlink-ng/make-dlink-config.pl switches.txt patchlist.txt | grep -E "11-1|11-2|13-1|13-2" | dlink-ng/dlink-ng.pl +# +# use strict; use warnings; use Net::Telnet::Cisco; @@ -11,7 +24,9 @@ use Getopt::Long; use Net::IP; use Net::OpenSSH; BEGIN { - require "dlink-ng-config.pm"; + use File::Basename; + my $dlink_dir = dirname(__FILE__); + require "$dlink_dir/dlink-ng-config.pm"; } # Make sure dlinkconfig.pm loads config (i.e. one config type has been uncommented) |