From 9cddd7fd210d9b16880ac243f7ca82256d39736c Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Wed, 25 Sep 2024 13:43:24 +0100 Subject: [PATCH] Fixed the issues with JetStream lldp discovery (#16414) * Fixed the issues with JetStream lldp discovery * Added is_array() check --- .../discovery/discovery-protocols.inc.php | 71 ++++++++++--------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index 3a440cb1ac..cd7a283bec 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -205,43 +205,44 @@ if (($device['os'] == 'routeros') && version_compare($device['version'], '7.7', } elseif ($device['os'] == 'jetstream') { echo ' JETSTREAM-LLDP MIB: '; - $lldp_array = SnmpQuery::hideMib()->walk('TPLINK-LLDPINFO-MIB::lldpNeighborInfoEntry')->table(); + $lldp = SnmpQuery::hideMib()->walk('TPLINK-LLDPINFO-MIB::lldpNeighborInfoEntry')->table(); - foreach ($lldp_array as $key => $lldp) { - if (! is_array($lldp['lldpNeighborPortIndexId'])) { - // code below will fail so no need to finish this loop occurence. - continue; + if (is_array($lldp['lldpNeighborPortIndexId'])) { + foreach ($lldp['lldpNeighborPortIndexId'] as $IndexId => $lldp_data) { + if (! is_array($lldp_data)) { + // code below will fail so no need to finish this loop occurence. + continue; + } + + $local_ifName = $lldp['lldpNeighborPortId'][$IndexId][1]; + $local_port_id = find_port_id('gigabitEthernet ' . $local_ifName, null, $device['device_id']); + + $remote_device_id = find_device_id($lldp['lldpNeighborDeviceName'][$IndexId][1]); + $remote_device_name = $lldp['lldpNeighborDeviceName'][$IndexId][1]; + $remote_device_sysDescr = $lldp['lldpNeighborDeviceDescr'][$IndexId][1]; + $remote_device_ip = $lldp['lldpNeighborManageIpAddr'][$IndexId][1]; + $remote_port_descr = $lldp['lldpNeighborPortIdDescr'][$IndexId][1]; + $remote_port_id = find_port_id($remote_port_descr, null, $remote_device_id); + + if (! $remote_device_id && + \LibreNMS\Util\Validate::hostname($remote_device_name) && + ! can_skip_discovery($remote_device_name, $remote_device_ip) && + Config::get('autodiscovery.xdp') === true) { + $remote_device_id = discover_new_device($remote_device_name, $device, 'LLDP', $local_ifName); + } + + discover_link( + $local_port_id, //our port id from database + 'lldp', + $remote_port_id, //remote port id from database if applicable + $remote_device_name, //remote device name from SNMP walk + $remote_port_descr, //remote port description from SNMP walk + null, + $remote_device_sysDescr, //remote device description from SNMP walk + $device['device_id'], //our device id + $remote_device_id //remote device id if applicable + ); } - $IndexId = key($lldp['lldpNeighborPortIndexId']); - - $local_ifName = $lldp['lldpNeighborPortId'][$IndexId]; - $local_port_id = find_port_id('gigabitEthernet ' . $local_ifName, null, $device['device_id']); - - $remote_device_id = find_device_id($lldp['lldpNeighborDeviceName'][$IndexId]); - $remote_device_name = $lldp['lldpNeighborDeviceName'][$IndexId]; - $remote_device_sysDescr = $lldp['lldpNeighborDeviceDescr'][$IndexId]; - $remote_device_ip = $lldp['lldpNeighborManageIpAddr'][$IndexId]; - $remote_port_descr = $lldp['lldpNeighborPortIdDescr'][$IndexId]; - $remote_port_id = find_port_id($remote_port_descr, null, $remote_device_id); - - if (! $remote_device_id && - \LibreNMS\Util\Validate::hostname($remote_device_name) && - ! can_skip_discovery($remote_device_name, $remote_device_ip) && - Config::get('autodiscovery.xdp') === true) { - $remote_device_id = discover_new_device($remote_device_name, $device, 'LLDP', $local_ifName); - } - - discover_link( - $local_port_id, //our port id from database - 'lldp', - $remote_port_id, //remote port id from database if applicable - $remote_device_name, //remote device name from SNMP walk - $remote_port_descr, //remote port description from SNMP walk - null, - $remote_device_sysDescr, //remote device description from SNMP walk - $device['device_id'], //our device id - $remote_device_id //remote device id if applicable - ); } echo PHP_EOL; } else {