X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=clients%2Fciscong.pl;h=a2c08954eb00ec5806b9c1dc035801cf3dc6eeb4;hb=de1b28e7de97f6f969c1c02e5b8d22f1eaedbbf9;hp=1a9c6182ab73bf52366472d4ca866ca25a42d4a6;hpb=059283b9a54e09b5226bf80c04c6db2546b33741;p=nms diff --git a/clients/ciscong.pl b/clients/ciscong.pl index 1a9c618..a2c0895 100644 --- a/clients/ciscong.pl +++ b/clients/ciscong.pl @@ -12,10 +12,15 @@ 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"; +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"; @@ -66,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 0; + } $ios->login($nms::config::ios_user, $nms::config::ios_pass); $ios->enable; @@ -84,7 +94,7 @@ sub do_distro { if (ios_getroute($ios, "192.168.1.0") == 1) { print "Already routed up 192.168.1.0/24\n" ; - return; + return 0; } my $zyxeloldip = "192.168.1.1"; @@ -97,10 +107,11 @@ 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; + return 0; } last if $p->ping($zyxeloldip); print "pinging...\n"; @@ -119,6 +130,7 @@ sub do_distro { $ios->close(); + return 1; } ## Collect switch ips @@ -136,22 +148,34 @@ 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, $switch); # my ($dip, $newip, $vlan) = @_; @@ -159,10 +183,57 @@ sub first_run { 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"; + my $ret = do_distro($dip, $ip, $vlan, $switch); + if ($ret == 0) { + # No answer from zyxel + last; + } + print "Waiting for telnet to time out so we can do run ciscong.pl\n"; + sleep 100; + system("perl ./ciscong2.pl $switch"); + last; + } + last if $p->ping($ip); + print "pinging...\n"; + sleep 1; + $counter++; + } + +# my ($dip, $newip, $vlan) = @_; + } + close(PATCHLIST); +} + if ($#ARGV > -1) { first_run(); } +else { + verify_run(); +} +close(LOG);