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
This commit is contained in:
PipoCanaja
2019-08-14 08:34:35 +02:00
committed by GitHub
parent 4631705838
commit 67376e2e95

View File

@@ -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'])) {