Fixed the issues with JetStream lldp discovery (#16414)

* Fixed the issues with JetStream lldp discovery

* Added is_array() check
This commit is contained in:
Neil Lathwood
2024-09-25 13:43:24 +01:00
committed by GitHub
parent 52c96a6e79
commit 9cddd7fd21

View File

@@ -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 {