mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
fix: issues with recent discovery refactor (#7437)
fix find_port_id() deleting all variables when device_id was given improve find_port_id() to find ports where only a number is given fix orphan deletion count fix insert and update of links with strings where int are required
This commit is contained in:
@@ -235,7 +235,8 @@ foreach (dbFetchRows($sql, array($device['device_id'])) as $test) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove orphaned links
|
// remove orphaned links
|
||||||
$deleted = dbQuery('DELETE `l` FROM `links` `l` LEFT JOIN `devices` `d` ON `d`.`device_id` = `l`.`local_device_id` WHERE `d`.`device_id` IS NULL');
|
$del_result = dbQuery('DELETE `l` FROM `links` `l` LEFT JOIN `devices` `d` ON `d`.`device_id` = `l`.`local_device_id` WHERE `d`.`device_id` IS NULL');
|
||||||
|
$deleted = mysqli_affected_rows($del_result);
|
||||||
echo str_repeat('-', $deleted);
|
echo str_repeat('-', $deleted);
|
||||||
d_echo(" $deleted orphaned links deleted\n");
|
d_echo(" $deleted orphaned links deleted\n");
|
||||||
|
|
||||||
@@ -244,5 +245,7 @@ unset(
|
|||||||
$sql,
|
$sql,
|
||||||
$fdp_array,
|
$fdp_array,
|
||||||
$cdp_array,
|
$cdp_array,
|
||||||
$lldp_array
|
$lldp_array,
|
||||||
|
$del_result,
|
||||||
|
$deleted
|
||||||
);
|
);
|
||||||
|
@@ -513,7 +513,7 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
|
|||||||
{
|
{
|
||||||
global $link_exists;
|
global $link_exists;
|
||||||
|
|
||||||
d_echo("Discover link: $local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version\n");
|
d_echo("Discover link: $local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version, $remote_device_id\n");
|
||||||
|
|
||||||
if (dbFetchCell(
|
if (dbFetchCell(
|
||||||
'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?',
|
'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?',
|
||||||
@@ -529,14 +529,14 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
|
|||||||
'local_device_id' => $local_device_id,
|
'local_device_id' => $local_device_id,
|
||||||
'protocol' => $protocol,
|
'protocol' => $protocol,
|
||||||
'remote_hostname' => $remote_hostname,
|
'remote_hostname' => $remote_hostname,
|
||||||
'remote_device_id' => $remote_device_id,
|
'remote_device_id' => (int)$remote_device_id,
|
||||||
'remote_port' => $remote_port,
|
'remote_port' => $remote_port,
|
||||||
'remote_platform' => $remote_platform,
|
'remote_platform' => $remote_platform,
|
||||||
'remote_version' => $remote_version,
|
'remote_version' => $remote_version,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($remote_port_id)) {
|
if (!empty($remote_port_id)) {
|
||||||
$insert_data['remote_port_id'] = $remote_port_id;
|
$insert_data['remote_port_id'] = (int)$remote_port_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$inserted = dbInsert($insert_data, 'links');
|
$inserted = dbInsert($insert_data, 'links');
|
||||||
@@ -552,8 +552,8 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
|
|||||||
'local_device_id' => $local_device_id,
|
'local_device_id' => $local_device_id,
|
||||||
'remote_platform' => $remote_platform,
|
'remote_platform' => $remote_platform,
|
||||||
'remote_version' => $remote_version,
|
'remote_version' => $remote_version,
|
||||||
'remote_device_id' => $remote_device_id,
|
'remote_device_id' => (int)$remote_device_id,
|
||||||
'remote_port_id' => $remote_port_id
|
'remote_port_id' => (int)$remote_port_id
|
||||||
);
|
);
|
||||||
|
|
||||||
$id = $data['id'];
|
$id = $data['id'];
|
||||||
@@ -1424,11 +1424,21 @@ function find_device_id($name = '', $ip = '', $mac_address = '')
|
|||||||
*/
|
*/
|
||||||
function find_port_id($description, $identifier = '', $device_id = 0, $mac_address = null)
|
function find_port_id($description, $identifier = '', $device_id = 0, $mac_address = null)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT `port_id` FROM `ports` WHERE (`ifDescr`=? OR `ifName`=?';
|
$sql = 'SELECT `port_id` FROM `ports` WHERE (0';
|
||||||
$params = array($description, $description);
|
$params = array();
|
||||||
|
|
||||||
|
if ($description) {
|
||||||
|
$sql .= ' OR `ifDescr`=? OR `ifName`=?';
|
||||||
|
$params[] = $description;
|
||||||
|
$params[] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
if ($identifier) {
|
if ($identifier) {
|
||||||
$sql .= ' OR `ifDescr`=? OR `ifName`=?';
|
if (is_numeric($identifier)) {
|
||||||
|
$sql .= ' OR `ifAlias`=? OR `ifIndex`=?';
|
||||||
|
} else {
|
||||||
|
$sql .= ' OR `ifDescr`=? OR `ifName`=?';
|
||||||
|
}
|
||||||
$params[] = $identifier;
|
$params[] = $identifier;
|
||||||
$params[] = $identifier;
|
$params[] = $identifier;
|
||||||
}
|
}
|
||||||
@@ -1442,7 +1452,7 @@ function find_port_id($description, $identifier = '', $device_id = 0, $mac_addre
|
|||||||
|
|
||||||
if ($device_id) {
|
if ($device_id) {
|
||||||
$sql .= ' AND `device_id`=?';
|
$sql .= ' AND `device_id`=?';
|
||||||
$params = $device_id;
|
$params[] = $device_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)dbFetchCell($sql, $params);
|
return (int)dbFetchCell($sql, $params);
|
||||||
|
Reference in New Issue
Block a user