From f01cf38a3ae15ddefd18813b2bdd1ca423920340 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 24 Oct 2017 02:21:32 -0500 Subject: [PATCH] fix: lldp discovery change local port resolution (#7443) * fix: lldp discovery change local port resolution dot1dBasePortIfIndex seems to skip some ports in certain configurations on Cisco devices. Add quirk for Calix devices that return different port labels than they actually are. * bdcom uses NMS-LLDP-MIB too. * use dot1dBasePort to look up ifIndex if we can. --- includes/discovery/discovery-protocols.inc.php | 14 +++++++++++--- includes/discovery/functions.inc.php | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index 6c872b9ad3..82c865a021 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -81,7 +81,7 @@ if (Config::get('autodiscovery.xdp') === true) { echo PHP_EOL; }//end if -if ($device['os'] == 'pbn' && Config::get('autodiscovery.xdp') === true) { +if (($device['os'] == 'pbn' || $device['os'] == 'bdcom') && Config::get('autodiscovery.xdp') === true) { echo ' NMS-LLDP-MIB: '; $lldp_array = snmpwalk_group($device, 'lldpRemoteSystemsData', 'NMS-LLDP-MIB'); @@ -118,6 +118,7 @@ if ($device['os'] == 'pbn' && Config::get('autodiscovery.xdp') === true) { $lldp_array = snmpwalk_group($device, 'lldpRemTable', 'LLDP-MIB', 3); if (!empty($lldp_array)) { $dot1d_array = snmpwalk_group($device, 'dot1dBasePortIfIndex', 'BRIDGE-MIB'); + $lldp_ports = snmpwalk_group($device, 'lldpLocPortId', 'LLDP-MIB'); } foreach ($lldp_array as $key => $lldp_if_array) { @@ -127,7 +128,10 @@ if ($device['os'] == 'pbn' && Config::get('autodiscovery.xdp') === true) { } else { $ifIndex = $entry_key; } - $interface = get_port_by_ifIndex($device['device_id'], $ifIndex); + + $local_port_id = find_port_id($lldp_ports[$entry_key]['lldpLocPortId'], $ifIndex, $device['device_id']); + $interface = get_port_by_id($local_port_id); + d_echo($lldp_instance); foreach ($lldp_instance as $entry_instance => $lldp) { @@ -157,6 +161,11 @@ if ($device['os'] == 'pbn' && Config::get('autodiscovery.xdp') === true) { } } + $remote_device = device_by_id_cache($remote_device_id); + if ($remote_device['os'] == 'calix') { + $lldp['lldpRemPortId'] = 'EthPort ' . $lldp['lldpRemPortId']; + } + $remote_port_id = find_port_id( $lldp['lldpRemPortDesc'], $lldp['lldpRemPortId'], @@ -165,7 +174,6 @@ if ($device['os'] == 'pbn' && Config::get('autodiscovery.xdp') === true) { ); if (empty($lldp['lldpRemSysName'])) { - $remote_device = device_by_id_cache($remote_device_id); $lldp['lldpRemSysName'] = $remote_device['sysName'] ?: $remote_device['hostname']; } diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 6a8726d7c4..5d915a4d50 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -1439,7 +1439,7 @@ function find_port_id($description, $identifier = '', $device_id = 0, $mac_addre if ($identifier) { if (is_numeric($identifier)) { - $sql .= ' OR `ifAlias`=? OR `ifIndex`=?'; + $sql .= ' OR `ifIndex`=? OR `ifAlias`=?'; } else { $sql .= ' OR `ifDescr`=? OR `ifName`=?'; }