diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2016-03-27 08:27:17 +0200 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2016-03-27 08:27:17 +0200 |
commit | 1d2470a411e5eaac7e5a1c5d5b6b81e92c92f4a8 (patch) | |
tree | 54b901757b088d54d33e70f28a6203383b4dc844 /clients | |
parent | 0a230ac5481b9518abc64181dbbb4509d83c0b89 (diff) | |
parent | 96a9bb4c42f4b53020302fea2a46e734c61c0319 (diff) |
Merge branch 'master' of github.com:tech-server/tgmanage
Diffstat (limited to 'clients')
-rwxr-xr-x | clients/build-linknets.pl | 128 | ||||
-rwxr-xr-x | clients/fetch-cubemap-munin.sh | 17 | ||||
-rwxr-xr-x | clients/flatify.pl | 21 | ||||
-rwxr-xr-x | clients/ping.pl | 8 | ||||
-rw-r--r-- | clients/snmp.sql | 25 | ||||
-rwxr-xr-x | clients/snmpfetchng.pl | 37 | ||||
-rwxr-xr-x | clients/ssendfile.pl | 50 |
7 files changed, 28 insertions, 258 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/fetch-cubemap-munin.sh b/clients/fetch-cubemap-munin.sh index 2beb8bc..0cc62e2 100755 --- a/clients/fetch-cubemap-munin.sh +++ b/clients/fetch-cubemap-munin.sh @@ -1,10 +1,17 @@ #!/bin/bash -#cp -p "/var/cache/munin/www/tg15.gathering.org/seamus.tg15.gathering.org/cubemap-day.png" "/root/tgmanage/examples/tg15/streamstats/cubemap_seamus_-`date +%Y%m%d_%H%M`.png" -#cp -p "/var/cache/munin/www/tg15.gathering.org/maggie.tg15.gathering.org/cubemap-day.png" "/root/tgmanage/examples/tg15/streamstats/cubemap_maggie_-`date +%Y%m%d_%H%M`.png" +tgyear="tg16" +reflector1="finn" +reflector2="rey" -epoch_to=`date +%s` +if [ $# -eq 0 ]; then + epoch_to=`date +%s` + epoch_date="`date +%Y%m%d-%H%M`" +else + epoch_to=`date --date "$1" +%s` + epoch_date="`date --date \"$1\" +%Y%m%d-%H%M`" +fi let "epoch_from = epoch_to - (60 * 60 * 24)" -wget -qO"/root/tgmanage/examples/tg15/streamstats/cubemap_maggie_detailed-`date +%Y%m%d-%H%M`.png" "http://munin.tg15.gathering.org/munin-cgi/munin-cgi-graph/tg15.gathering.org/maggie.tg15.gathering.org/cubemap-pinpoint=$epoch_from,$epoch_to.png?&lower_limit=&upper_limit=&size_x=1280&size_y=720" -wget -qO"/root/tgmanage/examples/tg15/streamstats/cubemap_seamus_detailed-`date +%Y%m%d-%H%M`.png" "http://munin.tg15.gathering.org/munin-cgi/munin-cgi-graph/tg15.gathering.org/seamus.tg15.gathering.org/cubemap-pinpoint=$epoch_from,$epoch_to.png?&lower_limit=&upper_limit=&size_x=1280&size_y=720" +wget -qO"/root/tgmanage/examples/$tgyear/streams/streamstats/cubemap_${reflector1}_detailed-$epoch_date.png" "http://munin.$tgyear.gathering.org/munin-cgi/munin-cgi-graph/$tgyear.gathering.org/${reflector1}.$tgyear.gathering.org/cubemap-pinpoint=$epoch_from,$epoch_to.png?&lower_limit=&upper_limit=&size_x=1280&size_y=720" +wget -qO"/root/tgmanage/examples/$tgyear/streams/streamstats/cubemap_${reflector2}_detailed-$epoch_date.png" "http://munin.$tgyear.gathering.org/munin-cgi/munin-cgi-graph/$tgyear.gathering.org/${reflector2}.$tgyear.gathering.org/cubemap-pinpoint=$epoch_from,$epoch_to.png?&lower_limit=&upper_limit=&size_x=1280&size_y=720" 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/ping.pl b/clients/ping.pl index 27aa878..d945917 100755 --- a/clients/ping.pl +++ b/clients/ping.pl @@ -15,13 +15,13 @@ my $dbh = nms::db_connect(); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; -my $q = $dbh->prepare("SELECT switch,host(ip) as ip,host(secondary_ip) as secondary_ip FROM switches WHERE ip is not null ORDER BY random()"); -my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets"); +my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null ORDER BY random()"); +my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null"); while (1) { # ping loopbacks my $ping = Net::Oping->new; - $ping->timeout(0.2); + $ping->timeout(0.3); $q->execute; my %ip_to_switch = (); @@ -73,7 +73,7 @@ while (1) { $dbh->commit; # ping linknets $ping = Net::Oping->new; - $ping->timeout(0.2); + $ping->timeout(0.3); $lq->execute; my @linknets = (); 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/snmpfetchng.pl b/clients/snmpfetchng.pl index e813499..2f5e785 100755 --- a/clients/snmpfetchng.pl +++ b/clients/snmpfetchng.pl @@ -9,13 +9,12 @@ use Data::Dumper; use lib '../include'; use nms; -SNMP::addMibDirs("/tmp/tmp.esQYrkg9MW/v2"); -SNMP::loadModules('SNMPv2-MIB'); -SNMP::loadModules('ENTITY-MIB'); -SNMP::loadModules('IF-MIB'); -SNMP::loadModules('LLDP-MIB'); -SNMP::loadModules('IP-MIB'); -SNMP::loadModules('IP-FORWARD-MIB'); +SNMP::initMib(); +SNMP::addMibDirs("/srv/tgmanage/mibs/StandardMibs"); +SNMP::addMibDirs("/srv/tgmanage/mibs/JuniperMibs"); +SNMP::addMibDirs("/srv/tgmanage/mibs"); +SNMP::loadModules('ALL'); + our $dbh = nms::db_connect(); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; @@ -23,13 +22,13 @@ $dbh->{RaiseError} = 1; my $qualification = <<"EOF"; (last_updated IS NULL OR now() - last_updated > poll_frequency) AND (locked='f' OR now() - last_updated > '15 minutes'::interval) -AND ip is not null +AND mgmt_v4_addr is not null EOF # Borrowed from snmpfetch.pl our $qswitch = $dbh->prepare(<<"EOF") SELECT - sysname,switch,host(ip) as ip,community, + sysname,switch,host(mgmt_v4_addr) as ip,community, DATE_TRUNC('second', now() - last_updated - poll_frequency) AS overdue FROM switches @@ -48,8 +47,6 @@ my @switches = (); my $sth = $dbh->prepare("INSERT INTO snmp (switch,data) VALUES((select switch from switches where sysname=?), ?)"); -our $outstanding = 0; - sub mylog { my $msg = shift; @@ -61,17 +58,10 @@ sub mylog sub populate_switches { @switches = (); - my $limit = $nms::config::snmp_max - $outstanding; - if ($limit < 0) { - mylog("Something wrong. Too many outstanding polls going."); - $limit = 1; - } - if ($outstanding > 0) { - mylog("Outstanding polls: $outstanding . Current limit: $limit"); - } + my $limit = $nms::config::snmp_max; $qswitch->execute($limit) or die "Couldn't get switch"; - + $dbh->commit; while (my $ref = $qswitch->fetchrow_hashref()) { push @switches, { 'sysname' => $ref->{'sysname'}, @@ -87,7 +77,6 @@ sub inner_loop populate_switches(); my $poll_todo = ""; for my $refswitch (@switches) { - $outstanding++; my %switch = %{$refswitch}; $poll_todo .= "$switch{'sysname'} "; @@ -102,11 +91,10 @@ sub inner_loop my $ret = $s->bulkwalk(0, 10, @nms::config::snmp_objects, sub{ callback(\%switch, @_); }); if (!defined($ret)) { mylog("Fudge: ". $s->{'ErrorStr'}); - $outstanding--; } } mylog( "Polling " . @switches . " switches: $poll_todo"); - SNMP::MainLoop(5); + SNMP::MainLoop(10); } sub callback{ @@ -146,8 +134,7 @@ sub callback{ $qunlock->execute($switch{'id'}) or die "Couldn't unlock switch"; $dbh->commit; - $outstanding--; - mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s. ($outstanding outstanding polls)"); + mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s."); } while (1) { inner_loop(); 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"; - } -# } -} |