aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorOle Mathias Heggem <olemathias.aa.heggem@gmail.com>2023-01-21 19:07:38 +0100
committerOle Mathias Heggem <olemathias.aa.heggem@gmail.com>2023-01-21 19:07:38 +0100
commit709c78569b26677624e60588fa1166dc659ac93c (patch)
tree2bd5555af31b637d03693b8563fb24b41bf1f22b /tools
parentf5da0d943401e527f5162e9c6344deb65b19b045 (diff)
chore: cleanup repo
Diffstat (limited to 'tools')
-rwxr-xr-xtools/add_switches.txt.pl17
-rwxr-xr-xtools/cubemap-stats.pl130
-rwxr-xr-xtools/deplist.sh22
-rwxr-xr-xtools/generate-dnsrr.pl149
-rwxr-xr-xtools/generate-rowdns.pl111
-rwxr-xr-xtools/get_mibs.sh15
-rwxr-xr-xtools/lldp/dotnet.sh9
-rwxr-xr-xtools/lldp/draw-neighbors.pl35
-rwxr-xr-xtools/lldp/lldpdiscover.pl280
-rwxr-xr-xtools/make-linknet-hosts.pl58
-rw-r--r--tools/sql-strip.pl35
11 files changed, 0 insertions, 861 deletions
diff --git a/tools/add_switches.txt.pl b/tools/add_switches.txt.pl
deleted file mode 100755
index 635e356..0000000
--- a/tools/add_switches.txt.pl
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/perl
-# Usage: ./add_switches.txt.pl < switches.txt > switches.json
-#
-# Parses switches.txt into json currently just throws it to stdout
-#
-# Actually adding them to a DB comes later.
-
-use strict;
-use warnings;
-use Data::Dumper;
-use lib '../include';
-use JSON;
-use nms::util;
-
-my @switches = parse_switches_txt(*STDIN);
-
-print JSON::XS::encode_json(\@switches);
diff --git a/tools/cubemap-stats.pl b/tools/cubemap-stats.pl
deleted file mode 100755
index 401424a..0000000
--- a/tools/cubemap-stats.pl
+++ /dev/null
@@ -1,130 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-use POSIX qw(strftime);
-use NetAddr::IP;
-use Net::IP;
-
-my (%streams, %ips, %total);
-$total{count}{c} = 0;
-$total{unique_count}{c} = 0;
-$total{count}{int} = 0;
-$total{unique_count}{int} = 0;
-$total{count}{ext} = 0;
-$total{unique_count}{ext} = 0;
-
-sub stream_name {
- my $stream = shift;
- $stream =~ s/\///g;
- return $stream;
-}
-
-# Is client in the network?
-sub is_in_network{
- my ($ip, $ipv4, $ipv6) = @_;
- my $in_scope = 0;
- my $ipv4_range = NetAddr::IP->new($ipv4);
- my $ipv6_range = NetAddr::IP->new($ipv6);
-
- if (Net::IP->new($ip)->ip_is_ipv4()){
- if (NetAddr::IP->new($ip)->within($ipv4_range)){
- $in_scope = 1;
- }
- } else {
- if (NetAddr::IP->new($ip)->within($ipv6_range)){
- $in_scope = 1;
- }
- }
-
- return $in_scope;
-}
-
-# add count
-sub add_count{
- my ($date, $stream_name, $count_name, $count_type) = @_;
-
- if($streams{$date}{$stream_name}{$count_name}{$count_type}){
- $streams{$date}{$stream_name}{$count_name}{$count_type}++;
- } else {
- $streams{$date}{$stream_name}{$count_name}{$count_type} = 1;
- }
-}
-
-sub print_info{
- foreach my $date (sort keys %streams) {
- print "### $date\n";
- foreach my $stream (sort keys %{$streams{$date}}){
- my $stream_name = stream_name($stream);
- printf "\t%s: %s (%s) - Int: %s (%s), Ext: %s (%s)\n",
- $stream_name,
- $streams{$date}{$stream}{count}{c},
- $streams{$date}{$stream}{unique_count}{c},
- $streams{$date}{$stream}{count}{int},
- $streams{$date}{$stream}{unique_count}{int},
- $streams{$date}{$stream}{count}{ext},
- $streams{$date}{$stream}{unique_count}{ext},
- }
- }
- print "\n\nTotal: $total{count}{c} ($total{unique_count}{c})\n";
- print "Internal: $total{count}{int} ($total{unique_count}{int})\n";
- print "External: $total{count}{ext} ($total{unique_count}{ext})\n";
-}
-
-while (<STDIN>) {
- chomp;
- my ($epoch, $ip, $stream, $connected_time, $bytes_sent, $loss_bytes, $loss_events) = /^(\d+) (\S+) (\S+) (\d+) (\d+) (\d+) (\d+)/ or next;
-
- next if ($stream =~ m/-/);
- next if ($stream =~ m/test/);
-
- my $stream_name = stream_name($stream);
-
- my $date = strftime("%d %b %Y", localtime($epoch));
-
- my $internal = is_in_network($ip, '151.216.128.0/17', '2a02:ed02::/32');
- unless($internal){
- # check server /24
- $internal = is_in_network($ip, '185.12.59.0/24', '2a02:ed02::/32');
- }
-
- print "$date, $stream_name, $ip, $internal\n";
-
- if($ips{$date}{$ip}){
- # already viewed this day
-
- add_count($date, $stream_name, 'count', 'c');
-
- if($internal){
- add_count($date, $stream_name, 'count', 'int');
- $total{count}{int}++;
- } else {
- add_count($date, $stream_name, 'count', 'ext');
- $total{count}{ext}++;
- }
-
- $total{count}{c}++;
- } else {
- # not viewed this day
- $ips{$date}{$ip} = 1;
-
- add_count($date, $stream_name, 'count', 'c');
- add_count($date, $stream_name, 'unique_count', 'c');
-
- if($internal){
- add_count($date, $stream_name, 'count', 'int');
- add_count($date, $stream_name, 'unique_count', 'int');
- $total{count}{int}++;
- $total{unique_count}{int}++;
- } else {
- add_count($date, $stream_name, 'count', 'ext');
- add_count($date, $stream_name, 'unique_count', 'ext');
- $total{count}{ext}++;
- $total{unique_count}{ext}++;
- }
-
- $total{count}{c}++;
- $total{unique_count}{c}++;
- }
-}
-
-print_info(); \ No newline at end of file
diff --git a/tools/deplist.sh b/tools/deplist.sh
deleted file mode 100755
index cd2ecc0..0000000
--- a/tools/deplist.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-# Generate a dependency list for debian packages needed to work
-#
-# This is ... somewhat extensive. And a good incentive for people to clean
-# up their mess.
-
-(
-cat <<_EOF_
-use lib '../include';
-use lib '../web/streamlib';
-_EOF_
-find ../ -name '*pl' -exec egrep '^use ' {} \; | sort | uniq
-cat <<_EOF_
-foreach my \$key (keys %INC) {
- if (\$INC{\$key} =~ m/^\./) {
- next;
- }
- print \$INC{\$key} . "\n";
-}
-_EOF_
-) | perl 2>/dev/null | xargs realpath | xargs dpkg -S | awk '{print $1}' | sed 's/:$//' | sort | uniq
diff --git a/tools/generate-dnsrr.pl b/tools/generate-dnsrr.pl
deleted file mode 100755
index 99ff395..0000000
--- a/tools/generate-dnsrr.pl
+++ /dev/null
@@ -1,149 +0,0 @@
-#!/usr/bin/perl -I /root/tgmanage
-#
-# USAGE:
-# Generate BIND Zone-file data based on the file hosts-to-add.txt
-# cat hosts-to-add.txt | tools/generate-dnsrr.pl
-#
-# Generate input data for nsupdate, to add FORWARD records based on hosts-to-add.txt
-# cat hosts-to-add.txt | tools/generate-dnsrr.pl --domain foo.tgXX.gathering.org -ns
-#
-# Generate input data for nsupdate, to add REVERSE records based on hosts-to-add.txt
-# cat hosts-to-add.txt | tools/generate-dnsrr.pl --domain foo.tgXX.gathering.org -ns -rev
-#
-# Generate input data for nsupdate, to DELETE forward records based on hosts-to-add.txt
-# cat hosts-to-DELETE.txt | tools/generate-dnsrr.pl --domain foo.tgXX.gathering.org -ns -del
-#
-# Generate input data for nsupdate, to DELETE reverse records based on hosts-to-add.txt
-# cat hosts-to-DELETE.txt | tools/generate-dnsrr.pl --domain foo.tgXX.gathering.org -ns -rev -del
-#
-# Command-syntax to send this to nsupdate, running it on the DNS server:
-# cat file.txt | tools/generate-dnsrr.pl --dom foo -ns | ssh $dnsserver "nsupdate -k /etc/bind/Kdhcp_updater.+157+XXXXX"
-#
-# Generate DNS for linknets:
-# cat /tmp/linknets.txt | perl -wple 's,;, ,g' | perl tools/make-linknet-hosts.pl | tools/generate-dnsrr.pl --domain tgXX.gathering.org -ns -rev | ssh $dnsserver "nsupdate -k /etc/bind/Kdhcp_updater.XXXXX"
-#
-# Format of input:
-# hostname ipv4-adress ipv6-address
-# If any of ipv4-address or ipv6-address are NOT set for the host, specify "nope"
-# Lines starting with # will (should) be skipped (comments)
-#
-# Example:
-#
-# host1 192.168.0.1 2001:db8:f00::1
-# host2 nope 2001:db8:f00::2
-# host3 192.168.0.3 nope
-# # comment, to be ignored.
-# host4 192.168.0.4
-
-use strict;
-use warnings;
-use lib '..';
-BEGIN {
- require "include/config.pm";
- eval {
- require "include/config.local.pm";
- };
-}
-use Net::IP;
-use Getopt::Long;
-
-my ($delete, $auto, $nsupdate, $reverse, $domain);
-
-if (@ARGV > 0) {
- GetOptions(
- 'del|delete' => \$delete,
- 'a|auto' => \$auto,
- 'ns|nsupdate' => \$nsupdate,
- 'r|reverse' => \$reverse,
- 'domain=s' => \$domain
- )
-}
-
-if ($nsupdate || $reverse){
- unless (defined($domain)){
- print "Missing domain.\n";
- exit 1 unless defined($domain);
- }
-}
-
-$domain = "." . $domain if defined($domain);
-
-print "server $nms::config::pri_v4\n" if ($nsupdate || $reverse);
-
-while (<STDIN>) {
- next if /^(#|\s+$)/; # skip if comment, or blank line
-
- my ($hostname, $ipv4, $ipv6) = split;
- $hostname = lc($hostname);
-
- unless ($ipv6){
- if ($auto){
- # Get IPv6-address based on IPv4-address
-
- my ($first, $second, $third, $fourth) = split('\.', $ipv4);
- # TODO: Need to do some more logic, since base_ipv6net looks like '2a02:ed02::/32'
- #$ipv6 = $nms::config::base_ipv6net . $third . "::" . $fourth;
- }
- }
-
- if ($reverse){
- # print ptr
- print_ptr($hostname, $ipv4, $ipv6);
- } else {
- # print forward
- print_fwd($hostname, $ipv4, $ipv6);
- }
-}
-
-sub print_ptr{
- my ($hostname, $ipv4, $ipv6) = @_;
-
- # IPv4
- unless ( $ipv4 eq "nope" ) {
- my $v4 = new Net::IP($ipv4);
-
- print "update add " . $v4->reverse_ip() . " 3600 IN PTR " . $hostname . $domain .".\n" unless $delete;
- print "update delete " . $v4->reverse_ip() . " IN PTR\n" if $delete;
- print "send\n";
- }
-
- # IPv6
- if (( not ($ipv6 eq "nope") ) && ( $ipv6 )) {
- my $v6 = new Net::IP($ipv6);
-
- print "update add " . $v6->reverse_ip() . " 3600 IN PTR " . $hostname . $domain . ".\n" unless $delete;
- print "update delete " . $v6->reverse_ip() . " IN PTR\n" if $delete;
- print "send\n";
- }
-}
-
-sub print_fwd{
- my ($hostname, $ipv4, $ipv6) = @_;
-
- if ($nsupdate){
-
- unless ( $ipv4 eq "nope" ) {
- # IPv4
- print "prereq nxrrset " . $hostname . $domain . " IN A\n" unless $delete;
- print "update add " . $hostname . $domain . " 3600 IN A $ipv4\n" unless $delete;
- print "update delete " . $hostname . $domain . " IN A\n" if $delete;
- print "send\n";
- }
- if (( not ($ipv6 eq "nope") ) && ( $ipv6 )) {
- # IPv6
- print "prereq nxrrset " . $hostname . $domain . " IN AAAA\n" unless $delete;
- print "update add " . $hostname . $domain . " 3600 IN AAAA $ipv6\n" unless $delete;
- print "update delete " . $hostname . $domain . " IN AAAA\n" if $delete;
- print "send\n";
- }
- } else {
- # IPv4
- unless ( $ipv4 eq "nope" ) {
- printf ("%-24s%s\t%s\t%s\n", $hostname, "IN", "A", $ipv4);
- }
- # IPv6
- if (( not ($ipv6 eq "nope") ) && ( $ipv6 )) {
- printf ("%-24s%s\t%s\t%s\n", $hostname, "IN", "AAAA", $ipv6) if ($ipv6);
- }
- }
-}
diff --git a/tools/generate-rowdns.pl b/tools/generate-rowdns.pl
deleted file mode 100755
index a37c0c8..0000000
--- a/tools/generate-rowdns.pl
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/usr/bin/perl
-use strict;
-
-BEGIN {
- require "include/config.pm";
-}
-
-use JSON -support_by_pp;
-use LWP 5.64;
-use LWP::UserAgent;
-use Net::SSL; # needed, else LWP goes into emo-mode
-use Net::IP;
-use NetAddr::IP;
-use Getopt::Long;
-
-my ($delete, $infra);
-
-if (@ARGV > 0) {
- GetOptions(
- 'del|delete' => \$delete,
- 'infra' => \$infra, # generate switch forward
- )
-}
-
-# Use this to generate nsupdate for all edge switches
-
-# fetch PI API content
-sub get_url{
- my $url = shift;
-
- $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; # just to be sure :-D
- my $ua = LWP::UserAgent->new;
- my $req = HTTP::Request->new(GET => $url);
- $req->authorization_basic($nms::config::gondul_user, $nms::config::gondul_pass);
-
- return $ua->request($req)->content();
-}
-
-my $json_obj = new JSON;
-my $json_content = get_url($nms::config::gondul_url . "/api/read/switches-management");
-
-if($json_content){
- my $json = $json_obj->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($json_content);
-
- print "server $nms::config::pri_v4\n";
-
- foreach my $switch (values %{$json->{switches}}){
- next unless ($switch->{subnet4}); # require at least IPv4 client subnet
- next unless ($switch->{sysname} =~ m/^e[0-9]+?\-/); # only rows
-
- (my $v4mgmt = $switch->{mgmt_v4_addr}) =~ s/\/[0-9]{1,2}//;
- (my $v6mgmt = $switch->{mgmt_v6_addr}) =~ s/\/[0-9]{1,2}//;
- (my $v4gw = NetAddr::IP->new($switch->{subnet4})->first()) =~ s/\/[0-9]{1,2}//;
- (my $v6gw = NetAddr::IP->new($switch->{subnet6})->first()) =~ s/\/[0-9]{1,2}//;
-
- my $fqdn = $switch->{sysname} . "." . $nms::config::tgname . ".gathering.org.";
- my $sw_fqdn = "sw." . $fqdn;
- my $gw_fqdn = "gw." . $fqdn;
-
- if($infra){
- # Add A and AAAA-records for the switch to the infra.tgNN.gathering.org-zone
- my $sw_infra = $switch->{sysname} . ".infra." . $nms::config::tgname . ".gathering.org.";
- printf ("%-24s%s\t%s\t%s\n", $switch->{sysname}, "IN", "A", $v4mgmt);
- printf ("%-24s%s\t%s\t%s\n", $switch->{sysname}, "IN", "AAAA", $v6mgmt);
- } else {
- # A and AAAA-record to the switch
- if($delete){
- print "update delete $sw_fqdn \t IN A\n";
- print "update delete $sw_fqdn \t IN AAAA\n";
- } else {
- print "update add $sw_fqdn \t 3600 IN A \t $v4mgmt\n";
- print "update add $sw_fqdn \t 3600 IN AAAA \t $v6mgmt\n";
- }
- print "send\n";
-
- # PTR to the switch
- if($delete){
- print "update delete " . Net::IP->new($v4mgmt)->reverse_ip() . " \t IN PTR\n" if $v4mgmt;
- print "send\n" if $v4mgmt;
- print "update delete " . Net::IP->new($v6mgmt)->reverse_ip() . " \t IN PTR\n" if $v6mgmt
- } else {
- print "update add " . Net::IP->new($v4mgmt)->reverse_ip() . " \t 3600 IN PTR \t $sw_fqdn\n" if $v4mgmt;
- print "send\n" if $v4mgmt;
- print "update add " . Net::IP->new($v6mgmt)->reverse_ip() . " \t 3600 IN PTR \t $sw_fqdn\n" if $v6mgmt;
- }
- print "send\n";
-
- # A and AAAA-record to the gateway/router
- if($delete){
- print "update delete $gw_fqdn \t IN A\n";
- print "update delete $gw_fqdn \t IN AAAA\n";
- } else {
- print "update add $gw_fqdn \t 3600 IN A \t $v4gw\n" if $v4gw;
- print "update add $gw_fqdn \t 3600 IN AAAA \t $v6gw\n" if $v6gw;
- }
- print "send\n";
-
- # PTR to the gateway/router
- if($delete){
- print "update delete " . Net::IP->new($v4gw)->reverse_ip() . " \t IN PTR\n" if $v4gw;
- print "send\n" if $v4gw;
- print "update delete " . Net::IP->new($v6gw)->reverse_ip() . " \t IN PTR\n" if $v6gw;
- } else {
- print "update add " . Net::IP->new($v4gw)->reverse_ip() . " \t 3600 IN PTR \t $gw_fqdn\n" if $v4gw;
- print "send\n" if $v4gw;
- print "update add " . Net::IP->new($v6gw)->reverse_ip() . " \t 3600 IN PTR \t $gw_fqdn\n" if $v6gw;
- }
- print "send\n";
- }
- }
-}
diff --git a/tools/get_mibs.sh b/tools/get_mibs.sh
deleted file mode 100755
index 7c8cc52..0000000
--- a/tools/get_mibs.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-ORIGPWD=$PWD
-TMP=$(mktemp -d)
-set -x
-set -e
-cd $TMP
-wget ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz
-tar xvzf v2.tar.gz --strip-components=2
-mkdir -p mibs
-
-cp v2/* mibs/
-mv mibs ${ORIGPWD}/
-cd ${ORIGPWD}
-rm -rf ${TMP}
diff --git a/tools/lldp/dotnet.sh b/tools/lldp/dotnet.sh
deleted file mode 100755
index 5c1b369..0000000
--- a/tools/lldp/dotnet.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env bash
-
-DATE="$(date +%s)"
-if [ -z "$1" ] || [ -z "$2" ]; then
- echo "Usage: $0 <ip> <community>"
- exit 1;
-fi
-./lldpdiscover.pl $1 $2 | ./draw-neighbors.pl | dot -Tpng > dotnet-${DATE}.png
-echo File name: dotnet-${DATE}.png
diff --git a/tools/lldp/draw-neighbors.pl b/tools/lldp/draw-neighbors.pl
deleted file mode 100755
index 323e676..0000000
--- a/tools/lldp/draw-neighbors.pl
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use JSON;
-
-my $in;
-while (<STDIN>) {
- $in .= $_;
-}
-
-my %assets = %{JSON::XS::decode_json($in)};
-
-print "strict graph network {\n";
-while (my ($key, $value) = each %assets) {
- print_tree ($key,0,undef);
-}
-print "}\n";
-
-sub print_tree
-{
- my ($chassis_id,$indent,$parent,$max) = @_;
- if (!defined($parent)) {
- $parent = "";
- }
- if ($indent > 50) {
- die "Possible loop detected.";
- }
- print " \"$assets{$chassis_id}{sysName}\" -- {";
- my @n;
- while (my ($key, $value) = each %{$assets{$chassis_id}{neighbors}}) {
- push @n, "\"$assets{$key}{sysName}\"";
- }
- print join(",",@n) . "};\n";
-}
-
diff --git a/tools/lldp/lldpdiscover.pl b/tools/lldp/lldpdiscover.pl
deleted file mode 100755
index 7ecf969..0000000
--- a/tools/lldp/lldpdiscover.pl
+++ /dev/null
@@ -1,280 +0,0 @@
-#! /usr/bin/perl
-#
-# Basic tool to discover your neighbourhood systems, using LLDP, as seen
-# through SNMP.
-#
-# Usage: ./lldpdiscover.pl <ip> <community>
-#
-# This will connect to <ip> and poll it for SNMP-data, then add that to an
-# asset database. After that's done, we parse the LLDP neighbor table
-# provided over SNMP and add those systems to assets, then try to probe
-# THEM with SNMP, using the same community, and so on.
-#
-# If the entire internet exposed LLDP and SNMP in a public domain, we could
-# theoretically map the whole shebang.
-#
-# Note that leaf nodes do NOT need to reply to SNMP to be added, but
-# without SNMP, there'll obviously be some missing data.
-#
-# The output is a JSON blob of all assets, indexed by chassis id. It also
-# includes a neighbor table for each asset which can be used to generate a
-# map (See dotnet.sh or draw-neighbors.pl for examples). It can also be
-# used to add the assets to NMS.
-#
-# A sensible approach might be to run this periodically, store the results
-# to disk, then have multiple tools parse the results.
-use POSIX;
-use Time::HiRes;
-use strict;
-use warnings;
-use Data::Dumper;
-
-use lib '../../include';
-use nms;
-use nms::snmp;
-
-# Actual assets detected, indexed by chassis ID
-my %assets;
-
-# Tracking arrays. Continue scanning until they are of the same length.
-my @chassis_ids_checked;
-my @chassis_ids_to_check;
-
-# If we are given one switch on the command line, add that and then exit.
-my ($cmdline_ip, $cmdline_community) = @ARGV;
-if (defined($cmdline_ip) && defined($cmdline_community)) {
- my $chassis_id;
- eval {
- # Special-case for the first switch is to fetch chassis id
- # directly. Everything else is fetched from a neighbour
- # table.
- my $session = nms::snmp::snmp_open_session($cmdline_ip, $cmdline_community);
- $chassis_id = get_lldp_chassis_id($session);
- $assets{$chassis_id}{'community'} = $cmdline_community;
- $assets{$chassis_id}{'ip'} = $cmdline_ip;
- push @chassis_ids_to_check, $chassis_id;
- };
- if ($@) {
- mylog("Error during SNMP : $@");
- exit 1;
- }
-
- # Welcome to the main loop!
- while (scalar @chassis_ids_to_check > scalar @chassis_ids_checked) {
- # As long as you call it something else, it's not really a
- # goto-statement, right!?
- OUTER: for my $id (@chassis_ids_to_check) {
- for my $id2 (@chassis_ids_checked) {
- if ($id2 eq $id) {
- next OUTER;
- }
- }
- mylog("Adding $id");
- add_switch($id);
- mylog("Discovering neighbors for $id");
- discover_lldp_neighbors($id);
- push @chassis_ids_checked,$id;
- }
- }
- print JSON::XS::encode_json(\%assets);
- # Creates corrupt output, hooray.
-# print JSON::XS->new->pretty(1)->encode(\%assets);
- exit;
-} else {
- print "RTFSC\n";
-}
-# Filter out stuff we don't scan. Return true if we care about it.
-# XXX: Several of these things are temporary to test (e.g.: AP).
-sub filter {
- my %sys = %{$_[0]};
- if (!defined($sys{'lldpRemSysCapEnabled'})) {
- return 0;
- }
- my %caps = %{$sys{'lldpRemSysCapEnabled'}};
- my $sysdesc = $sys{'lldpRemSysDesc'};
- my $sysname = $sys{'lldpRemSysName'};
-
- if ($caps{'cap_enabled_ap'}) {
- return 1;
- }
- if ($caps{'cap_enabled_telephone'}) {
- return 0;
- }
- if (!defined($sysdesc)) {
- return 1;
- }
- if ($sysdesc =~ /\b(C1530|C3600|C3700)\b/) {
- return 0;
- }
- if (!$caps{'cap_enabled_bridge'} && !$caps{'cap_enabled_router'}) {
- return 1;
- }
- if ($sysname =~ /BCS-OSL/) {
- return 1;
- }
- return 1;
-}
-
-# Discover neighbours of a switch. The data needed is already present int
-# %assets , so this shouldn't cause any extra SNMP requests. It will add
-# new devices as it finds them.
-sub discover_lldp_neighbors {
- my $local_id = $_[0];
- #print "local id: $local_id\n";
- my $ip = $assets{$local_id}{mgmt};
- my $local_sysname = $assets{$local_id}{snmp}{sysName};
- my $community = $assets{$local_id}{community};
- my $addrtable;
- while (my ($key, $value) = each %{$assets{$local_id}{snmp_parsed}}) {
- my $chassis_id = $value->{'lldpRemChassisId'};
- #print "chasis id: $chassis_id\n";
- my $sysname = $value->{'lldpRemSysName'};
- if (!defined($sysname)) {
- $sysname = $chassis_id;
- }
-
- # Do not try to poll servers.
- if (!filter(\%{$value})) {
- mylog("Filtered out $sysname ($local_sysname -> $sysname)");
- next;
- }
- $sysname =~ s/\..*$//;
- if (defined($value->{lldpRemManAddr})) {
- mylog("Found $sysname ($local_sysname -> $sysname )");
- } else {
- next;
- }
- if (defined($assets{$chassis_id}{'sysName'})) {
- mylog("Duplicate $sysname: \"$sysname\" vs \"$assets{$chassis_id}{'sysName'}\"");
- if ($assets{$chassis_id}{'sysName'} eq "") {
- $assets{$chassis_id}{'sysName'} = $sysname;
- }
- } else {
- $assets{$chassis_id}{'sysName'} = $sysname;
- }
-
- # FIXME: We should handle duplicates better and for more
- # than just sysname. These happen every time we are at
- # least one tier down (given A->{B,C,D,E}, switch B, C, D
- # and E will all know about A, thus trigger this). We also
- # want to _add_ information only, since two nodes might
- # know about the same switch, but one might have incomplete
- # information (as is the case when things start up).
-
- # We simply guess that the community is the same as ours.
- $assets{$chassis_id}{'community'} = $community;
- $assets{$chassis_id}{'ip'} = $value->{lldpRemManAddr};
-
- $assets{$chassis_id}{'neighbors'}{$local_id} = 1;
- $assets{$local_id}{'neighbors'}{$chassis_id} = 1;
- check_neigh($chassis_id);
- #print "checking $chassis_id\n";
- }
-}
-
-sub mylog {
- my $msg = shift;
- my $time = POSIX::ctime(time);
- $time =~ s/\n.*$//;
- printf STDERR "[%s] %s\n", $time, $msg;
-}
-
-# Get raw SNMP data for an ip/community.
-# FIXME: This should be seriously improved. Three get()'s and four
-# gettables could definitely be streamlined, but then again, I doubt it
-# matters much unless we start running this tool constantly.
-sub get_snmp_data {
- my ($ip, $community) = @_;
- my %ret = ();
- eval {
- my $session = nms::snmp::snmp_open_session($ip, $community);
- $ret{'sysName'} = $session->get('sysName.0');
- $ret{'sysDescr'} = $session->get('sysDescr.0');
- $ret{'lldpRemManAddrTable'} = $session->gettable("lldpRemManAddrTable");
- $ret{'lldpRemTable'} = $session->gettable("lldpRemTable");
- $ret{'lldpLocChassisIdParsed'} = nms::convert_mac($session->get('lldpLocChassisId.0'));
- $ret{'lldpLocChassisId'} = $session->get('lldpLocChassisId.0');
- #print Dumper(\%ret);
- };
- if ($@) {
- mylog("Error during SNMP to $ip : $@");
- return undef;
- }
- return \%ret;
-}
-
-# Filter raw SNMP data over to something more legible.
-# This is the place to add all post-processed results so all parts of the
-# tool can use them.
-sub parse_snmp
-{
- my $snmp = $_[0];
- my %result = ();
- my %lol = ();
- while (my ($key, $value) = each %{$snmp}) {
- $result{$key} = $value;
- }
- while (my ($key, $value) = each %{$snmp->{lldpRemTable}}) {
- my $chassis_id = nms::convert_mac($value->{'lldpRemChassisId'});
- foreach my $key2 (keys %$value) {
- $lol{$value->{lldpRemIndex}}{$key2} = $value->{$key2};
- }
- $lol{$value->{lldpRemIndex}}{'lldpRemChassisId'} = $chassis_id;
- my %caps = ();
- nms::convert_lldp_caps($value->{'lldpRemSysCapEnabled'}, \%caps);
- $lol{$value->{lldpRemIndex}}{'lldpRemSysCapEnabled'} = \%caps;
- }
- while (my ($key, $value) = each %{$snmp->{lldpRemManAddrTable}}) {
- foreach my $key2 (keys %$value) {
- $lol{$value->{lldpRemIndex}}{$key2} = $value->{$key2};
- }
- my $addr = $value->{'lldpRemManAddr'};
- my $addrtype = $value->{'lldpRemManAddrSubtype'};
- if ($addrtype == 1) {
- $lol{$value->{lldpRemIndex}}{lldpRemManAddr} = nms::convert_ipv4($addr);
- } elsif ($addrtype == 2) {
- $lol{$value->{lldpRemIndex}}{lldpRemManAddr} = nms::convert_ipv6($addr);
- }
- }
- return \%lol;
- print Dumper (\%lol);
-}
-
-# Add a chassis_id to the list to be checked, but only if it isn't there.
-# I'm sure there's some better way to do this, but meh, perl. Doesn't even
-# have half-decent prototypes.
-sub check_neigh {
- my $n = $_[0];
- for my $v (@chassis_ids_to_check) {
- if ($v eq $n) {
- return 0;
- }
- }
- push @chassis_ids_to_check,$n;
- return 1;
-}
-
-# We've got a switch. Populate it with SNMP data (if we can).
-sub add_switch {
- my $chassis_id = shift;
- my $addr;
- my $snmp = undef;
- $addr = $assets{$chassis_id}{'ip'};
- mylog("Probing $addr");
- $snmp = get_snmp_data($addr, $assets{$chassis_id}{'community'});
-
- return if (!defined($snmp));
- my $sysname = $snmp->{sysName};
- $sysname =~ s/\..*$//;
- $assets{$chassis_id}{'sysName'} = $sysname;
- $assets{$chassis_id}{'ip'} = $addr;
- $assets{$chassis_id}{'snmp'} = $snmp;
- $assets{$chassis_id}{'snmp_parsed'} = parse_snmp($snmp);
- return;
-}
-
-sub get_lldp_chassis_id {
- my ($session) = @_;
- my $response = $session->get('lldpLocChassisId.0');
- return nms::convert_mac($response);
-}
diff --git a/tools/make-linknet-hosts.pl b/tools/make-linknet-hosts.pl
deleted file mode 100755
index c00e81b..0000000
--- a/tools/make-linknet-hosts.pl
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/perl
-use NetAddr::IP;
-use Net::IP;
-use Getopt::Long;
-
-my ($first);
-
-if (@ARGV > 0) {
- GetOptions(
- 'f|first' => \$first,
- )
-}
-
-# Input file format:
-#
-# <ipv4-linknet> <ipv6-linknet> src-router dst-router
-#
-# e.g.
-# 151.216.128.0/31 2a02:ed02:FFFE::0/127 rs1.tele rs1.core
-# 151.216.128.2/31 2a02:ed02:FFFE::2/127 rs1.tele rs1.noc
-
-while (<STDIN>) {
- next if /^(#|\s+$)/; # skip if comment, or blank line
-
- my ($ipv4_raw, $ipv6_raw, $from, $to) = split;
-
- my ($ipv4_first, $ipv4_second, $ipv6_first, $ipv6_second);
- if($ipv6_raw =~ m/nope/){
- $ipv6_first = "nope";
- $ipv6_second = "nope";
- } else {
- my $ipv6 = NetAddr::IP->new($ipv6_raw);
- $ipv6_first = $ipv6->addr();
- $ipv6++;
- $ipv6_second = $ipv6->addr();
- }
-
- if($ipv4_raw =~ m/nope/){
- $ipv4_first = "";
- $ipv4_second = "";
- } else {
- my $ipv4 = NetAddr::IP->new($ipv4_raw);
- $ipv4_first = $ipv4->addr();
- $ipv4++;
- $ipv4_second = $ipv4->addr;
- }
-
-
- # generate-dnsrr.pl format:
- # hostname ipv4 ipv6
- if($first){
- printf("%s %s %s\n", $from, $ipv4_first, $ipv6_first);
- printf("%s %s %s\n", $to, $ipv4_second, $ipv6_second);
- } else {
- printf("%s-%s %s %s\n", $from, $to, $ipv4_first, $ipv6_first);
- printf("%s-%s %s %s\n", $to, $from, $ipv4_second, $ipv6_second);
- }
-}
diff --git a/tools/sql-strip.pl b/tools/sql-strip.pl
deleted file mode 100644
index 0e2fec6..0000000
--- a/tools/sql-strip.pl
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/perl
-use warnings;
-use strict;
-
-my $ignore = "((([0-9a-f]{2}[:]){5}[0-9a-f]{2})|";
-$ignore .= "([0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}\:[0-9]{2}\:[0-9]{2})";
-$ignore .= ").*";
-
-my $community = "<removed>";
-my $snmpv3 = 'SHA/<removed>/AES/<removed>';
-
-my $skip = 0;
-
-open (SQL, $ARGV[0]) or die "Unable to open SQL-file";
-while (<SQL>) {
- unless (/^$ignore$/){
-
- if (/COPY (linknet_ping|ping|mbd_log|squeue|temppoll|ap_poll|polls)/){
- $skip = 1;
- print;
- }
-
- if (/\\\./){
- $skip = 0;
- }
-
- unless ($skip){
- s/$community/<removed>/g; # community
- s/PASSWORD '.+'/PASSWORD '<removed>'/g; # password for SQL-users
- s/public$/<removed>/; # public-community -- assuming last column
- #s/$snmpv3/SHA\/<removed>\/AES\/<removed>/g; # snmpv3
- print;
- }
- }
-}