fix: re-scan updates services on existing pending devices instead of skipping

This commit is contained in:
Pouzor
2026-03-07 23:09:54 +01:00
parent d98bfba506
commit 6e6041d871
+10 -5
View File
@@ -115,16 +115,21 @@ async def run_scan(ranges: list[str], db: AsyncSession, run_id: str) -> None:
services = fingerprint_ports(host["open_ports"])
suggested_type = suggest_node_type(host["open_ports"])
# Skip if already pending (by IP)
existing = await db.execute(
# Update existing pending device or create a new one
existing_result = await db.execute(
select(PendingDevice).where(
PendingDevice.ip == host["ip"],
PendingDevice.status == "pending",
)
)
if existing.scalar_one_or_none():
continue
existing = existing_result.scalar_one_or_none()
if existing:
existing.mac = host.get("mac") or existing.mac
existing.hostname = host.get("hostname") or existing.hostname
existing.os = host.get("os") or existing.os
existing.services = services
existing.suggested_type = suggested_type
else:
device = PendingDevice(
ip=host["ip"],
mac=host.get("mac"),