Просмотр исходного кода

bugfix: fixed backup huawei devices

rajven 4 лет назад
Родитель
Сommit
f70f01b8e1
2 измененных файлов с 36 добавлено и 58 удалено
  1. 33 29
      scripts/Rstat/cmd.pm
  2. 3 29
      scripts/backupcfg.pl

+ 33 - 29
scripts/Rstat/cmd.pm

@@ -67,13 +67,13 @@ foreach my $row (@ret) {
     if ($row) {
         my @tmp=split("\n",$row);
         foreach  my $line (@tmp) {
-		next if (!$line);
-		$line=trim($line);
-		next if (!$line);
-		push(@a,$line);
-		log_session('Get:'.$line);
-		}
-	}
+                next if (!$line);
+                $line=trim($line);
+                next if (!$line);
+                push(@a,$line);
+                log_session('Get:'.$line);
+                }
+        }
 }
 
 select(undef, undef, undef, 0.15) if ($sleep);
@@ -115,17 +115,17 @@ foreach my $out (split("\n",$command)){
         #sleep 250 ms
         select(undef, undef, undef, 0.25) if ($sleep);
         foreach my $str ($t->waitfor($t->prompt)) {
-	    $str=trim($str);
-	    if ($str) {
-	            my @tmp=split("\n",$str);
-		    foreach  my $line (@tmp) {
-			next if (!$line);
-			$line=trim($line);
-			next if (!$line);
-			push(@a,$line);
-			log_session('Get:'.$line);
-			}
-		    }
+            $str=trim($str);
+            if ($str) {
+                    my @tmp=split("\n",$str);
+                    foreach  my $line (@tmp) {
+                        next if (!$line);
+                        $line=trim($line);
+                        next if (!$line);
+                        push(@a,$line);
+                        log_session('Get:'.$line);
+                        }
+                    }
             }
     }
 chomp(@a);
@@ -204,7 +204,7 @@ log_session('Get:'.Dumper(\@result));
 return @result;
 }
 
-#--------------------------------------------------------------------------------- 
+#---------------------------------------------------------------------------------
 
 sub flush_telnet {
 my $t = shift;
@@ -263,7 +263,9 @@ if ($device->{device_type} eq '2') {
     $device->{password}=$config_ref{router_password};
     }
 #switch
-if ($device->{device_type} eq '1') {
+if ($device->{device_type} eq '1' or $device->{vendor_id} eq '3') {
+    #mikrotik
+    if ($device->{vendor_id} eq '9') { $device->{port}=$config_ref{router_port}; }
     $device->{login}=$sw_login;
     $device->{password}=$sw_password;
     }
@@ -379,20 +381,20 @@ if ($switch_auth{$device->{vendor_id}}{proto} eq 'ssh') {
             $t->send("no logging console");
             $t->waitfor("/$switch_auth{$device->{vendor_id}}{prompt}/",1);
             }
-        if ($device->{vendor_id} eq '5') { 
-            $t->send("terminal page-break disable"); 
+        if ($device->{vendor_id} eq '5') {
+            $t->send("terminal page-break disable");
             $t->waitfor("/$switch_auth{$device->{vendor_id}}{prompt}/",1);
             }
-        if ($device->{vendor_id} eq '6') { 
-            $t->send("terminal length 0"); 
+        if ($device->{vendor_id} eq '6') {
+            $t->send("terminal length 0");
             $t->waitfor("/$switch_auth{$device->{vendor_id}}{prompt}/",1);
             }
-        if ($device->{vendor_id} eq '9') { 
-            $t->send("/system note set show-at-login=no"); 
+        if ($device->{vendor_id} eq '9') {
+            $t->send("/system note set show-at-login=no");
             $t->waitfor("/$switch_auth{$device->{vendor_id}}{prompt}/",1);
             }
-        if ($device->{vendor_id} eq '16') { 
-            $t->send("terminal width 0"); 
+        if ($device->{vendor_id} eq '16') {
+            $t->send("terminal width 0");
             $t->waitfor("/$switch_auth{$device->{vendor_id}}{prompt}/",1);
             }
         if ($device->{vendor_id} eq '17') {
@@ -493,7 +495,9 @@ if ($device->{vendor_id} eq '2') {
 if ($device->{vendor_id} eq '3') {
     eval {
         my $session = netdev_login($device);
-        my $cmd = "tftp $tftp_ip put vrpcfg.zip $device->{device_name}.zip";
+        my $cmd = "quit";
+        netdev_cmd($device,$session,$switch_auth{$device->{vendor_id}}{proto},$cmd,3);
+        $cmd = "tftp $tftp_ip put vrpcfg.zip $device->{device_name}.zip";
         netdev_cmd($device,$session,$switch_auth{$device->{vendor_id}}{proto},$cmd,3);
         };
     }

+ 3 - 29
scripts/backupcfg.pl

@@ -26,44 +26,18 @@ my $debug = 1;
 
 if ($ARGV[0]) {
     my $device=get_record_sql($dbh,'SELECT * FROM devices WHERE id='.$ARGV[0]);
+    $device = netdev_set_auth($device);
     print "Backup switch $device->{device_name} ip: $device->{ip} ...";
-    #router
-    if ($device->{device_type} eq '2') {
-        #mikrotik
-        if ($device->{vendor_id} eq '9') { $device->{port}='60023'; }
-        $device->{login}=$router_login;
-        $device->{password}=$router_password;
-        }
-    #switch
-    if ($device->{device_type} eq '1') {
-        #mikrotik
-        if ($device->{vendor_id} eq '9') { $device->{port}='60023'; }
-        $device->{login}='admin';
-        $device->{password}=$sw_password;
-        }
     netdev_backup($device,$tftp_server);
     print " end.\n";
     } else {
     my @devices=get_records_sql($dbh,'SELECT * FROM devices WHERE deleted=0 and (vendor_id=3 or vendor_id=8 or vendor_id=9)');
     foreach my $device (@devices) {
+        $device = netdev_set_auth($device);
         print "Backup switch $device->{device_name} ip: $device->{ip} ...";
-        #router
-        if ($device->{device_type} eq '2') {
-            #mikrotik
-            if ($device->{vendor_id} eq '9') { $device->{port}='60023'; }
-            $device->{login}=$router_login;
-            $device->{password}=$router_password;
-            }
-        #switch
-        if ($device->{device_type} eq '1') {
-            #mikrotik
-            if ($device->{vendor_id} eq '9') { $device->{port}='60023'; }
-            $device->{login}='admin';
-            $device->{password}=$sw_password;
-            }
         netdev_backup($device,$tftp_server);
         print " end.\n";
-	}
+        }
     }
 
 exit 0;