Procházet zdrojové kódy

optimized snmp collector

root před 1 rokem
rodič
revize
abe0374
3 změnil soubory, kde provedl 30 přidání a 6 odebrání
  1. 24 5
      scripts/eyelib/net_utils.pm
  2. 4 0
      scripts/eyelib/snmp.pm
  3. 2 1
      scripts/fetch_new_arp.pl

+ 24 - 5
scripts/eyelib/net_utils.pm

@@ -311,11 +311,30 @@ $ret ? return 1: return 0;
 
 sub HostIsLive {
 my $host=shift;
-my $proto=shift || "tcp";
-if ($< eq 0) { $proto="icmp"; }
-my $p = Net::Ping->new($proto);
-my $ok= $p->ping($host,5);
-$p->close();
+my $proto=shift;
+my $ok = 0;
+my $p;
+if ($proto and $proto=~/(icmp|tcp)/i) {
+    $p = Net::Ping->new($proto);
+    $ok = $p->ping($host,5);
+    $p->close();
+    return $ok;
+    }
+if (!$proto) {
+    eval {
+        $p = Net::Ping->new('icmp');
+        $ok = $p->ping($host,5);
+        $p->close();
+    };
+    if ($@) {
+        eval {
+            $p = Net::Ping->new('tcp');
+            $ok = $p->ping($host,5);
+            $p->close();
+        };
+        if ($@) { return 0; }
+        }
+    }
 return $ok;
 }
 

+ 4 - 0
scripts/eyelib/snmp.pm

@@ -554,6 +554,10 @@ sub init_snmp {
 		-timeout      => $snmp->{timeout},
 		);
 	}
+    if ($error) {
+        log_debug("SNMP init-request status for $host:");
+        log_debug(Dumper($error));
+        }
     return if (!defined($session) or !$session);
     return $session;
 }

+ 2 - 1
scripts/fetch_new_arp.pl

@@ -230,8 +230,9 @@ $dbh->disconnect;
 FDB_LOOP:
 foreach my $device (@device_list) {
 setCommunity($device);
+if (!HostIsLive($device->{ip})) { log_info("Host id: $device->{id} name: $device->{device_name} ip: $device->{ip} is down! Skip."); next; }
 my $int_list = get_snmp_ifindex($device->{ip},$device->{snmp});
-if (!$int_list) { log_info("Host id: $device->{id} name: $device->{device_name} ip: $device->{ip} is down! Skip."); next; }
+if (!$int_list) { log_info("Host id: $device->{id} name: $device->{device_name} ip: $device->{ip} interfaces not found by snmp request! Skip."); next; }
 $pm_fdb->start() and next FDB_LOOP;
 my $result;
 my $tmp_dbh = init_db();