From 67376e2e95f2aab26ac23d0ea19c0531d5cc60f2 Mon Sep 17 00:00:00 2001 From: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com> Date: Wed, 14 Aug 2019 08:34:35 +0200 Subject: [PATCH] Reduce discovery snmp load of Cisco VTP vlans module (#10510) * Only poll necessary OIDs for Cisco VTP vlan discovery, the current code overload some nexus devices * codeclimate --- includes/discovery/vlans/cisco-vtp.inc.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/discovery/vlans/cisco-vtp.inc.php b/includes/discovery/vlans/cisco-vtp.inc.php index 33b2100151..c276e40571 100644 --- a/includes/discovery/vlans/cisco-vtp.inc.php +++ b/includes/discovery/vlans/cisco-vtp.inc.php @@ -3,15 +3,16 @@ if ($device['os_group'] == 'cisco') { echo "Cisco VLANs:\n"; - $native_vlans = snmpwalk_cache_oid($device, 'vlanTrunkPortNativeVlan', array(), 'CISCO-VTP-MIB'); + $native_vlans = snmpwalk_cache_oid($device, 'vlanTrunkPortNativeVlan', [], 'CISCO-VTP-MIB'); $native_vlans = snmpwalk_cache_oid($device, 'vmVlan', $native_vlans, 'CISCO-VLAN-MEMBERSHIP-MIB'); // Not sure why we check for VTP, but this data comes from that MIB, so... $vtpversion = snmp_get($device, 'vtpVersion.0', '-OnvQ', 'CISCO-VTP-MIB'); - if ($vtpversion == '1' || $vtpversion == '2' || $vtpversion == '3' || $vtpversion == 'one' || $vtpversion == 'two' || $vtpversion == 'three' || $vtpversion == 'none') { + if (in_array($vtpversion, ['1', '2', '3', 'one', 'two', 'three', 'none'])) { // FIXME - can have multiple VTP domains. - $vtpdomains = snmpwalk_cache_oid($device, 'vlanManagementDomains', array(), 'CISCO-VTP-MIB'); - $vlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanEntry', array(), 'CISCO-VTP-MIB'); + $vtpdomains = snmpwalk_cache_oid($device, 'vlanManagementDomains', [], 'CISCO-VTP-MIB'); + $vlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanName', [], 'CISCO-VTP-MIB'); + $vlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanType', $vlans, 'CISCO-VTP-MIB'); foreach ($vtpdomains as $vtpdomain_id => $vtpdomain) { echo 'VTP Domain '.$vtpdomain_id.' '.$vtpdomain['managementDomainName'].' '; @@ -37,11 +38,13 @@ if ($device['os_group'] == 'cisco') { // Ignore reserved VLAN IDs // get dot1dStpPortEntry within the vlan context $vlan_device = array_merge($device, array('community' => $device['community'] . '@' . $vlan_id, 'context_name' => "vlan-$vlan_id")); - $tmp_vlan_data = snmpwalk_cache_oid($vlan_device, 'dot1dStpPortEntry', array(), 'BRIDGE-MIB'); + $tmp_vlan_data = snmpwalk_cache_oid($vlan_device, 'dot1dStpPortPriority', [], 'BRIDGE-MIB'); + $tmp_vlan_data = snmpwalk_cache_oid($vlan_device, 'dot1dStpPortState', $tmp_vlan_data, 'BRIDGE-MIB'); + $tmp_vlan_data = snmpwalk_cache_oid($vlan_device, 'dot1dStpPortPathCost', $tmp_vlan_data, 'BRIDGE-MIB'); // may need to fetch additional dot1dBasePortIfIndex mappings $tmp_vlan_data = snmpwalk_cache_oid($vlan_device, 'dot1dBasePortIfIndex', $tmp_vlan_data, 'BRIDGE-MIB'); - $vlan_data = array(); + $vlan_data = []; // flatten the array, use ifIndex instead of dot1dBasePortId foreach ($tmp_vlan_data as $index => $array) { if (isset($array['dot1dBasePortIfIndex'])) {