]> git.sesse.net Git - nms/blobdiff - clients/ciscong.pl
Merge with space:/root/nms
[nms] / clients / ciscong.pl
index 89ad6d58609151686f9f7e819b656aa78d991b3a..76ec4759102a2d9556f1352ec28bc68ec8230d46 100644 (file)
@@ -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 (<PATCHLIST>) {
                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);
@@ -191,9 +202,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);
@@ -215,5 +232,6 @@ else {
        verify_run();
 }
 
+close(LOG);