diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2016-04-12 18:08:59 +0200 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2016-04-12 18:08:59 +0200 |
commit | bb6b9c5cc38ee136ddab5d28f1baae903c38c07c (patch) | |
tree | 08c9893214222f418b3fcb41e69e9d26e9068494 /include | |
parent | 09ea945c3908fd42e90eb64c194d9af11d174206 (diff) |
Walk through include/ somewhat
Diffstat (limited to 'include')
-rwxr-xr-x | include/config.pm.dist | 128 | ||||
-rwxr-xr-x | include/nms.pm | 114 | ||||
-rw-r--r-- | include/nms/snmp.pm | 8 | ||||
-rw-r--r-- | include/nms/util.pm | 3 | ||||
-rwxr-xr-x | include/nms/web.pm | 1 |
5 files changed, 38 insertions, 216 deletions
diff --git a/include/config.pm.dist b/include/config.pm.dist index 776e479..ff17111 100755 --- a/include/config.pm.dist +++ b/include/config.pm.dist @@ -1,109 +1,43 @@ #! /usr/bin/perl use strict; use warnings; -use DBI; package nms::config; # DB -our $db_name = "nms"; -our $db_host = "bb-8.tg16.gathering.org"; -our $db_username = "nms"; -our $db_password = "<removed>"; +our $db_name = "{ db_name }"; +our $db_host = "{ db_host }"; +our $db_username = "{ db_user }"; +our $db_password = "{ db_password }"; -# NMS: What SNMP objects to fetch. -# Some basics -our @snmp_objects = [ -['ifIndex'], -['sysName'], -['sysDescr'], -['ifHighSpeed'], -['ifType'], -['ifName'], -['ifDescr'], -['ifAlias'], -['ifOperStatus'], -['ifAdminStatus'], -['ifLastChange'], -['ifHCInOctets'], -['ifHCOutOctets'], -['ifInDiscards'], -['ifOutDiscards'], -['ifInErrors'], -['ifOutErrors'], -['ifInUnknownProtos'], -['ifOutQLen'], -['sysUpTime'], -['jnxOperatingTemp'], -['jnxOperatingCPU'], -['jnxOperatingDescr'], -['jnxBoxSerialNo'] -]; # Max SNMP polls to fire off at the same time. our $snmp_max = 20; -# DHCP-servers -our $dhcp_server1 = "185.110.149.2"; # primary -our $dhcp_server2 = "185.110.148.2"; # secondary - -# TACACS-login for NMS -our $tacacs_user = "<removed>"; -our $tacacs_pass = "<removed>"; - -# Telnet-timeout for smanagrun -our $telnet_timeout = 300; - -# IP/IPv6/DNS-info -our $tgname = "tg16"; -our $pri_hostname = "r2-d2"; -our $pri_v4 = "185.110.149.2"; -our $pri_v6 = "2a06:5841:149a::2"; -our $pri_net_v4 = "185.110.149.0/26"; -our $pri_net_v6 = "2a06:5841:149a::/64"; - -our $sec_hostname = "c-3po"; -our $sec_v4 = "185.110.148.2"; -our $sec_v6 = "2a06:5841:1337::2"; -our $sec_net_v4 = "185.110.148.0/26"; -our $sec_net_v6 = "2a06:5841:1337::/64"; - -# for RIPE to get reverse zones via DNS AXFR -# https://www.ripe.net/data-tools/dns/reverse-dns/how-to-set-up-reverse-delegation -our $ext_xfer = "193.0.0.0/22; 2001:610:240::/48; 2001:67c:2e8::/48"; - -# allow XFR from NOC -our $noc_net = "185.110.150.0/25; 2a06:5841:150a::1/64"; - -# To generate new dnssec-key for ddns: -# dnssec-keygen -a HMAC-MD5 -b 128 -n HOST DHCP_UPDATER -our $ddns_key = "<removed>"; -our $ddns_to = "127.0.0.1"; # just use localhost - -# Base networks -our $base_ipv4net = "88.92.0.0/17"; -our $base_ipv6net = "2a06:5840::/29"; -our $ipv6zone = "0.4.8.5.6.0.a.2.ip6.arpa"; - -# extra networks that are outside the normal ranges -# that should have recursive DNS access -our $rec_net = "185.110.148.0/22"; - -# extra networks that are outside the normal ranges -# that should be added to DNS -our @extra_nets = ( - '185.110.148.0/24', - '185.110.149.0/24', - '185.110.150.0/24', - '185.110.151.0/24', -); - -# add WLC's -our $wlc1 = "185.110.148.14"; - -# add VOIP-server -our $voip1 = "<removed>"; - -# PXE-server (rest of bootstrap assumes $sec_v4/$sec_v6) -our $pxe_server_v4 = $sec_v4; -our $pxe_server_v6 = $sec_v6; +# What SNMP objects to fetch. +our @snmp_objects = [ + ['ifIndex'], + ['sysName'], + ['sysDescr'], + ['ifHighSpeed'], + ['ifType'], + ['ifName'], + ['ifDescr'], + ['ifAlias'], + ['ifOperStatus'], + ['ifAdminStatus'], + ['ifLastChange'], + ['ifHCInOctets'], + ['ifHCOutOctets'], + ['ifInDiscards'], + ['ifOutDiscards'], + ['ifInErrors'], + ['ifOutErrors'], + ['ifInUnknownProtos'], + ['ifOutQLen'], + ['sysUpTime'], + ['jnxOperatingTemp'], + ['jnxOperatingCPU'], + ['jnxOperatingDescr'], + ['jnxBoxSerialNo'] +]; 1; diff --git a/include/nms.pm b/include/nms.pm index 2ec922b..273d65d 100755 --- a/include/nms.pm +++ b/include/nms.pm @@ -2,8 +2,6 @@ use strict; use warnings; use DBI; -use Net::OpenSSH; -use Net::Telnet; use Data::Dumper; use FileHandle; use JSON; @@ -31,118 +29,6 @@ sub db_connect { return $dbh; } -sub switch_connect_ssh($) { - my ($ip) = @_; - my $ssh = Net::OpenSSH->new($ip, - user => $nms::config::tacacs_user, - password => $nms::config::tacacs_pass, - master_opts => [ "-o", "StrictHostKeyChecking=no" ]); - my ($pty, $pid) = $ssh->open2pty({stderr_to_stdout => 1}) - or die "unable to start remote shell: " . $ssh->error; - - my $dumplog = FileHandle->new; - $dumplog->open(">>/tmp/dumplog-queue") or die "/tmp/dumplog-queue: $!"; - #$dumplog->print("\n\nConnecting to " . $ip . "\n\n"); - - my $inputlog = FileHandle->new; - $inputlog->open(">>/tmp/inputlog-queue") or die "/tmp/inputlog-queue: $!"; - #$inputlog->print("\n\nConnecting to " . $ip . "\n\n"); - - my $telnet = Net::Telnet->new(-fhopen => $pty, - -timeout => $nms::config::telnet_timeout, - -dump_log => $dumplog, - -input_log => $inputlog, - -prompt => '/.*\@[a-z0-9-]+[>#] /', - -telnetmode => 0, - -cmd_remove_mode => 1, - -output_record_separator => "\r"); - $telnet->waitfor(-match => $telnet->prompt, - -errmode => "return") - or die "login failed: " . $telnet->lastline; - - $telnet->cmd("set cli screen-length 0"); - - return { telnet => $telnet, ssh => $ssh, pid => $pid, pty => $pty }; -} - -sub switch_connect_dlink($) { - my ($ip) = @_; - - my $dumplog = FileHandle->new; - $dumplog->open(">>/tmp/dumplog-queue") or die "/tmp/dumplog-queue: $!"; - $dumplog->print("\n\nConnecting to " . $ip . "\n\n"); - - my $inputlog = FileHandle->new; - $inputlog->open(">>/tmp/inputlog-queue") or die "/tmp/inputlog-queue: $!"; - $inputlog->print("\n\nConnecting to " . $ip . "\n\n"); - - my $conn = new Net::Telnet( Timeout => $nms::config::telnet_timeout, - Dump_Log => $dumplog, - Input_Log => $inputlog, - Errmode => 'return', - Prompt => '/[\S\-\_]+[#>]/'); - my $ret = $conn->open( Host => $ip); - if (!$ret || $ret != 1) { - return (undef); - } - # Handle login with and without password - print "Logging in without password\n"; - $conn->waitfor('/User ?Name:/'); - $conn->print('admin'); - my (undef, $match) = $conn->waitfor('/DGS-3100#|Password:/'); - die 'Unexpected prompt after login attempt' if (not defined $match); - if ($match eq 'Password:') { - $conn->print('gurbagurba'); # Dette passordet skal feile - $conn->waitfor('/User ?Name:/'); - $conn->print($nms::config::tacacs_user); - my (undef, $match) = $conn->waitfor('/DGS-3100#|Password:/'); - if ($match eq 'Password:') { - $conn->cmd($nms::config::tacacs_pass); - } - } - return { telnet => $conn }; -} - -# Send a command to switch and return the data recvied from the switch -sub switch_exec { - my ($cmd, $conn, $print) = @_; - - sleep 1; # don't overload the D-Link - - # Send the command and get data from switch - my @data; - if (defined($print)) { - $conn->print($cmd); - return; - } else { - @data = $conn->cmd($cmd); - print "ERROR: " . $conn->errmsg . "\n" if $conn->errmsg; - } - return @data; -} - -sub switch_exec_json($$) { - my ($cmd, $conn) = @_; - my @json = switch_exec("$cmd | display json", $conn); - pop @json; # Remove the banner at the end of the output - return ::decode_json(join("", @json)); -} - -sub switch_timeout { - my ($timeout, $conn) = @_; - - $conn->timeout($timeout); - return ('Set timeout to ' . $timeout); -} - -sub switch_disconnect($) { - my ($struct) = @_; - my $conn = $struct->{telnet}; - $conn->close(); - if ($struct->{pid}) { - waitpid($struct->{pid}, 0); - } -} # A few utilities to convert from SNMP binary address format to human-readable. sub convert_mac { diff --git a/include/nms/snmp.pm b/include/nms/snmp.pm index 26ada44..5e3adac 100644 --- a/include/nms/snmp.pm +++ b/include/nms/snmp.pm @@ -9,12 +9,12 @@ use base 'Exporter'; our @EXPORT = qw(); BEGIN { - # $SNMP::debugging = 1; + # FIXME: Should be configurable. + #$SNMP::debugging = 1; - # sudo mkdir /usr/share/mibs/site - # cd /usr/share/mibs/site - # wget -O- ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz | sudo tar --strip-components=3 -zxvvf - SNMP::initMib(); + + # FIXME: This is just plain dumb. SNMP::addMibDirs("/srv/tgmanage/mibs/StandardMibs"); SNMP::addMibDirs("/srv/tgmanage/mibs/JuniperMibs"); diff --git a/include/nms/util.pm b/include/nms/util.pm index 64637b8..8c5b9d8 100644 --- a/include/nms/util.pm +++ b/include/nms/util.pm @@ -51,7 +51,8 @@ sub parse_switches { } # Guesses placement from name to get a starting point -# Largely courtesy of Knuta +# +# FIXME: Move to configuration sub guess_placement { my ($x, $y, $xx, $yy); diff --git a/include/nms/web.pm b/include/nms/web.pm index 7c9339e..8a20f50 100755 --- a/include/nms/web.pm +++ b/include/nms/web.pm @@ -26,6 +26,7 @@ sub get_input { while(<STDIN>) { $in .= $_; } return $in; } + # Print cache-control from %cc sub printcc { my $line = ""; |