65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domovoy\Services\Inventory;
|
|
|
|
use Domovoy\Models\DiscoveredHost;
|
|
use Domovoy\Repositories\DeviceRepository;
|
|
|
|
class MergeSuggestionService
|
|
{
|
|
private DeviceRepository $deviceRepository;
|
|
|
|
public function __construct(DeviceRepository $deviceRepository)
|
|
{
|
|
$this->deviceRepository = $deviceRepository;
|
|
}
|
|
|
|
/**
|
|
* Find merge suggestions for a discovered host.
|
|
* Returns array of ['device' => Device, 'confidence' => int, 'reason' => string]
|
|
*/
|
|
public function findSuggestions(DiscoveredHost $host): array
|
|
{
|
|
$suggestions = [];
|
|
|
|
// High confidence: MAC address match
|
|
if ($host->macAddress !== null) {
|
|
$device = $this->deviceRepository->findByMac($host->macAddress);
|
|
if ($device !== null) {
|
|
$suggestions[] = [
|
|
'device' => $device,
|
|
'confidence' => 90,
|
|
'reason' => 'MAC адрес совпадает',
|
|
];
|
|
}
|
|
}
|
|
|
|
// Medium confidence: hostname match
|
|
if ($host->hostname !== null) {
|
|
$device = $this->deviceRepository->findByName($host->hostname);
|
|
if ($device !== null) {
|
|
$suggestions[] = [
|
|
'device' => $device,
|
|
'confidence' => 60,
|
|
'reason' => 'Hostname совпадает',
|
|
];
|
|
}
|
|
}
|
|
|
|
if ($host->ipAddress !== '') {
|
|
$device = $this->deviceRepository->findByIp($host->ipAddress);
|
|
if ($device !== null) {
|
|
$suggestions[] = [
|
|
'device' => $device,
|
|
'confidence' => 40,
|
|
'reason' => 'IP адрес совпадает',
|
|
];
|
|
}
|
|
}
|
|
|
|
return $suggestions;
|
|
}
|
|
}
|