Jelajahi Sumber

add full support ifindex map table

Roman Dmitriev 2 tahun lalu
induk
melakukan
1530cc68e6

+ 1 - 2
html/admin/devices/editdevice.php

@@ -55,7 +55,6 @@ if (isset($_POST["editdevice"]) and isset($id)) {
     if (isset($_POST["f_snmp3_user_ro"])) { $new['snmp3_user_ro'] = substr($_POST["f_snmp3_user_ro"], 0, 20); }
     if (isset($_POST["f_snmp3_user_ro"])) { $new['snmp3_user_ro'] = substr($_POST["f_snmp3_user_ro"], 0, 20); }
     if (isset($_POST["f_snmp3_user_rw_password"])) { $new['snmp3_user_rw_password'] = substr($_POST["f_snmp3_user_rw_password"], 0, 20); }
     if (isset($_POST["f_snmp3_user_rw_password"])) { $new['snmp3_user_rw_password'] = substr($_POST["f_snmp3_user_rw_password"], 0, 20); }
     if (isset($_POST["f_snmp3_user_ro_password"])) { $new['snmp3_user_ro_password'] = substr($_POST["f_snmp3_user_ro_password"], 0, 20); }
     if (isset($_POST["f_snmp3_user_ro_password"])) { $new['snmp3_user_ro_password'] = substr($_POST["f_snmp3_user_ro_password"], 0, 20); }
-    if (isset($_POST["f_fdb_snmp"])) { $new['fdb_snmp_index'] = $_POST["f_fdb_snmp"]; }
     if (isset($_POST["f_discovery"])) { $new['discovery'] = $_POST["f_discovery"]; }
     if (isset($_POST["f_discovery"])) { $new['discovery'] = $_POST["f_discovery"]; }
     if (isset($_POST["f_dhcp"])) { $new['dhcp'] = $_POST["f_dhcp"] * 1; }
     if (isset($_POST["f_dhcp"])) { $new['dhcp'] = $_POST["f_dhcp"] * 1; }
     if (isset($_POST["f_user_acl"])) { $new['user_acl'] = $_POST["f_user_acl"] * 1; }
     if (isset($_POST["f_user_acl"])) { $new['user_acl'] = $_POST["f_user_acl"] * 1; }
@@ -135,9 +134,9 @@ if ($device['device_type']<=2) {
     print "<tr><td>".WEB_snmp_version."</td><td><p title='".WEB_device_snmp_hint."'>".WEB_device_mac_by_oid."</p></td>";
     print "<tr><td>".WEB_snmp_version."</td><td><p title='".WEB_device_snmp_hint."'>".WEB_device_mac_by_oid."</p></td>";
     print "<td>".WEB_network_discovery."</td><td>".WEB_nagios."</td></tr>";
     print "<td>".WEB_network_discovery."</td><td>".WEB_nagios."</td></tr>";
     print "<tr><td class='data'>"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td>\n";
     print "<tr><td class='data'>"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td>\n";
-    print "<td class='data'>"; print_qa_select('f_fdb_snmp', $device['fdb_snmp_index']); print "</td>\n";
     print "<td class='data'>"; print_qa_select('f_discovery', $device['discovery']); print "</td>\n";
     print "<td class='data'>"; print_qa_select('f_discovery', $device['discovery']); print "</td>\n";
     print "<td class='data'>"; print_qa_select('f_nagios', $device['nagios']); print "</td>\n";
     print "<td class='data'>"; print_qa_select('f_nagios', $device['nagios']); print "</td>\n";
+    print "<td class='data'></td>\n";
     print "</tr>";
     print "</tr>";
     if ($device['snmp_version'] ==3) {
     if ($device['snmp_version'] ==3) {
         print "<tr><td>".WEB_snmp_v3_user_ro."</td><td>".WEB_snmp_v3_user_rw."</td><td>".WEB_snmp_v3_ro_password."</td><td>".WEB_snmp_v3_rw_password."</td><td></td>";
         print "<tr><td>".WEB_snmp_v3_user_ro."</td><td>".WEB_snmp_v3_user_rw."</td><td>".WEB_snmp_v3_ro_password."</td><td>".WEB_snmp_v3_rw_password."</td><td></td>";

+ 2 - 3
html/admin/devices/mactable.php

@@ -25,13 +25,12 @@ print "<td>User</td>\n";
 print "<td>Mac</td>\n";
 print "<td>Mac</td>\n";
 print "</tr>";
 print "</tr>";
 foreach ($ports as $port) {
 foreach ($ports as $port) {
-    if (!$device['fdb_snmp_index']) { $port['snmp_index'] = $port['port']; }
     foreach ($fdb as $a_mac => $a_port) {
     foreach ($fdb as $a_mac => $a_port) {
 	if ($a_port == $port['snmp_index']) {
 	if ($a_port == $port['snmp_index']) {
 		print "<tr>";
 		print "<tr>";
 		print "<td class=\"data\">" . $port['port'] . "</td>\n";
 		print "<td class=\"data\">" . $port['port'] . "</td>\n";
-	        $auth = get_auth_by_mac($db_link, dec_to_hex($a_mac));
-                print "<td class=\"data\">" .$auth['auth'] . "</td><td class=\"data\">". $auth['mac']."</td>\n";
+	    $auth = get_auth_by_mac($db_link, dec_to_hex($a_mac));
+        print "<td class=\"data\">" .$auth['auth'] . "</td><td class=\"data\">". $auth['mac']."</td>\n";
 		print "</tr>";
 		print "</tr>";
 		}
 		}
     }
     }

+ 11 - 9
html/admin/devices/portmactable.php

@@ -4,7 +4,7 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
 
 $port_id = $id;
 $port_id = $id;
-$sSQL = "SELECT DP.device_id, DP.port, DP.snmp_index, D.device_name, D.ip, D.snmp_version, D.community, D.fdb_snmp_index, D.vendor_id FROM `device_ports` AS DP, devices AS D WHERE D.id = DP.device_id AND DP.id=$port_id";
+$sSQL = "SELECT DP.device_id, DP.port, DP.snmp_index, D.device_name, D.ip, D.snmp_version, D.community, D.vendor_id FROM `device_ports` AS DP, devices AS D WHERE D.id = DP.device_id AND DP.id=$port_id";
 $port_info = get_record_sql($db_link, $sSQL);
 $port_info = get_record_sql($db_link, $sSQL);
 
 
 $device_id = $port_info["device_id"];
 $device_id = $port_info["device_id"];
@@ -36,15 +36,17 @@ if ($port_info['vendor_id'] == 9) {
 if ($port_info['snmp_index'] > 0) {
 if ($port_info['snmp_index'] > 0) {
     print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
     print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
     print "<tr><td colspan=2><b>".WEB_device_port_mac_table_show."</b></td></tr>\n";
     print "<tr><td colspan=2><b>".WEB_device_port_mac_table_show."</b></td></tr>\n";
-    if (! $port_info['fdb_snmp_index']) { $port_info['snmp_index'] = $port_info['port']; }
-    $fdb = get_fdb_port_table($port_info['ip'], $port_info['snmp_index'], $port_info['community'], $port_info['snmp_version']);
+    $fdb = get_fdb_table($port_info['ip'], $port_info['community'], $port_info['snmp_version']);
     foreach ($fdb as $a_mac => $a_port) {
     foreach ($fdb as $a_mac => $a_port) {
-        $a_mac = dec_to_hex($a_mac);
-        if (!empty($sw_mac) and preg_match('/^'.$sw_mac.'/',mac_simplify($a_mac))) { continue; }
-        print "<tr>";
-        $auth = get_auth_by_mac($db_link, $a_mac);
-        print "<td class=\"data\">" .$auth['auth'] . "</td><td class=\"data\">". $auth['mac']."</td>\n";
-        print "</tr>";
+        if ($a_port == $port_info['snmp_index']) {
+            $a_mac = dec_to_hex($a_mac);
+            //mikrotik patch
+            if (!empty($sw_mac) and preg_match('/^'.$sw_mac.'/',mac_simplify($a_mac))) { continue; }
+            print "<tr>";
+            $auth = get_auth_by_mac($db_link, $a_mac);
+            print "<td class=\"data\">" .$auth['auth'] . "</td><td class=\"data\">". $auth['mac']."</td>\n";
+            print "</tr>";
+            }
         }
         }
     print "</table>\n";
     print "</table>\n";
     }
     }

+ 2 - 2
html/admin/devices/switchstatus.php

@@ -128,7 +128,7 @@ if ($device['snmp_version']>0) {
         //fix empty port names
         //fix empty port names
         if (empty($row['port_name'])) { $row['port_name']=$row['port']; $new_info['port_name']=$row['port']; }
         if (empty($row['port_name'])) { $row['port_name']=$row['port']; $new_info['port_name']=$row['port']; }
         if (isset($device['ip']) and ($device['ip'] != '') and $snmp_ok) {
         if (isset($device['ip']) and ($device['ip'] != '') and $snmp_ok) {
-            $port_state_detail = get_port_state_detail($row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $device['fdb_snmp_index']);
+            $port_state_detail = get_port_state_detail($row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
             list ($poper, $padmin, $pspeed, $perrors) = explode(';', $port_state_detail);
             list ($poper, $padmin, $pspeed, $perrors) = explode(';', $port_state_detail);
             if ($poper == 1 ) { $cl = "up";  }
             if ($poper == 1 ) { $cl = "up";  }
             if ($poper >= 2 ) {
             if ($poper >= 2 ) {
@@ -156,7 +156,7 @@ if ($device['snmp_version']>0) {
         $ifname= $row['ifName'];
         $ifname= $row['ifName'];
 
 
         if ($snmp_ok) {
         if ($snmp_ok) {
-            $vlan = get_port_vlan($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $device['fdb_snmp_index']);
+            $vlan = get_port_vlan($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
             $ifname = get_snmp_ifname1($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']);
             $ifname = get_snmp_ifname1($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']);
             if (empty($ifname)) { $ifname = get_snmp_ifname2($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']); }
             if (empty($ifname)) { $ifname = get_snmp_ifname2($device['ip'], $device['community'], $device['snmp_version'], $row['snmp_index']); }
             $sfp_status = get_sfp_status($device['vendor_id'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $modules_oids);
             $sfp_status = get_sfp_status($device['vendor_id'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $modules_oids);

+ 38 - 137
html/inc/common.php

@@ -1718,143 +1718,45 @@ function is_up($ip)
     return $rval == 0;
     return $rval == 0;
 }
 }
 
 
-function get_mac_port_table($ip, $port_index, $community, $version, $oid, $index_map)
-{
-    if (! isset($ip)) {
-        return;
-    }
-    if (! isset($port_index)) {
-        return;
-    }
-    if (! isset($oid)) {
-        return;
-    }
-    if (! isset($community)) {
-        $community = 'public';
-    }
-    if (! isset($version)) {
-        $version = '2';
-    }
-    $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_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);
-                if ($result) {
-                    $mac_key = preg_replace('/^\./', '', $matches[0]);
-                    $fdb_port_table[$mac_key] = $value;
-                }
-            }
-        }
-    }
-    return $fdb_port_table;
-}
-
 function get_ifmib_index_table ($ip, $community, $version)
 function get_ifmib_index_table ($ip, $community, $version)
 {
 {
 $ifmib_map = NULL;
 $ifmib_map = NULL;
-$index_table = walk_snmp($ip, $community, $version, IFMIB_IFINDEX_MAP);
-$is_mikrotik = walk_snmp($ip, $community, $version, MIKROTIK_DHCP_SERVER);
-$mk_ros_version = 6497;
-
-if ($is_mikrotik) {
-    $mikrotik_version = walk_snmp($ip, $community, $version, MIKROTIK_ROS_VERSION);
-    $result = preg_match('/RouterOS\s+(\d)\.(\d{1,3})\.(\d{1,3})\s+/',$mikrotik_version[MIKROTIK_ROS_VERSION],$matches);
-    if ($result) {
-        $mk_ros_version = $matches[1]*1000 + $matches[2]*10 + $matches[3];
-        }
-    }
+#fdb_index => snmp_index
+$index_map_table = walk_snmp($ip, $community, $version, IFMIB_IFINDEX_MAP);
 
 
-if (isset($index_table) and count($index_table) > 0 and ($is_mikrotik and $mk_ros_version>6468)) {
-        foreach ($index_table as $key => $value) {
+#get map snmp interfaces to fdb table
+if (isset($index_map_table) and count($index_map_table) > 0) {
+        foreach ($index_map_table as $key => $value) {
             $key = trim($key);
             $key = trim($key);
             $value = intval(trim(str_replace('INTEGER:', '', $value)));
             $value = intval(trim(str_replace('INTEGER:', '', $value)));
             $result = preg_match('/\.(\d{1,10})$/',$key,$matches);
             $result = preg_match('/\.(\d{1,10})$/',$key,$matches);
             if ($result) {
             if ($result) {
-                $int_index = preg_replace('/^\./', '', $matches[0]);
-                $ifmib_map[$int_index]=$value;
+                $fdb_index = preg_replace('/^\./', '', $matches[0]);
+                $ifmib_map[$fdb_index]=$value;
                 }
                 }
             }
             }
-        } else {
-#        $index_table =  walk_snmp($ip, $community, $version, IFMIB_IFINDEX);
-        if (isset($index_table) and count($index_table) > 0) {
-            foreach ($index_table as $key => $value) {
-                $key = trim($key);
+        }
+        
+#return simple map snmp_port_index = snmp_port_index
+if (empty($ifmib_map)) {
+    #ifindex
+    $index_table = walk_snmp($ip, $community, $version, IFMIB_IFINDEX);
+    if (isset($index_table) and count($index_table) > 0) {
+        foreach ($index_table as $key => $value) {
+            $key = trim($key);
 	        $value = intval(trim(str_replace('INTEGER:', '', $value)));
 	        $value = intval(trim(str_replace('INTEGER:', '', $value)));
-    	        $result = preg_match('/\.(\d{1,10})$/',$key,$matches);
+    	    $result = preg_match('/\.(\d{1,10})$/',$key,$matches);
         	if ($result) {
         	if ($result) {
-            	        $int_index = preg_replace('/^\./', '', $matches[0]);
-            		$ifmib_map[$int_index]=$int_index;
+                    $fdb_index = preg_replace('/^\./', '', $matches[0]);
+            		$ifmib_map[$fdb_index]=$value;
             		}
             		}
-                }
-            }
-        }
-return $ifmib_map;
-}
-
-function get_fdb_port_table($ip, $port_index, $community, $version)
-{
-
-    if (! isset($ip)) {
-        return;
-    }
-    if (! isset($port_index)) {
-        return;
-    }
-    if (! isset($community)) {
-        $community = 'public';
-    }
-    if (! isset($version)) {
-        $version = '2';
-    }
-
-    $ifindex_map = get_ifmib_index_table($ip,$community, $version);
-    $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?!
-    if (! isset($fdb_port_table) or ! $fdb_port_table or count($fdb_port_table) == 0) {
-        $vlan_table = walk_snmp($ip, $community, $version, CISCO_VLAN_OID);
-        if (! $vlan_table) {
-            return;
-        }
-        //fucking cisco!!!
-        foreach ($vlan_table as $vlan_oid => $value) {
-            if (! $vlan_oid) { continue; }
-            $pattern = '/\.(\d{1,4})$/';
-            $result = preg_match($pattern, $vlan_oid, $matches);
-            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_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_OID2,$ifindex_map);
-                }
-                foreach ($fdb_vlan_table as $mac => $port) {
-                    if (! isset($mac)) { continue; }
-                    $fdb_port_table[$mac] = $port;
-                }
             }
             }
         }
         }
     }
     }
-    return $fdb_port_table;
+return $ifmib_map;
 }
 }
 
 
+#get mac table by selected snmp oid
 function get_mac_table($ip, $community, $version, $oid, $index_map)
 function get_mac_table($ip, $community, $version, $oid, $index_map)
 {
 {
     if (! isset($ip)) {
     if (! isset($ip)) {
@@ -1879,8 +1781,14 @@ function get_mac_table($ip, $community, $version, $oid, $index_map)
             $value_raw = intval(trim(str_replace('INTEGER:', '', $value)));
             $value_raw = intval(trim(str_replace('INTEGER:', '', $value)));
             if (empty($value_raw)) { continue; }
             if (empty($value_raw)) { continue; }
             if (!empty($index_map)) {
             if (!empty($index_map)) {
-                if (empty($index_map[$value_raw])) { $value = $value_raw; } else { $value = $index_map[$value_raw]; }
-                } else { $value = $value_raw; }
+                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})$/';
             $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);
             $result = preg_match($pattern, $key, $matches);
             if (!empty($result)) {
             if (!empty($result)) {
@@ -1892,6 +1800,7 @@ function get_mac_table($ip, $community, $version, $oid, $index_map)
     return $fdb_table;
     return $fdb_table;
 }
 }
 
 
+#get mac table by analyze all available tables
 function get_fdb_table($ip, $community, $version)
 function get_fdb_table($ip, $community, $version)
 {
 {
 
 
@@ -1910,18 +1819,16 @@ function get_fdb_table($ip, $community, $version)
     if (!empty($fdb1_table)) {
     if (!empty($fdb1_table)) {
         $fdb_table = $fdb1_table;
         $fdb_table = $fdb1_table;
         } else {
         } else {
-        $fdb2_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID2, NULL);
+        $fdb2_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID2, $ifindex_map);
         if (!empty($fdb2_table)) { $fdb_table = $fdb2_table; }
         if (!empty($fdb2_table)) { $fdb_table = $fdb2_table; }
         }
         }
 
 
     // maybe cisco?!
     // maybe cisco?!
-    if (! isset($fdb_table) or ! $fdb_table or count($fdb_table) == 0) {
+    if (! isset($fdb_table) or empty($fdb_table) or count($fdb_table) == 0) {
         $vlan_table = walk_snmp($ip, $community, $version, CISCO_VLAN_OID);
         $vlan_table = walk_snmp($ip, $community, $version, CISCO_VLAN_OID);
-        if (! $vlan_table) {
-            return;
-        }
+        if (empty($vlan_table)) { return; }
         foreach ($vlan_table as $vlan_oid => $value) {
         foreach ($vlan_table as $vlan_oid => $value) {
-            if (! $vlan_oid) { continue; }
+            if (empty($vlan_oid)) { continue; }
             $pattern = '/\.(\d{1,4})$/';
             $pattern = '/\.(\d{1,4})$/';
             $result = preg_match($pattern, $vlan_oid, $matches);
             $result = preg_match($pattern, $vlan_oid, $matches);
             if (!empty($result)) {
             if (!empty($result)) {
@@ -1930,14 +1837,14 @@ function get_fdb_table($ip, $community, $version)
                 $fdb_vlan_table = get_mac_table($ip, $community.'@'.$vlan_id, $version, MAC_TABLE_OID,$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) {
                 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_OID2,$ifindex_map);
                     $fdb_vlan_table = get_mac_table($ip, $community, $version, MAC_TABLE_OID2,$ifindex_map);
-                }
+                    }
                 foreach ($fdb_vlan_table as $mac => $port) {
                 foreach ($fdb_vlan_table as $mac => $port) {
                     if (! isset($mac)) { continue; }
                     if (! isset($mac)) { continue; }
                     $fdb_table[$mac] = $port;
                     $fdb_table[$mac] = $port;
+                    }
                 }
                 }
             }
             }
         }
         }
-    }
     return $fdb_table;
     return $fdb_table;
 }
 }
 
 
@@ -2059,8 +1966,6 @@ function get_sfp_status($vendor_id, $port, $ip, $community, $version, $modules_o
     if (! isset($version)) {
     if (! isset($version)) {
         $version = '2';
         $version = '2';
     }
     }
-    // if (!is_up($ip)) { return; }
-
 
 
     $status = '';
     $status = '';
     // eltex
     // eltex
@@ -2158,7 +2063,6 @@ function get_sfp_status($vendor_id, $port, $ip, $community, $version, $modules_o
     // huawei
     // huawei
     if ($vendor_id == 3) {
     if ($vendor_id == 3) {
         
         
-        
         // get interface names
         // get interface names
         $port_name = parse_snmp_value(get_snmp($ip, $community, $version, IFMIB_IFNAME . "." . $port));
         $port_name = parse_snmp_value(get_snmp($ip, $community, $version, IFMIB_IFNAME . "." . $port));
         if (empty($port_name)) {
         if (empty($port_name)) {
@@ -2218,7 +2122,7 @@ function get_sfp_status($vendor_id, $port, $ip, $community, $version, $modules_o
     return;
     return;
 }
 }
 
 
-function get_port_vlan($vendor, $port, $port_index, $ip, $community, $version, $fdb_by_snmp)
+function get_port_vlan($vendor, $port, $port_index, $ip, $community, $version)
 {
 {
     if (! isset($port)) {
     if (! isset($port)) {
         return;
         return;
@@ -2232,11 +2136,9 @@ function get_port_vlan($vendor, $port, $port_index, $ip, $community, $version, $
     if (! isset($version)) {
     if (! isset($version)) {
         $version = '2';
         $version = '2';
     }
     }
-    // if (!is_up($ip)) { return; }
-
-    if ($fdb_by_snmp == 1) { $port = $port_index; }
 
 
     if ($vendor == 69) { $port_oid = TPLINK_VLAN_PVID . "." . $port; } else { $port_oid = PORT_VLAN_OID . "." . $port; }
     if ($vendor == 69) { $port_oid = TPLINK_VLAN_PVID . "." . $port; } else { $port_oid = PORT_VLAN_OID . "." . $port; }
+
     $port_vlan = get_snmp($ip, $community, $version, $port_oid);
     $port_vlan = get_snmp($ip, $community, $version, $port_oid);
     $port_vlan = preg_replace('/.*\:/','',$port_vlan);
     $port_vlan = preg_replace('/.*\:/','',$port_vlan);
     $port_vlan = intval(trim($port_vlan));
     $port_vlan = intval(trim($port_vlan));
@@ -2589,7 +2491,6 @@ function get_port_state_detail($port, $ip, $community, $version)
     }
     }
     // if (!is_up($ip)) { return; }
     // if (!is_up($ip)) { return; }
 
 
-
     $oper = PORT_STATUS_OID . $port;
     $oper = PORT_STATUS_OID . $port;
     $admin = PORT_ADMIN_STATUS_OID . $port;
     $admin = PORT_ADMIN_STATUS_OID . $port;
     $speed = PORT_SPEED_OID . $port;
     $speed = PORT_SPEED_OID . $port;

+ 67 - 75
scripts/Rstat/snmp.pm

@@ -173,6 +173,43 @@ sub get_arp_table {
 
 
 #-------------------------------------------------------------------------------------
 #-------------------------------------------------------------------------------------
 
 
+sub get_ifmib_index_table {
+my $ip = shift;
+my $community = shift;
+my $version = shift;
+my $ifmib_map;
+
+my $index_map_table =  snmp_get_oid($ip, $community, $ifIndex_map, $version);
+if (!$index_map_table) { $index_map_table =  snmp_walk_oid($ip, $community, $ifIndex_map, $version); }
+
+if ($index_map_table) {
+    foreach my $row (keys(%$index_map_table)) {
+        my $port_index = $index_map_table->{$row};
+        next if (!$port_index);
+   	    my $value;
+        if ($row=~/\.([0-9]{1,10})$/) { $value = $1; }
+        next if (!$value);
+        $ifmib_map->{$value}=$port_index;
+       	}
+    }
+
+if (!$ifmib_map) {
+    my $index_table =  snmp_get_oid($ip, $community, $if_index, $version);
+    if (!$index_table) { $index_map_table =  snmp_walk_oid($ip, $community, $if_index, $version); }
+    foreach my $row (keys(%$index_table)) {
+	    my $port_index = $index_table->{$row};
+	    next if (!$port_index);
+        my $value;
+        if ($row=~/\.([0-9]{1,10})$/) { $value = $1; }
+	    next if (!$value);
+    	$ifmib_map->{$value}=$value;
+        };
+    }
+return $ifmib_map;
+}
+
+#-------------------------------------------------------------------------------------
+
 sub get_mac_table {
 sub get_mac_table {
     my ($host,$community,$oid,$version,$index_map) = @_;
     my ($host,$community,$oid,$version,$index_map) = @_;
     my $port = 161;
     my $port = 161;
@@ -185,63 +222,18 @@ sub get_mac_table {
     if (!$fdb_table1) { $fdb_table1=snmp_walk_oid($host,$community,$oid,$version,undef); }
     if (!$fdb_table1) { $fdb_table1=snmp_walk_oid($host,$community,$oid,$version,undef); }
     if ($fdb_table1) {
     if ($fdb_table1) {
         foreach my $row (keys(%$fdb_table1)) {
         foreach my $row (keys(%$fdb_table1)) {
-	    my $port_index = $fdb_table1->{$row};
-        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);
-        if ($index_map and exists $index_map->{$port_index}) { $port_index = $index_map->{$port_index}; }
-	    $fdb->{$mac}=$port_index;
-	    };
+	        my $port_index = $fdb_table1->{$row};
+            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);
+            if ($index_map and exists $index_map->{$port_index}) { $port_index = $index_map->{$port_index}; }
+	        $fdb->{$mac}=$port_index;
+	        };
         return $fdb;
         return $fdb;
-	}
-}
-
-#-------------------------------------------------------------------------------------
-
-sub get_ifmib_index_table {
-my $ip = shift;
-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); }
-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;
-
-if ($is_mikrotik=~/MikroTik/i) {
-    my $mikrotik_version = snmp_get_request($ip, '.1.0.8802.1.1.2.1.3.4.0', $community, 161, $version);
-    #"MikroTik RouterOS 6.46.8 (long-term) CRS326-24S+2Q+"
-    if ($mikrotik_version =~/RouterOS\s+(\d)\.(\d{1,3})\.(\d{1,3})\s+/) {
-        $mk_ros_version = $1*1000 + $2*10 + $3;
-        }
-    }
-
-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;
-                if ($row=~/\.([0-9]{1,10})$/) { $value = $1; }
-	            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;
-                if ($row=~/\.([0-9]{1,10})$/) { $value = $1; }
-	            next if (!$value);
-    	        $ifmib_map->{$value}=$value;
-                };
-            }
-        }
-return $ifmib_map;
+	    }
 }
 }
 
 
 #-------------------------------------------------------------------------------------
 #-------------------------------------------------------------------------------------
@@ -264,29 +256,29 @@ sub get_fdb_table {
 
 
     #maybe cisco?!
     #maybe cisco?!
     if (!$fdb) {
     if (!$fdb) {
-	my $vlan_table=snmp_get_oid($host,$community,$cisco_vlan_oid,$version);
+	    my $vlan_table=snmp_get_oid($host,$community,$cisco_vlan_oid,$version);
         if (!$vlan_table) { $vlan_table=snmp_walk_oid($host,$community,$cisco_vlan_oid,$version); }
         if (!$vlan_table) { $vlan_table=snmp_walk_oid($host,$community,$cisco_vlan_oid,$version); }
         #fuck!
         #fuck!
         if (!$vlan_table) { return; }
         if (!$vlan_table) { return; }
         my %fdb_vlan;
         my %fdb_vlan;
-	foreach my $vlan_oid (keys %$vlan_table) {
-	    next if (!$vlan_oid);
-	    my $vlan_id;
-	    if ($vlan_oid=~/\.([0-9]{1,4})$/) { $vlan_id=$1; }
-	    next if (!$vlan_id);
-	    next if ($vlan_id>1000 and $vlan_id<=1009);
-	    $fdb_vlan{$vlan_id}=get_mac_table($host,$community.'@'.$vlan_id,$fdb_table_oid,$version,$ifindex_map);
-	    if (!$fdb_vlan{$vlan_id}) { $fdb_vlan{$vlan_id}=get_mac_table($host,$community.'@'.$vlan_id,$fdb_table_oid2,$version,$ifindex_map); }
-	    }
-	foreach my $vlan_id (keys %fdb_vlan) {
-	    next if (!exists $fdb_vlan{$vlan_id});
-	    if (defined $fdb_vlan{$vlan_id}) {
-		my %tmp=%{$fdb_vlan{$vlan_id}};
-		foreach my $mac (keys %tmp) {
-			next if (!$mac);
-			$fdb->{$mac}=$tmp{$mac};
-			}
-		}
+	    foreach my $vlan_oid (keys %$vlan_table) {
+	        next if (!$vlan_oid);
+	        my $vlan_id;
+	        if ($vlan_oid=~/\.([0-9]{1,4})$/) { $vlan_id=$1; }
+	        next if (!$vlan_id);
+	        next if ($vlan_id>1000 and $vlan_id<=1009);
+	        $fdb_vlan{$vlan_id}=get_mac_table($host,$community.'@'.$vlan_id,$fdb_table_oid,$version,$ifindex_map);
+	        if (!$fdb_vlan{$vlan_id}) { $fdb_vlan{$vlan_id}=get_mac_table($host,$community.'@'.$vlan_id,$fdb_table_oid2,$version,$ifindex_map); }
+	        }
+	    foreach my $vlan_id (keys %fdb_vlan) {
+	        next if (!exists $fdb_vlan{$vlan_id});
+	        if (defined $fdb_vlan{$vlan_id}) {
+		        my %tmp=%{$fdb_vlan{$vlan_id}};
+		        foreach my $mac (keys %tmp) {
+			        next if (!$mac);
+			        $fdb->{$mac}=$tmp{$mac};
+			        }
+		    }
 	    }
 	    }
 	}
 	}
     return $fdb;
     return $fdb;

+ 4 - 6
scripts/fetch_new_arp.pl

@@ -260,7 +260,7 @@ foreach my $port_data (@device_ports) {
     my $fdb_port_index=$port_data->{port};
     my $fdb_port_index=$port_data->{port};
     my $port_id = $port_data->{id};
     my $port_id = $port_data->{id};
     if (!$port_data->{snmp_index}) { $port_data->{snmp_index} = $port_data->{port}; }
     if (!$port_data->{snmp_index}) { $port_data->{snmp_index} = $port_data->{port}; }
-    if ($device->{fdb_snmp_index}) { $fdb_port_index=$port_data->{snmp_index}; }
+    $fdb_port_index=$port_data->{snmp_index};
     my $current_vlan = $vlans->{$fdb_port_index};
     my $current_vlan = $vlans->{$fdb_port_index};
     if (!$current_vlan) { $current_vlan=1; }
     if (!$current_vlan) { $current_vlan=1; }
     if ($current_vlan != $vlan) {
     if ($current_vlan != $vlan) {
@@ -292,11 +292,9 @@ foreach my $mac (keys %$fdb) {
     my $port = $fdb->{$mac};
     my $port = $fdb->{$mac};
     next if (!$port);
     next if (!$port);
     #real port number
     #real port number
-    if ($device->{fdb_snmp_index}) {
-        #если mac-таблица привязана к snmp-индексам портов, номер порта ставим в snmp-индекс порта
-        if (!exists $port_snmp_index{$port}) { next; }
-        $port=$port_snmp_index{$port};
-        }
+    if (!exists $port_snmp_index{$port}) { next; }
+    #get real port number by snmp our snmp index
+    $port=$port_snmp_index{$port};
     if (!exists $port_index{$port}) { next; }
     if (!exists $port_index{$port}) { next; }
     #mikrotik patch - skip mikrotik device mac
     #mikrotik patch - skip mikrotik device mac
     if ($sw_mac and $mac=~/^$sw_mac/i) { next; }
     if ($sw_mac and $mac=~/^$sw_mac/i) { next; }