Skip to content

Commit 08451a2

Browse files
authored
fix error in discovery-protocols (librenms#17579)
* fix discovery-protocols.inc.php * ci
1 parent a2b91d2 commit 08451a2

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

includes/discovery/discovery-protocols.inc.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ function ($v) {
372372
if (str_ends_with($lldp['lldpRemSysDesc'], 'Gigabit Switch w/WebView')) {
373373
$lldp['lldpRemPortDesc'] = '';
374374
}
375-
376-
$remote_device_id = find_device_id($lldp['lldpRemSysName'], $lldp['lldpRemManAddr'], $remote_port_mac);
377-
375+
$remote_device_id = find_device_id($lldp['lldpRemSysName'], $lldp['lldpRemManAddr'] ?? '', $remote_port_mac);
378376
// add device if configured to do so
379377
if (! $remote_device_id && ! can_skip_discovery($lldp['lldpRemSysName'], $lldp['lldpRemSysDesc']) &&
380378
Config::get('autodiscovery.xdp') === true) {
@@ -397,32 +395,34 @@ function ($v) {
397395
}
398396
}
399397

400-
$remote_device = device_by_id_cache($remote_device_id);
401-
if ($remote_device['os'] == 'calix') {
402-
$remote_port_name = 'EthPort ' . $lldp['lldpRemPortId'];
403-
}
398+
if (! empty($remote_device_id)) {
399+
$remote_device = device_by_id_cache($remote_device_id);
400+
if ($remote_device['os'] == 'calix') {
401+
$remote_port_name = 'EthPort ' . $lldp['lldpRemPortId'];
402+
}
404403

405-
if ($remote_device['os'] == 'xos') {
406-
$slot_port = explode(':', $remote_port_name);
407-
if (count($slot_port) == 2) {
408-
$n_slot = (int) $slot_port[0];
409-
$n_port = (int) $slot_port[1];
410-
} else {
411-
$n_slot = 1;
412-
$n_port = (int) $slot_port[0];
404+
if ($remote_device['os'] == 'xos') {
405+
$slot_port = explode(':', $remote_port_name);
406+
if (count($slot_port) == 2) {
407+
$n_slot = (int) $slot_port[0];
408+
$n_port = (int) $slot_port[1];
409+
} else {
410+
$n_slot = 1;
411+
$n_port = (int) $slot_port[0];
412+
}
413+
$remote_port_name = (string) ($n_slot * 1000 + $n_port);
413414
}
414-
$remote_port_name = (string) ($n_slot * 1000 + $n_port);
415-
}
416415

417-
if ($remote_device['os'] == 'netgear' &&
418-
$remote_device['sysDescr'] == 'GS108T' &&
419-
$lldp['lldpRemSysDesc'] == 'Smart Switch') {
420-
// Some netgear switches, as Netgear GS108Tv1 presents it's port name over snmp as
421-
// "Port 1 Gigabit Ethernet" but as 'lldpRemPortId' => 'g1' and
422-
// 'lldpRemPortDesc' => 'Port #1' over lldp.
423-
// So remap g1 to 1 so it matches ifIndex
424-
if (preg_match("/^g(\d+)$/", $lldp['lldpRemPortId'], $matches)) {
425-
$remote_port_name = $matches[1];
416+
if ($remote_device['os'] == 'netgear' &&
417+
$remote_device['sysDescr'] == 'GS108T' &&
418+
$lldp['lldpRemSysDesc'] == 'Smart Switch') {
419+
// Some netgear switches, as Netgear GS108Tv1 presents it's port name over snmp as
420+
// "Port 1 Gigabit Ethernet" but as 'lldpRemPortId' => 'g1' and
421+
// 'lldpRemPortDesc' => 'Port #1' over lldp.
422+
// So remap g1 to 1 so it matches ifIndex
423+
if (preg_match("/^g(\d+)$/", $lldp['lldpRemPortId'], $matches)) {
424+
$remote_port_name = $matches[1];
425+
}
426426
}
427427
}
428428

0 commit comments

Comments
 (0)