aboutsummaryrefslogtreecommitdiffstats
path: root/clients
diff options
context:
space:
mode:
Diffstat (limited to 'clients')
-rwxr-xr-xclients/build-linknets.pl128
-rwxr-xr-xclients/flatify.pl21
-rw-r--r--clients/snmp.sql25
-rwxr-xr-xclients/ssendfile.pl50
4 files changed, 0 insertions, 224 deletions
diff --git a/clients/build-linknets.pl b/clients/build-linknets.pl
deleted file mode 100755
index 015e006..0000000
--- a/clients/build-linknets.pl
+++ /dev/null
@@ -1,128 +0,0 @@
-#! /usr/bin/perl
-
-# sesse testing
-
-use strict;
-use warnings;
-use lib '../include';
-use nms;
-use Net::CIDR;
-
-my $dbh = nms::db_connect();
-
-my $coregws = $dbh->prepare("SELECT switch, ip, community, sysname FROM switches WHERE sysname NOT LIKE 'e%' and sysname NOT LIKE 'sw%creativia%' AND sysname NOT LIKE 'sw%crew'")
- or die "Can't prepare query: $!";
-$coregws->execute;
-
-my %switch_id = (); # sysname -> switch database ID
-my %loopbacks = (); # sysname -> primary address
-my %loop_ipv6 = (); # sysname -> primary address
-my %map = (); # CIDR -> (sysname,ip)*
-my %lldpneigh = (); # sysname -> sysname -> 1
-
-while (my $ref = $coregws->fetchrow_hashref) {
- my $sysname = $ref->{'sysname'};
- $switch_id{$sysname} = $ref->{'switch'};
-
- print "$sysname...\n";
- my $snmp;
- eval {
- $snmp = nms::snmp_open_session($ref->{'ip'}, $ref->{'community'});
- };
- warn $@ if $@;
- next if not $snmp;
-
- my $routes = $snmp->gettable('ipCidrRouteTable');
- my $ifs = $snmp->gettable('ifTable');
- my $addrs = $snmp->gettable('ipAddrTable');
- my $lldp = $snmp->gettable('lldpRemTable');
- my $ipaddresstable = $snmp->gettable('ipAddressTable');
-
- # Find all direct routes we have, and that we also have an address in.
- # These are our linknet candidates.
- for my $route (values %$routes) {
- next if ($route->{'ipCidrRouteMask'} eq '255.255.255.255');
- next if ($route->{'ipCidrRouteNextHop'} ne '0.0.0.0');
- my $cidr = Net::CIDR::addrandmask2cidr($route->{'ipCidrRouteDest'}, $route->{'ipCidrRouteMask'});
-
- for my $addr (values %$addrs) {
- my $ip = $addr->{'ipAdEntAddr'};
- if (Net::CIDR::cidrlookup($ip, $cidr)) {
- push @{$map{$cidr}}, [ $sysname, $ip ];
- }
- }
- }
-
- # Find the first loopback address.
- my %loopbacks_this_switch = ();
- for my $addr (values %$addrs) {
- my $ifdescr = $ifs->{$addr->{'ipAdEntIfIndex'}}->{'ifDescr'};
- next unless $ifdescr =~ /^Loop/;
- $loopbacks_this_switch{$ifdescr} = $addr->{'ipAdEntAddr'};
- }
- for my $if (sort keys %loopbacks_this_switch) {
- $loopbacks{$sysname} = $loopbacks_this_switch{$if};
- last;
- }
-
- my %loopbacks_ipv6_this_switch = ();
- for my $addr (values %$ipaddresstable) {
- next if not $addr->{'ipAddressAddrType'} == 2; # Only IPv6 addresses please.
- my $ifdescr = $ifs->{$addr->{'ipAddressIfIndex'}}->{'ifDescr'};
- next unless $ifdescr =~ /^Loop/;
- $loopbacks_ipv6_this_switch{$ifdescr} = nms::convert_ipv6( $addr->{'ipAddressAddr'} );
- }
- for my $if (sort keys %loopbacks_ipv6_this_switch) {
- $loop_ipv6{$sysname} = $loopbacks_ipv6_this_switch{$if};
- last;
- }
-
- # Find all LLDP neighbors.
- for my $neigh (values %$lldp) {
- $lldpneigh{lc($sysname)}{lc($neigh->{'lldpRemSysName'})} = 1;
- }
-}
-
-# print Dumper(\%switch_id);
-# print Dumper(\%map);
-# print Dumper(\%loopbacks);
-# print Dumper(\%lldpneigh);
-
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
-
-# Update the switches we have loopback addresses fora
-while (my ($sysname, $ip) = each %loopbacks) {
- $dbh->do('UPDATE switches SET ip=? WHERE sysname=?',
- undef, $ip, $sysname);
-}
-while (my ($sysname, $ipv6) = each %loop_ipv6) {
- $dbh->do('UPDATE switches SET secondary_ip=? WHERE sysname=?',
- undef, $ipv6, $sysname);
-}
-
-# 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) {
- my $device_a = $devices->[$i];
- for (my $j = $i + 1; $j < scalar @$devices; ++$j) {
- my $device_b = $devices->[$j];
- next if $device_a->[0] eq $device_b->[0];
- next unless exists($lldpneigh{lc($device_a->[0])}{lc($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_a, $device_a->[1],
- $switch_b, $device_b->[1]);
- }
- }
-}
-$dbh->commit;
diff --git a/clients/flatify.pl b/clients/flatify.pl
deleted file mode 100755
index f2aa18a..0000000
--- a/clients/flatify.pl
+++ /dev/null
@@ -1,21 +0,0 @@
-#! /usr/bin/perl
-
-# Make the given switch into a D-Link placement-wise.
-
-use strict;
-use warnings;
-use lib '../include';
-use nms;
-
-my $dbh = nms::db_connect();
-my $q = $dbh->prepare('SELECT switch,placement FROM switches NATURAL JOIN placements WHERE sysname LIKE ?');
-$q->execute('%'.$ARGV[0].'%');
-
-while (my $ref = $q->fetchrow_hashref) {
- $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/ or die;
- my ($x1,$y1,$x2,$y2) = ($1, $2, $3, $4);
- my $placement = sprintf "(%d,%d),(%d,%d)", $x2 - 100, $y2 - 16, $x2, $y2;
- $dbh->do("UPDATE placements SET placement=? WHERE switch=?",
- undef, $placement, $ref->{'switch'});
- last; # Take only one.
-}
diff --git a/clients/snmp.sql b/clients/snmp.sql
deleted file mode 100644
index 7e09313..0000000
--- a/clients/snmp.sql
+++ /dev/null
@@ -1,25 +0,0 @@
-create table switchtypes (
- switchtype varchar not null primary key,
- ports varchar not null
-);
-
-create table switches (
- switch serial not null primary key,
- ip inet not null,
- secondary_ip inet,
- sysname varchar not null,
- switchtype varchar not null references switchtypes,
- last_updated timestamp,
- locked boolean not null default 'f'
-);
-
-create table poll (
- time timestamp not null,
- switch integer not null references switches,
- port integer not null,
- bytes_in bigint not null,
- bytes_out bigint not null,
-
- primary key ( time, switch, port )
-);
-create index poll_switch_port on poll ( switch, port );
diff --git a/clients/ssendfile.pl b/clients/ssendfile.pl
deleted file mode 100755
index 224f4e2..0000000
--- a/clients/ssendfile.pl
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/perl
-use warnings;
-use strict;
-use lib '../include';
-use POSIX;
-
-my $delaytime = 30;
-my $poll_frequency = 60;
-
-sub mylog {
- my $msg = shift;
- my $time = POSIX::ctime(time);
- $time =~ s/\n.*$//;
- printf STDERR "[%s] %s\n", $time, $msg;
-}
-
-if ($#ARGV != 1) {
- die("Error in arguments passed\n".
- "./ssendfile.pl addr configfile\n");
-}
-
-my $ssh = nms::switch_connect_ssh($ARGV[0]);
-my $conn = $ssh->{telnet};
-if (!defined($conn)) {
- die("Could not connect to switch.\n");
-}
-
-open(CONFIG, $ARGV[1]);
-while (<CONFIG>) {
- my $cmd = $_;
- $cmd =~ s/[\r\n]+//g;
- print "Executing: `$cmd`\n";
-# if ($cmd =~ /ip ifconfig swif0 (\d{1-3}\.\d{1-3}\.\d{1-3}\.\d{1-3})/) {
-# print "New ip: $1\n";
-# $conn->cmd( String => $cmd,
-# Timeout => 3);
-# $ssh = nms::switch_connect_ssh($1);
-# $conn = $ssh->{telnet};
-# if (!defined($conn)) {
-# die "Could not connect to new ip: $1\n";
-# }
-# }
-# else {
- my @data = nms::switch_exec($cmd, $conn);
- foreach my $line (@data) {
- $line =~ s/[\r\n]+//g;
- print "$line\n";
- }
-# }
-}