瀏覽代碼

The algorithm for polling the table of poppies has been changed. Now dot1dTpFdbTable is the first to be polled, checking the binding of interfaces to Ifindex_map, in the absence of this table, dot1qTpFdbPort is polled without analyzing ifindex_map.
Disabled merging of dot1dTpFdbTable & dot1qTpFdbPort tables

Roman Dmitriev 2 年之前
父節點
當前提交
448b18e014
共有 3 個文件被更改,包括 57 次插入89 次删除
  1. 31 32
      html/inc/common.php
  2. 2 4
      html/inc/consts.php
  3. 24 53
      scripts/Rstat/snmp.pm

+ 31 - 32
html/inc/common.php

@@ -1738,9 +1738,14 @@ function get_mac_port_table($ip, $port_index, $community, $version, $oid, $index
     $mac_table = walk_snmp($ip, $community, $version, $oid);
     if (isset($mac_table) and count($mac_table) > 0) {
         foreach ($mac_table as $key => $value) {
+            if (empty($value)) { continue; }
+            if (empty($key)) { continue; }
             $key = trim($key);
-            $value = intval(trim(str_replace('INTEGER:', '', $value)));
-            $value = $index_map[$value];
+            $value_raw = intval(trim(str_replace('INTEGER:', '', $value)));
+            if (empty($value_raw)) { continue; }
+            if (!empty($index_map)) {
+                if (empty($index_map[$value_raw])) { $value = $value_raw; } else { $value = $index_map[$value_raw]; }
+                } else { $value = $value_raw; }
             if ($value == $port_index) {
                 $pattern = '/\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/';
                 $result = preg_match($pattern, $key, $matches);
@@ -1813,18 +1818,13 @@ function get_fdb_port_table($ip, $port_index, $community, $version)
     }
 
     $ifindex_map = get_ifmib_index_table($ip,$community, $version);
-    $fdb1_port_table = get_mac_port_table($ip, $port_index, $community, $version, MAC_TABLE_OID2, $ifindex_map);
-    $fdb2_port_table = get_mac_port_table($ip, $port_index, $community, $version, MAC_TABLE_OID, $ifindex_map);
-
-    if (!empty($fdb1_port_table)) { $fdb_port_table = $fdb1_port_table; }
-    if (!empty($fdb2_port_table)) {
-        if (empty($fdb_port_table)) {
-            $fdb_port_table = $fdb2_port_table;
-            } else {
-            foreach ($fdb2_port_table as $mac => $port) {
-                if (empty($fdb_port_table[$mac])) { $fdb_port_table[$mac]=$port; }
-                }
-            }
+    $fdb1_port_table = get_mac_port_table($ip, $port_index, $community, $version, MAC_TABLE_OID, $ifindex_map);
+
+    if (!empty($fdb1_port_table)) { 
+        $fdb_port_table = $fdb1_port_table; 
+        } else {
+            $fdb2_port_table = get_mac_port_table($ip, $port_index, $community, $version, MAC_TABLE_OID2, NULL);
+            if (!empty($fdb2_port_table)) { $fdb_port_table = $fdb2_port_table; }
         }
 
     // maybe cisco?!
@@ -1841,9 +1841,9 @@ function get_fdb_port_table($ip, $port_index, $community, $version)
             if (!empty($result)) {
                 $vlan_id = preg_replace('/^\./', '', $matches[0]);
                 if ($vlan_id > 1000 and $vlan_id < 1009) { continue; }
-                $fdb_vlan_table = get_mac_port_table($ip, $port_index, $community . '@' . $vlan_id, $version, MAC_TABLE_OID2,$ifindex_map);
+                $fdb_vlan_table = get_mac_port_table($ip, $port_index, $community . '@' . $vlan_id, $version, MAC_TABLE_OID,$ifindex_map);
                 if (! isset($fdb_vlan_table) or ! $fdb_vlan_table or count($fdb_vlan_table) == 0) {
-                    $fdb_vlan_table = get_mac_port_table($ip, $port_index, $community, $version, MAC_TABLE_OID,$ifindex_map);
+                    $fdb_vlan_table = get_mac_port_table($ip, $port_index, $community, $version, MAC_TABLE_OID2,$ifindex_map);
                 }
                 foreach ($fdb_vlan_table as $mac => $port) {
                     if (! isset($mac)) { continue; }
@@ -1873,9 +1873,14 @@ function get_mac_table($ip, $community, $version, $oid, $index_map)
     $mac_table = walk_snmp($ip, $community, $version, $oid);
     if (isset($mac_table) and count($mac_table) > 0) {
         foreach ($mac_table as $key => $value) {
+            if (empty($value)) { continue; }
+            if (empty($key)) { continue; }
             $key = trim($key);
-            $value = intval(trim(str_replace('INTEGER:', '', $value)));
-            $value = $index_map[$value];
+            $value_raw = intval(trim(str_replace('INTEGER:', '', $value)));
+            if (empty($value_raw)) { continue; }
+            if (!empty($index_map)) {
+                if (empty($index_map[$value_raw])) { $value = $value_raw; } else { $value = $index_map[$value_raw]; }
+                } else { $value = $value_raw; }
             $pattern = '/\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/';
             $result = preg_match($pattern, $key, $matches);
             if (!empty($result)) {
@@ -1901,18 +1906,12 @@ function get_fdb_table($ip, $community, $version)
     }
 
     $ifindex_map = get_ifmib_index_table($ip,$community, $version);
-    $fdb1_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID2, $ifindex_map);
-    $fdb2_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID, $ifindex_map);
-
-    if (!empty($fdb1_table)) { $fdb_table = $fdb1_table; }
-    if (!empty($fdb2_table)) {
-        if (empty($fdb_table)) {
-            $fdb_table = $fdb2_table;
-            } else {
-            foreach ($fdb2_table as $mac => $port) {
-                if (empty($fdb_table[$mac])) { $fdb_table[$mac]=$port; }
-                }
-            }
+    $fdb1_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID, $ifindex_map);
+    if (!empty($fdb1_table)) {
+        $fdb_table = $fdb1_table;
+        } else {
+        $fdb2_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID2, NULL);
+        if (!empty($fdb2_table)) { $fdb_table = $fdb2_table; }
         }
 
     // maybe cisco?!
@@ -1928,9 +1927,9 @@ function get_fdb_table($ip, $community, $version)
             if (!empty($result)) {
                 $vlan_id = preg_replace('/^\./', '', $matches[0]);
                 if ($vlan_id > 1000 and $vlan_id < 1009) { continue; }
-                $fdb_vlan_table = get_mac_table($ip, $community.'@'.$vlan_id, $version, MAC_TABLE_OID2,$ifindex_map);
+                $fdb_vlan_table = get_mac_table($ip, $community.'@'.$vlan_id, $version, MAC_TABLE_OID,$ifindex_map);
                 if (! isset($fdb_vlan_table) or ! $fdb_vlan_table or count($fdb_vlan_table) == 0) {
-                    $fdb_vlan_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID,$ifindex_map);
+                    $fdb_vlan_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID2,$ifindex_map);
                 }
                 foreach ($fdb_vlan_table as $mac => $port) {
                     if (! isset($mac)) { continue; }

+ 2 - 4
html/inc/consts.php

@@ -17,10 +17,8 @@ define("IFMIB_IFINDEX_MAP",".1.3.6.1.2.1.17.1.4.1.2");
 define("IFMIB_IFDESCR",".1.3.6.1.2.1.2.2.1.2");
 define("IFMIB_IFNAME",".1.3.6.1.2.1.31.1.1.1.1");
 
-define("MAC_TABLE_OID",".1.3.6.1.2.1.17.7.1.2.2.1.2");
-define("MAC_TABLE_OID2",".1.3.6.1.2.1.17.4.3.1.2");
-define("MAC_TABLE_STR_OID",".1.3.6.1.2.1.17.4.3.1.2");
-define("MAC_TABLE_STR_OID2","1.3.6.1.2.1.17.7.1.2.2.1.2");
+define("MAC_TABLE_OID",".1.3.6.1.2.1.17.4.3.1.2");
+define("MAC_TABLE_OID2",".1.3.6.1.2.1.17.7.1.2.2.1.2");
 
 define("ELTEX_SFP_STATUS",".1.3.6.1.4.1.89.90.1.2.1.3");
 define("ELTEX_SFP_VENDOR",".1.3.6.1.4.1.35265.1.23.53.1.1.1.5");

+ 24 - 53
scripts/Rstat/snmp.pm

@@ -29,7 +29,6 @@ get_snmp_ifindex
 get_ifmib_index_table
 get_interfaces
 get_router_state
-get_bgp
 snmp_get_req
 snmp_get_oid
 snmp_walk_oid
@@ -39,8 +38,6 @@ $ifName
 $ifDescr
 $ifIndex
 $ifIndex_map
-$bgp_prefixes
-$bgp_aslist
 $arp_oid
 $ipNetToMediaPhysAddress
 $fdb_table_oid
@@ -61,15 +58,21 @@ our $ifDescr      ='.1.3.6.1.2.1.2.2.1.2';
 our $ifIndex      ='.1.3.6.1.2.1.2.2.1.1';
 our $ifIndex_map  ='.1.3.6.1.2.1.17.1.4.1.2';
 
-our $bgp_prefixes ='.1.3.6.1.4.1.9.9.187.1.2.4.1.1';
-our $bgp_aslist   ='.1.3.6.1.2.1.15.3.1.9';
+#RFC1213::atPhysAddress
 our $arp_oid      ='.1.3.6.1.2.1.3.1.1.2';
+#RFC1213::ipNetToMediaPhysAddress
 our $ipNetToMediaPhysAddress = '.1.3.6.1.2.1.4.22.1.2';
+#RFC1493::dot1dTpFdbTable
 our $fdb_table_oid ='.1.3.6.1.2.1.17.4.3.1.2';
+#Q-BRIDGE-MIB::dot1qTpFdbPort
 our $fdb_table_oid2='.1.3.6.1.2.1.17.7.1.2.2.1.2';
+#Q-BRIDGE-MIB::dot1qPortVlanEntry
 our $port_vlan_oid ='.1.3.6.1.2.1.17.7.1.4.5.1.1';
+#CISCO-ES-STACK-MIB::
 our $cisco_vlan_oid='.1.3.6.1.4.1.9.9.46.1.3.1.1.2';
+
 our $fdb_table;
+
 our $snmp_timeout = 15;
 
 #---------------------------------------------------------------------------------
@@ -179,17 +182,17 @@ sub get_mac_table {
     #need for callback
     $fdb_table=$oid;
     my $fdb_table1 = snmp_get_oid($host,$community,$oid,$version);
-    if (!$fdb_table1) { $fdb_table1=snmp_walk_oid($host,$community,$oid,$version); }
+    if (!$fdb_table1) { $fdb_table1=snmp_walk_oid($host,$community,$oid,$version,undef); }
     if ($fdb_table1) {
         foreach my $row (keys(%$fdb_table1)) {
 	    my $port_index = $fdb_table1->{$row};
-            next if (!$port_index);
+        next if (!$port_index);
 	    my $mac;
 	    if ($row=~/\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/) {
         	$mac=sprintf "%02x%02x%02x%02x%02x%02x",$1,$2,$3,$4,$5,$6;
         	}
-            next if (!$mac);
-            $port_index = $index_map->{$port_index};
+        next if (!$mac);
+        if ($index_map and exists $index_map->{$port_index}) { $port_index = $index_map->{$port_index}; }
 	    $fdb->{$mac}=$port_index;
 	    };
         return $fdb;
@@ -204,7 +207,7 @@ my $community = shift;
 my $version = shift;
 my $ifmib_map;
 my $index_table =  snmp_get_oid($ip, $community, $ifIndex_map, $version);
-if (!%$index_table) { $index_table =  snmp_walk_oid($ip, $community, $ifIndex_map, $version); }
+if (!$index_table) { $index_table =  snmp_walk_oid($ip, $community, $ifIndex_map, $version); }
 return if (!$index_table);
 my $is_mikrotik = snmp_get_request($ip, '.1.3.6.1.2.1.9999.1.1.1.1.0', $community, 161, $version);
 my $mk_ros_version = 6491;
@@ -219,21 +222,21 @@ if ($is_mikrotik=~/MikroTik/i) {
 
 if ($is_mikrotik=~/MikroTik/i and ($mk_ros_version > 6468)) {
             foreach my $row (keys(%$index_table)) {
-	        my $port_index = $index_table->{$row};
-	        next if (!$port_index);
-        	my $value;
+	            my $port_index = $index_table->{$row};
+	            next if (!$port_index);
+        	    my $value;
                 if ($row=~/\.([0-9]{1,10})$/) { $value = $1; }
-	        next if (!$value);
+	            next if (!$value);
     	        $ifmib_map->{$value}=$port_index;
         	}
         } else {
         if (%$index_table) {
             foreach my $row (keys(%$index_table)) {
-	        my $port_index = $index_table->{$row};
-	        next if (!$port_index);
-        	my $value;
+	            my $port_index = $index_table->{$row};
+	            next if (!$port_index);
+        	    my $value;
                 if ($row=~/\.([0-9]{1,10})$/) { $value = $1; }
-	        next if (!$value);
+	            next if (!$value);
     	        $ifmib_map->{$value}=$value;
                 };
             }
@@ -251,19 +254,12 @@ sub get_fdb_table {
     if (!$version) { $version='2'; }
 
     my $ifindex_map = get_ifmib_index_table($host,$community,$version);
-
     my $fdb1=get_mac_table($host,$community,$fdb_table_oid,$version,$ifindex_map);
-    my $fdb2=get_mac_table($host,$community,$fdb_table_oid2,$version,$ifindex_map);
 
     my $fdb;
-    if ($fdb1) { $fdb = $fdb1; }
-    if ($fdb2) {
-        if (!$fdb) { $fdb = $fdb2; }
-            else {
-            foreach my $mac (keys %$fdb2) {
-                if (!exists($fdb->{$mac})) { $fdb->{$mac}=$fdb2->{$mac}; }
-                }
-            }
+    if ($fdb1) { $fdb = $fdb1; } else {
+        my $fdb2=get_mac_table($host,$community,$fdb_table_oid2,$version);
+        if ($fdb2) { $fdb = $fdb2; }
         }
 
     #maybe cisco?!
@@ -402,31 +398,6 @@ sub get_router_state {
 
 #-------------------------------------------------------------------------------------
 
-sub get_bgp {
-    my ($host,$community,$snmp) = @_;
-    return if (!HostIsLive($host));
-    my $port = 161;
-    ### open SNMP session
-    my ($snmp_session, $error) = Net::SNMP->session( -hostname  => $host, -community => $community, -version => $snmp, -timeout => $snmp_timeout );
-    return if (!defined($snmp_session));
-    $snmp_session->translate([-timeticks]);
-    #bgp annonce counter exists?
-    my $bgp_annonces;
-    $bgp_annonces = $snmp_session->get_table($bgp_prefixes);
-    return if (!$bgp_annonces);
-    my $bgp_status = $snmp_session->get_table($bgp_aslist);
-    return if (!$bgp_status);
-    my $as;
-    foreach my $row (keys(%$bgp_status)) {
-    my $as_ip=$row;
-    $as_ip=~s/1\.3\.6\.1\.2\.1\.15\.3\.1\.9\.//;
-    $as->{$as_ip}=$bgp_status->{$row};
-    }
-    return $as;
-}
-
-#-------------------------------------------------------------------------------------
-
 sub snmp_get_req {
 my ($host,$community,$oid,$version) = @_;
 #return if (!HostIsLive($host));