فهرست منبع

optimize get interface names by snmp

Roman Dmitriev 2 سال پیش
والد
کامیت
38d71ecc5d
5فایلهای تغییر یافته به همراه30 افزوده شده و 15 حذف شده
  1. 3 6
      html/admin/devices/snmpwalk.php
  2. 6 2
      html/admin/devices/switchport.php
  3. 3 4
      html/admin/devices/switchstatus.php
  4. 17 3
      html/inc/common.php
  5. 1 0
      html/inc/consts.php

+ 3 - 6
html/admin/devices/snmpwalk.php

@@ -24,16 +24,13 @@ if ($snmp_ok) {
     $interfaces = get_snmp_interfaces($device['ip'], $device['community'], $device['snmp_version']);
     $dev_info = walk_snmp($device['ip'], $device['community'], $device['snmp_version'],SYSINFO_MIB);
     foreach ($dev_info as $key => $value) {
-        list ($v_type,$v_data)=explode(':',$value);
-        $v_clean = preg_replace('/\s/', '', $v_data);
-        if (empty($v_clean)) { continue; }
-        print "$v_data<br>";
+        $v_data = trim(parse_snmp_value($value));
+        if (!empty($v_data)) { print "$v_data<br>"; }
         }
     print "<table  class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
     print "<tr><td><b>".WEB_snmp_interface_index."</div></b></td><td><b>".WEB_snmp_interface_name."</b></td></tr>\n";
     foreach ($interfaces as $key => $int) { 
-        list ($v_type,$v_data)=explode(':',$int);
-        print "<tr><td class=\"data\">$key</td><td class=\"data\"> $v_data</td></tr>"; 
+        print "<tr><td class=\"data\">$key</td><td class=\"data\"> $int</td></tr>"; 
         }
     print "</table>\n";
     } else { print "No SNMP access!"; }

+ 6 - 2
html/admin/devices/switchport.php

@@ -108,7 +108,11 @@ foreach ($ports as $row) {
         print "<td class='".$cl."' >" . get_qa($row['uplink']) . "</td>\n";
         print "<td class='".$cl."' >" . get_qa($row['nagios']) . "</td>\n";
         print "<td class='".$cl."' >" . get_qa($row['skip']) . "</td>\n";
-        $vlan = $row['vlan'];
+        $display_vlan= $row['vlan'];
+        if (!empty($row['untagged_vlan'])) { 
+            if ($row['untagged_vlan'] != $row['vlan']) { $display_vlan.=";U:".$row['untagged_vlan']; }
+            }
+        if (!empty($row['tagged_vlan'])) { $display_vlan.=";T:".$row['tagged_vlan']; }
         $ifname= compact_port_name($row['ifName']);
         $f_cacti_url = get_cacti_graph($device['ip'], $row['snmp_index']);
         if (empty(get_const('torrus_url')) and (empty($f_cacti_url))) {  $snmp_url=$ifname; }
@@ -123,7 +127,7 @@ foreach ($ports as $row) {
                     $snmp_url = "<a href='".$t_url."'>" . $ifname . "</a>";
                     }
                 }
-        print "<td class='".$cl."'>" . $vlan . "</td>\n";
+        print "<td class='".$cl."'>" . $display_vlan . "</td>\n";
         print "<td class='".$cl."'>" . $snmp_url . "</td>\n";
         print "<td class='".$cl."' ><button name='write' class='j-submit-report' onclick='window.open('portmactable.php?id=" . $row['id'] . "')'>" . $row['last_mac_count'] . "</button></td>\n";
 print "</tr>";

+ 3 - 4
html/admin/devices/switchstatus.php

@@ -99,6 +99,7 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
                     $modules_oids = snmprealwalk($device['ip'], $device['community'], CISCO_MODULES, SNMP_timeout, SNMP_retry);
                     }
                 $vlan_list = get_switch_vlans($device['vendor_id'],$device['ip'], $device['community'], $device['snmp_version']);
+                $ifmib_list = get_snmp_interfaces($device['ip'], $device['community'], $device['snmp_version']);
                 }
             } else {
             $snmp_ok = 0;
@@ -176,10 +177,6 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
             $ifname = $row['ifName'];
 
             if ($snmp_ok) {
-                $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']);
-                }
                 $sfp_status = get_sfp_status($device['vendor_id'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version'], $modules_oids);
                 $poe_status = get_port_poe_state($device['vendor_id'], $row['port'], $row['snmp_index'], $device['ip'], $device['community'], $device['snmp_version']);
                 if (isset($poe_status)) {
@@ -205,6 +202,8 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
                         }
                     if (!empty($new_info['tagged_vlan'])) { $display_vlan.=";T:".$new_info['tagged_vlan']; }
                 }
+                //interface name
+                if (!empty($ifmib_list[$row['snmp_index']])) { $ifname = $ifmib_list[$row['snmp_index']]; }
                 if (!isset($row['ifName']) or $row['ifName'] !== $ifname) {
                     $new_info['ifName'] = $ifname;
                 }

+ 17 - 3
html/inc/common.php

@@ -2293,9 +2293,23 @@ function get_snmp_ifname2($ip, $community, $version, $port)
 
 function get_snmp_interfaces($ip, $community, $version)
 {
-    $result = walk_snmp($ip, $community, $version, IFMIB_IFNAME);
-    if (empty($result)) {
-        $result = walk_snmp($ip, $community, $version, IFMIB_IFDESCR);
+    $result=[];
+    $ifmib_list = walk_snmp($ip, $community, $version, IFMIB_IFNAME);
+    if (empty($ifmib_list)) {
+        $ifmib_list = walk_snmp($ip, $community, $version, IFMIB_IFDESCR);
+    }
+    if (empty($ifmib_list)) {
+        $ifmib_list = walk_snmp($ip, $community, $version, IFMIB_IFALIAS);
+    }
+    if (!empty($ifmib_list)) {
+        foreach ($ifmib_list as $key => $value) {
+            $key = trim($key);
+            $value = parse_snmp_value($value);
+            if (preg_match('/\.(\d{1,10})$/', $key, $matches)) { 
+                $int_index = preg_replace('/^\./', '', $matches[0]); 
+                $result[$int_index]=$value;
+            }
+        }
     }
     return $result;
 }

+ 1 - 0
html/inc/consts.php

@@ -37,6 +37,7 @@ define("IFMIB_IFINDEX",".1.3.6.1.2.1.2.2.1.1");
 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("IFMIB_IFALIAS",".1.3.6.1.2.1.31.1.1.1.18");
 
 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");