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:
Tony Murray
2017-10-06 08:53:16 -05:00
committed by GitHub
parent a2b9342f05
commit f92449e637
2 changed files with 24 additions and 11 deletions

View File

@@ -513,7 +513,7 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
{
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(
'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,
'protocol' => $protocol,
'remote_hostname' => $remote_hostname,
'remote_device_id' => $remote_device_id,
'remote_device_id' => (int)$remote_device_id,
'remote_port' => $remote_port,
'remote_platform' => $remote_platform,
'remote_version' => $remote_version,
);
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');
@@ -552,8 +552,8 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
'local_device_id' => $local_device_id,
'remote_platform' => $remote_platform,
'remote_version' => $remote_version,
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id
'remote_device_id' => (int)$remote_device_id,
'remote_port_id' => (int)$remote_port_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)
{
$sql = 'SELECT `port_id` FROM `ports` WHERE (`ifDescr`=? OR `ifName`=?';
$params = array($description, $description);
$sql = 'SELECT `port_id` FROM `ports` WHERE (0';
$params = array();
if ($description) {
$sql .= ' OR `ifDescr`=? OR `ifName`=?';
$params[] = $description;
$params[] = $description;
}
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;
}
@@ -1442,7 +1452,7 @@ function find_port_id($description, $identifier = '', $device_id = 0, $mac_addre
if ($device_id) {
$sql .= ' AND `device_id`=?';
$params = $device_id;
$params[] = $device_id;
}
return (int)dbFetchCell($sql, $params);