From: root Date: Wed, 4 Apr 2007 10:06:22 +0000 (+0200) Subject: Commit working ZyxelNG. X-Git-Url: https://git.sesse.net/?p=nms;a=commitdiff_plain;h=863f7f00cd98c888055f3643e57d2a14c3a3a441 Commit working ZyxelNG. --- diff --git a/clients/ciscong.pl b/clients/ciscong.pl index 9d2dac2..1a2c457 100644 --- a/clients/ciscong.pl +++ b/clients/ciscong.pl @@ -12,12 +12,14 @@ use Net::Ping; use Data::Dumper; -#my $patchlist = "/root/patchlist.txt"; -#my $switches = "/root/switches.txt"; +my $patchlist = "/root/patchlist.txt"; +my $switches = "/root/switches.txt"; #my $patchlist = "/home/eirikn/patchlist.txt.eirik"; #my $switches = "/home/eirikn/switches.txt.eirik"; -my $patchlist = "/root/patchlist.txt.d01-1-2"; -my $switches = "/root/switches.txt.d01-1-2"; +#my $patchlist = "/root/patchlist.txt.d05"; +#my $switches = "/root/switches.txt.d05"; + +open LOG, ">>/tmp/zyxel.could.not.connect" or die "Could not open log"; BEGIN { @@ -69,7 +71,12 @@ sub do_distro { my $ios = Net::Telnet::Cisco->new(Host => $dip, Errmode => 'return', - Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/'); + Prompt => '/\S+[#>]/'); +# Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/'); + if (!defined($ios)) { + print "Could not connect to $dip"; + return; + } $ios->login($nms::config::ios_user, $nms::config::ios_pass); $ios->enable; @@ -100,8 +107,9 @@ sub do_distro { 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"; + if ($counter > 6) { + print "Waiting for zyxel on $dip:$vlan timed out, wanted to set ip: $newip\n"; + print LOG "Could not connect to $switchname\n"; stop_vlan($ios, $vlan); return; } @@ -158,6 +166,9 @@ sub first_run { open(PATCHLIST, $patchlist) or die "Unable to open patchlist"; while () { my ($switch, $distro, $port) = split; + + #print "Testing: ".$ARGV[1]." $switch\n"; + next if (defined($ARGV[1]) and $ARGV[1] ne $switch); print "First run...\n"; my ($row, $place, $ipnet, $vlan, $ip, $dip) = switch_info($switch, $distro, $port); @@ -186,9 +197,15 @@ sub verify_run { printf "Checking if zyxel is up $dip:$vlan $ip...\n"; my $counter = 0; while (1) { - if ($counter > 10) { + if ($counter > 4) { print "No answer from $dip:$vlan $ip, trying to route it up\n"; do_distro($dip, $ip, $vlan, $switch); + my $pid = fork(); + if ($pid == 0) { + sleep 100; + system("perl ./ciscong2.pl $switch"); + exit 0; + } last; } last if $p->ping($ip); @@ -210,5 +227,6 @@ else { verify_run(); } +close(LOG); diff --git a/clients/ciscong2.pl b/clients/ciscong2.pl new file mode 100644 index 0000000..b8c33b2 --- /dev/null +++ b/clients/ciscong2.pl @@ -0,0 +1,146 @@ +#!/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"; +#my $patchlist = "/root/patchlist.txt.d05"; +#my $switches = "/root/switches.txt.d05"; + +open LOG, ">>/tmp/zyxel.could.not.connect2" or die "Could not open log"; + + +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 do_distro { + my ($dip, $newip, $net, $switchname) = @_; + + my $ios = Net::Telnet::Cisco->new(Host => $dip, + Errmode => 'return', + Prompt => '/(\S+[#>])|(es-3024>)/'); +# Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/'); + if (!defined($ios)) { + print "Could not connect to $dip"; + return; + } + $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"); + + + $ios->print("telnet $newip"); + $ios->waitfor("/Password:/"); + print "Hei\n"; + $ios->cmd($nms::config::zyxel_password); + + my ($first, $second, $third, $fourth) = split(/\./, $net); + my $gw = "$first.$second.$third.".(int($fourth)+1); + $ios->cmd("ip route drop 192.168.1.0/24"); + $ios->cmd("ip route add default $gw"); + $ios->cmd("exit"); + + #system("perl ./zyxelng.pl 192.168.1.1 $newip $switchname"); + +#### + + $ios->close(); + +} + +## Collect switch ips + +my %switchips; + +open(SWITCHES, $switches) or die "Unable to open switches"; +while() { + my ($ip, $net, $name) = split; + + 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 switch_info { + my ($switch, $distro, $port) = @_; + + $switch =~ /e(\d+)-(\d)/; + my ($row, $place) = ($1, $2); + my $ipnet = $switchips{$switch}; + my $vlan = $row . $place; + my ($first, $second, $third, $fourth) = split(/\./, $ipnet); + my $ip = "$first.$second.$third.".(int($fourth)+2); + my $dip = $distro.".net.tg07.gathering.org"; + + return ($row, $place, $ipnet, $vlan, $ip, $dip); +} + +sub first_run { + + open(PATCHLIST, $patchlist) or die "Unable to open patchlist"; + while () { + my ($switch, $distro, $port) = split; + + next if (defined($ARGV[0]) and $ARGV[0] ne $switch); + + print "First run...\n"; + my ($row, $place, $ipnet, $vlan, $ip, $dip) = switch_info($switch, $distro, $port); + print "Switch: $switch, Distro: $distro, vlan: $vlan\n"; + print "Ip net: $ipnet\n"; + print "Ip: $ip\n"; + + do_distro($dip, $ip, $ipnet, $switch); +# my ($dip, $newip, $vlan) = @_; + } + close(PATCHLIST); +} + +first_run(); + +close(LOG); + +