Skip to content

Commit

Permalink
Improve last fix for Collector -> Server discovery. Delete discovery …
Browse files Browse the repository at this point in the history
…on Collector if type = 'collector' and discovery name contains 'Instant Discovery'.
  • Loading branch information
mark-unwin committed Mar 5, 2024
1 parent af5d05e commit aebaf0e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions app/Helpers/discoveries_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1957,14 +1957,16 @@ function ip_audit($ip_scan = null)
$device_json->network[] = $item;
}
}
foreach ($audit as $key => $value) {
if ($key !== 'system' and is_countable($value) and count($value) > 0) {
$device_json->{$key} = $value;
if (!empty($audit)) {
foreach ($audit as $key => $value) {
if ($key !== 'system' and is_countable($value) and count($value) > 0) {
$device_json->{$key} = $value;
}
}
}
foreach ($audit->system as $key => $value) {
if ($key !== 'id' and !empty($value)) {
$device_json->system->{$key} = $value;
foreach ($audit->system as $key => $value) {
if ($key !== 'id' and !empty($value)) {
$device_json->system->{$key} = $value;
}
}
}
unset($device_json->system->original_last_seen_by);
Expand Down Expand Up @@ -2147,7 +2149,7 @@ function discovery_check_finished(int $id)
$result = $query->getResult();
if (!empty($result[0]->count)) {
$count = intval($result[0]->count);
$sql = 'SELECT `ip_responding_count`, `status` FROM `discoveries` WHERE `id` = ?';
$sql = 'SELECT `name`, `ip_responding_count`, `status` FROM `discoveries` WHERE `id` = ?';
$result = $db->query($sql, [$id])->getResult();
$device_count = intval($result[0]->ip_responding_count);
$status = $result[0]->status;
Expand All @@ -2161,6 +2163,13 @@ function discovery_check_finished(int $id)
$log->ip = '127.0.0.1';
unset($log->device_id);
$discoveryLogModel->create($log);
// If we are a collector and the discovery is an instant - delete it locally
$instance = & get_instance();
if (!empty($instance->config->cervers) and $instance->config->servers->type === 'collector' and strpos($result[0]->name, 'Instant Discovery') !== false) {
$sql = "DELETE FROM `discoveries` WHERE `id` = ?";
$db->query($sql, [$id]);
log_message('info', 'Deleting discovery named: ' . $result[0]->name);
}
}
}
} else {
Expand Down

0 comments on commit aebaf0e

Please sign in to comment.