From 29e708819ae672c65964c17e7c811d343c587df7 Mon Sep 17 00:00:00 2001 From: vitalisator Date: Sun, 13 Dec 2015 20:15:43 +0100 Subject: [PATCH 1/3] closes #2614 --- .../discovery/discovery-protocols.inc.php | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index 93a130878..a27b48286 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -143,12 +143,24 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { if (!$remote_device_id && is_valid_hostname($lldp['lldpRemSysName'])) { $remote_device_id = discover_new_device($lldp['lldpRemSysName'], $device, 'LLDP', $interface); } - + // normalize MAC address if present + if ($lldp['lldpRemChassisIdSubtype'] == 'macAddress') { + $remote_mac_address = str_replace(array(' ', ':', '-'), '', strtolower($lldp['lldpRemChassisId'])); + } + // get remote device hostname from db by MAC address and replace lldpRemSysName if absent + if (!$remote_device_id && $remote_mac_address) { + $remote_device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE ifPhysAddress = ? AND `deleted` = ?', array($remote_mac_address, '0')); + if ($remote_device_id) { + $remote_device_hostname = dbFetchRow('SELECT hostname FROM devices WHERE device_id = ?', $remote_device_id); + } + if ($remote_device_hostname['hostname']) { + $lldp['lldpRemSysName'] = $remote_device_hostname['hostname']; + } + } if ($remote_device_id) { $if = $lldp['lldpRemPortDesc']; $id = $lldp['lldpRemPortId']; - $PhysAddress = preg_replace('/ /', '', $id); - $remote_port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ? OR `ifPhysAddress` = ?) AND `device_id` = ?', array($if, $if, $id, $id, $PhysAddress, $remote_device_id)); + $remote_port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ? OR `ifPhysAddress` = ?) AND `device_id` = ?', array($if, $if, $id, $id, $remote_mac_address, $remote_device_id)); } else { $remote_port_id = '0'; @@ -163,7 +175,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { }//end if }//end elseif -echo 'OSPF Discovery: '; +echo ' OSPF Discovery: '; if ($config['autodiscovery']['ospf'] === true) { echo "enabled\n"; From 7237c84164b7292f2c161db9c49210545bbfb759 Mon Sep 17 00:00:00 2001 From: vitalisator Date: Sun, 13 Dec 2015 20:24:08 +0100 Subject: [PATCH 2/3] change fetchRow to fetchCell --- includes/discovery/discovery-protocols.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index a27b48286..a9a4e9a06 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -151,7 +151,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { if (!$remote_device_id && $remote_mac_address) { $remote_device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE ifPhysAddress = ? AND `deleted` = ?', array($remote_mac_address, '0')); if ($remote_device_id) { - $remote_device_hostname = dbFetchRow('SELECT hostname FROM devices WHERE device_id = ?', $remote_device_id); + $remote_device_hostname = dbFetchCell('SELECT hostname FROM devices WHERE device_id = ?', $remote_device_id); } if ($remote_device_hostname['hostname']) { $lldp['lldpRemSysName'] = $remote_device_hostname['hostname']; From 4bd3b12c446bcde93340c614a3600dbb5b5852ac Mon Sep 17 00:00:00 2001 From: vitalisator Date: Sun, 13 Dec 2015 21:00:39 +0100 Subject: [PATCH 3/3] revert to fetchRow --- includes/discovery/discovery-protocols.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index a9a4e9a06..5563da898 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -151,7 +151,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { if (!$remote_device_id && $remote_mac_address) { $remote_device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE ifPhysAddress = ? AND `deleted` = ?', array($remote_mac_address, '0')); if ($remote_device_id) { - $remote_device_hostname = dbFetchCell('SELECT hostname FROM devices WHERE device_id = ?', $remote_device_id); + $remote_device_hostname = dbFetchRow('SELECT `hostname` FROM `devices` WHERE `device_id` = ?', array($remote_device_id)); } if ($remote_device_hostname['hostname']) { $lldp['lldpRemSysName'] = $remote_device_hostname['hostname'];