From: root Date: Tue, 3 Apr 2007 16:46:20 +0000 (+0200) Subject: Merge. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=8c3c9e3b907b47ea0aa1f89d75d80d618fde9e95;hp=23344eda0979f5e23d5fd016ef4903f7dc572e63;p=nms Merge. --- diff --git a/clients/ciscong.pl b/clients/ciscong.pl new file mode 100644 index 0000000..277dfcf --- /dev/null +++ b/clients/ciscong.pl @@ -0,0 +1,169 @@ +#!/usr/bin/perl +# +# + +use warnings; +use strict; + +use lib '../include'; + +use Net::Telnet::Cisco; +use Net::Ping; + +use Data::Dumper; + +my $patchlist = "/root/patchlist.txt"; +my $switches = "/root/switches.txt"; +#my $patchlist = "/home/eirikn/patchlist.txt.eirik"; +#my $switches = "/home/eirikn/switches.txt.eirik"; + +BEGIN { + require "../include/config.pm"; + eval { + require "../include/config.local.pm"; + }; +} + +sub ios_getroute { + my ($t, $net) = @_; + + $t->cmd("show ip route".($net ? " $net" : '')) or return 0;; + + return 1; +} + +#my $ios_server = "noc-gw.net.tg07.gathering.org"; +#my $vlannumber = 16; + +#my $ios = nms::ios_connect($ios_server, $nms::config::ios_user, $nms::config::ios_pass) +# or die "Unable to connect to cisco"; + + +sub start_vlan { + my ($ios, $vlan) = @_; + + $ios->cmd("conf t"); + $ios->cmd("int vlan $vlan"); + $ios->cmd("ip add 192.168.1.254 255.255.255.0 secondary"); + $ios->cmd("exit"); + $ios->cmd("exit"); +} + +sub stop_vlan { + my ($ios, $vlan) = @_; + + $ios->cmd("conf t"); + $ios->cmd("int vlan $vlan"); + $ios->cmd("no ip add 192.168.1.254 255.255.255.0 secondary"); + $ios->cmd("exit"); + $ios->cmd("exit"); +} + + + +sub do_distro { + my ($dip, $newip, $vlan) = @_; + + my $ios = Net::Telnet::Cisco->new(Host => $dip, + Errmode => 'return', + Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/'); + $ios->login($nms::config::ios_user, $nms::config::ios_pass); + $ios->enable; + +#nms::ios_enable($ios); +#$ios->cmd(); +#nms::ios_getroute($ios, "192.168.1.0"); +#$ios->cmd(""); + +#nms::ios_close($ios); + +# Disable paging + $ios->cmd("terminal length 0"); + +#my @routes = $ios->cmd("show ip route"); + + if (ios_getroute($ios, "192.168.1.0") == 1) { + print "Already routed up 192.168.1.0/24\n" ; + return; + } + + my $zyxeloldip = "192.168.1.1"; + start_vlan($ios, $vlan); + +### Do things +## ZyxelNG connect + + my $p = Net::Ping->new(); + printf "Waiting for zyxel to come up...\n"; + my $counter = 0; + while (1) { + if ($counter > 180) { + print "Waiting for zyxel on $dip:$vlan timed out, wanted to set ip: $newip"; + stop_vlan($ios, $vlan); + return; + } + last if $p->ping($zyxeloldip); + print "pinging...\n"; + sleep 1; + $counter++; + } + print "Zyxel is alive..\n"; + $p->close(); + + system("perl ./zyxelng.pl 192.168.1.1 $newip"); + +#### + + stop_vlan($ios, $vlan); + + + $ios->close(); + +} + +## Collect switch ips + +my %switchips; + +open(SWITCHES, $switches) or die "Unable to open switches"; +while() { + my ($ip, $net, $name) = split; + + print $name."\n"; + if ($name =~ /e\d+-\d/) { + die "We only support /26 nets for now you wanted $net" if ($net ne "26"); + $switchips{$name} = $ip; + } +} +close(SWITCHES); + +sub first_run { + + open(PATCHLIST, $patchlist) or die "Unable to open patchlist"; + while () { + my ($switch, $distro, $port) = split; + + $switch =~ /e(\d+)-(\d)/; + my ($row, $place) = ($1, $2); + my $ipnet = $switchips{$switch}; + my $vlan = $row . $place; + print "Switch: $switch, Distro: $distro, vlan: $vlan\n"; + print "Ip net: $ipnet\n"; + my ($first, $second, $third, $fourth) = split(/\./, $ipnet); + my $ip = "$first.$second.$third.".(int($fourth)+2); + print "Ip: $ip\n"; + my $dip = $distro.".net.tg07.gathering.org"; + + do_distro($dip, $ip, $vlan); +# my ($dip, $newip, $vlan) = @_; + } + close(PATCHLIST); +} + + +if ($#ARGV > -1) { + first_run(); +} + + + diff --git a/clients/zyxelng.pl b/clients/zyxelng.pl new file mode 100644 index 0000000..e41f657 --- /dev/null +++ b/clients/zyxelng.pl @@ -0,0 +1,124 @@ +#!/usr/bin/perl -w +# +# + +use strict; +use lib '../include'; + +use Data::Dumper; + +use nms qw(switch_connect switch_exec); +#use ios; + +#my $t = nms::ios_connect('62.148.36.12', 'c', 'c', 'c'); + +#print STDERR "No such network 192.168.1.0\n" if nms::ios_getroute($t, "192.168.1.0") == 0; + +#nms::ios_close($t); + +my $oldip; +my $newip; +if ($#ARGV < 1) { + die "Foo $#ARGV"; +} + +$oldip = $ARGV[0]; +$newip = $ARGV[1]; + +my $one = 0; + +my $switchip; +#$switchip = "87.76.250.226" if $one; +#$switchip = "192.168.2.150" if $one; +#$switchip = "192.168.1.1" unless $one; +$switchip = $oldip; +my $switch = switch_connect($switchip) + or die "Could not connect to $switchip"; + +my $cmds1 = <close(); + +#print "Reconnecting... "; +##$switchip = "192.168.1.1" if $one; +##$switchip = "192.168.2.150" unless $one; +#$switchip = $newip; +#autoflush STDOUT 1; +#print "Connecting to: $switchip...\n"; +#my $i = 1; +#while(1) { +# $switch = switch_connect($switchip); +# +# #print (defined($switch)? $switch : "foo") ." <---- switch\n"; +# if (defined($switch) || $switch) { +# last; +# } +# printf("Waited $i seconds...\r"); +# $i++; +# sleep 1; +#} +#print "\n"; + +#print $switch."\n"; +#$cmd = "sys sw vlan1q svlan cpu 248"; +#print "Sending '$cmd'\n"; +#print "XXX: No we did not..."; +#print Dumper($switch->cmd("ip ifconfig")); +#print Dumper($switch->cmd("ip route status")); +#switch_exec($cmd, $switch, 1); + diff --git a/include/nms.pm b/include/nms.pm index 0c0d754..b55314d 100644 --- a/include/nms.pm +++ b/include/nms.pm @@ -5,6 +5,10 @@ use DBI; use Net::Telnet; package nms; + +use base 'Exporter'; +our @EXPORT = qw(switch_connect switch_exec); + BEGIN { require "config.pm"; eval { @@ -25,10 +29,11 @@ sub db_connect { sub switch_connect($) { my ($ip) = @_; -# Dump_Log => '/tmp/dumplog-queue', my $conn = new Net::Telnet( Timeout => $nms::config::telnet_timeout, +# Dump_Log => '/tmp/dumplog-queue', Errmode => 'return', - Prompt => '/(es3024|e\d+\-\dsw)>/i'); +# Prompt => '/ES-3023>/'); + Prompt => '/(ES-3024|e\d{1,2}\-\dsw)>/i'); my $ret = $conn->open( Host => $ip); if (!$ret || $ret != 1) { return (undef); @@ -45,11 +50,17 @@ sub switch_connect($) { } # Send a command to switch and return the data recvied from the switch -sub switch_exec($$) { - my ($cmd, $conn) = @_; +sub switch_exec { + my ($cmd, $conn, $print) = @_; # Send the command and get data from switch - my @data = $conn->cmd($cmd); + my @data; + if (defined($print)) { + $conn->print($cmd); + return; + } else { + @data = $conn->cmd($cmd); + } my @lines = (); foreach my $line (@data) { # Remove escape-7 sequence diff --git a/make-all-config.sh b/make-all-config.sh index 10d3180..4321b56 100755 --- a/make-all-config.sh +++ b/make-all-config.sh @@ -1,5 +1,6 @@ #! /bin/sh ./planning/planning +scp switches.txt patchlist.txt space:/root/ cat static-switches.txt >> switches.txt ./config/make-dhcpd.pl > /etc/dhcp3/dhcpd.conf ./config/make-named.pl > /etc/bind/named.conf diff --git a/web/bg07.png b/web/bg07.png new file mode 100644 index 0000000..7b65a60 Binary files /dev/null and b/web/bg07.png differ diff --git a/web/nettkart.pl b/web/nettkart.pl index 29499fb..e0b47e8 100755 --- a/web/nettkart.pl +++ b/web/nettkart.pl @@ -9,7 +9,7 @@ my $cgi = CGI->new; my $dbh = nms::db_connect(); GD::Image->trueColor(1); -$img = GD::Image->new('snmp-bg.png'); +$img = GD::Image->new('bg2.png'); my $blk = $img->colorResolve(0, 0, 0); diff --git a/web/portkart.pl b/web/portkart.pl index 9150cef..259376e 100755 --- a/web/portkart.pl +++ b/web/portkart.pl @@ -9,7 +9,7 @@ my $cgi = CGI->new; my $dbh = nms::db_connect(); GD::Image->trueColor(1); -$img = GD::Image->new('snmp-bg.png'); +$img = GD::Image->new('bg2.png'); my $blk = $img->colorResolve(0, 0, 0); diff --git a/web/stempmap.pl b/web/stempmap.pl index fcfd32c..2399b31 100755 --- a/web/stempmap.pl +++ b/web/stempmap.pl @@ -12,7 +12,7 @@ use warnings; GD::Image->trueColor(1); -my $img = GD::Image->new('snmp-bg.png'); +my $img = GD::Image->new('bg2.png'); #my $img = GD::Image->new(100,100); my $cgi = CGI->new;