autodiscovery fix (#14213)

* autodiscovery fix

* much simpler approach

* murrant suggestion

* Simplify even more

* Use nullable operator

Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
Peca Nesovanovic
2022-08-19 03:30:57 +02:00
committed by GitHub
parent 73fee2a1aa
commit 59fc562d99
2 changed files with 6 additions and 9 deletions

View File

@@ -76,18 +76,14 @@ function discover_new_device($hostname, $device = [], $method = '', $interface =
}
try {
$remote_device_id = addHost($hostname, '', '161', 'udp', Config::get('default_poller_group'));
$remote_device_id = addHost($hostname, '', '161', 'udp', $device['poller_group']); // discover with actual poller group
$remote_device = device_by_id_cache($remote_device_id, 1);
echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]';
discover_device($remote_device);
device_by_id_cache($remote_device_id, 1);
if ($remote_device_id && is_array($device) && ! empty($method)) {
$extra_log = '';
$int = cleanPort($interface);
if (is_array($int)) {
$extra_log = ' (port ' . $int['label'] . ') ';
}
$extra_log = is_array($interface) ? ' (port ' . cleanPort($interface)['label'] . ') ' : '';
log_event('Device ' . $remote_device['hostname'] . " ($ip) $extra_log autodiscovered through $method on " . $device['hostname'], $remote_device_id, 'discovery', 1);
} else {

View File

@@ -41,9 +41,10 @@ function cleanPort($interface, $device = null)
if (! $interface) {
return $interface;
}
$interface['ifAlias'] = htmlentities($interface['ifAlias']);
$interface['ifName'] = htmlentities($interface['ifName']);
$interface['ifDescr'] = htmlentities($interface['ifDescr']);
$interface['ifAlias'] = htmlentities($interface['ifAlias'] ?? '');
$interface['ifName'] = htmlentities($interface['ifName'] ?? '');
$interface['ifDescr'] = htmlentities($interface['ifDescr'] ?? '');
if (! $device) {
$device = device_by_id_cache($interface['device_id']);