X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=clients%2Fciscong.pl;h=76ec4759102a2d9556f1352ec28bc68ec8230d46;hb=ec7c8cc04058bb8b9e921ae529f523d381808caf;hp=277dfcf13dc7ebc712983633ac614ddb259705d0;hpb=d9ecfc56d84895d3a88399d67db4cae1a31e7271;p=nms diff --git a/clients/ciscong.pl b/clients/ciscong.pl index 277dfcf..76ec475 100644 --- a/clients/ciscong.pl +++ b/clients/ciscong.pl @@ -16,6 +16,11 @@ 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.connect" or die "Could not open log"; + BEGIN { require "../include/config.pm"; @@ -62,11 +67,16 @@ sub stop_vlan { sub do_distro { - my ($dip, $newip, $vlan) = @_; + my ($dip, $newip, $vlan, $switchname) = @_; 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; @@ -97,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; } @@ -110,7 +121,7 @@ sub do_distro { print "Zyxel is alive..\n"; $p->close(); - system("perl ./zyxelng.pl 192.168.1.1 $newip"); + system("perl ./zyxelng.pl 192.168.1.1 $newip $switchname"); #### @@ -129,7 +140,6 @@ 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; @@ -137,24 +147,78 @@ while() { } 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; + + #print "Testing: ".$ARGV[1]." $switch\n"; + next if (defined($ARGV[1]) and $ARGV[1] ne $switch); - $switch =~ /e(\d+)-(\d)/; - my ($row, $place) = ($1, $2); - my $ipnet = $switchips{$switch}; - my $vlan = $row . $place; + 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"; - 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); + do_distro($dip, $ip, $vlan, $switch); +# my ($dip, $newip, $vlan) = @_; + } + close(PATCHLIST); +} + +sub verify_run { + open(PATCHLIST, $patchlist) or die "Unable to open patchlist"; + while () { + print "Verify run....\n"; + my ($switch, $distro, $port) = split; + + if ($switch eq "e71-6") { + print "There is no e71-6\n"; + next; + } + + 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"; + + my $p = Net::Ping->new(); + printf "Checking if zyxel is up $dip:$vlan $ip...\n"; + my $counter = 0; + while (1) { + 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); + print "pinging...\n"; + sleep 1; + $counter++; + } + # my ($dip, $newip, $vlan) = @_; } close(PATCHLIST); @@ -164,6 +228,10 @@ sub first_run { if ($#ARGV > -1) { first_run(); } +else { + verify_run(); +} +close(LOG);