Modifies find_device_id (#11804)

* modifies find_device_id

* Removed host name validation check for RFC. Some devices and OS allow you
  to set a name that contains characters that are prohibited by the RFC.
  Such devices can be added using their IP address, their sysName will be
  written to the database. If the device is already in the database, then it
  should be possible to find it, even if the name is unacceptable according
  to RFC requirements.
* Additional search options for sysName have been added using the default
  domain. This was needed to improve LLDP detection - a short name was used in
  the PDU, and the full name with the domain was stored in the sysName field
  in the database.

* modifies find_device_id

* reordering checks
* handling situations with duplicate sysName

* modifies find_device_id (fix style errors)
This commit is contained in:
seros1521
2020-07-04 22:23:11 -05:00
committed by GitHub
parent ad6348af42
commit ddab4153bc
+26 -3
View File
@@ -1364,9 +1364,6 @@ function find_device_id($name = '', $ip = '', $mac_address = '')
$params = array();
if ($name && is_valid_hostname($name)) {
$where[] = '`sysName`=?';
$params[] = $name;
$where[] = '`hostname`=?';
$params[] = $name;
@@ -1405,6 +1402,32 @@ function find_device_id($name = '', $ip = '', $mac_address = '')
}
}
if ($name) {
$where = array();
$params = array();
$where[] = '`sysName`=?';
$params[] = $name;
if ($mydomain = Config::get('mydomain')) {
$where[] = '`sysName`=?';
$params[] = "$name.$mydomain";
$where[] = 'concat(`sysName`, \'.\', ?) =?';
$params[] = "$mydomain";
$params[] = "$name";
}
$sql = 'SELECT `device_id` FROM `devices` WHERE ' . implode(' OR ', $where) . ' LIMIT 2';
$ids = dbFetchColumn($sql, $params);
if (count($ids) == 1) {
return (int)$ids[0];
} elseif (count($ids) > 1) {
d_echo("find_device_id: more than one device found with sysName '$name'.\n");
// don't do anything, try other methods, if any
}
}
return 0;
}