feature: Scan progress and timing features

This commit is contained in:
Keith Solomon
2026-03-08 15:40:11 -05:00
parent 12b23b43d8
commit 5a35a7158b
5 changed files with 207 additions and 15 deletions

View File

@@ -37,10 +37,12 @@ def home() -> FileResponse:
@app.get("/api/health")
def health() -> dict[str, Any]:
progress = scan_state.snapshot()
return {
"status": "ok",
"scan_running": scan_state.running,
"current_scan_id": scan_state.current_scan_id,
"scan_running": progress["running"],
"current_scan_id": progress["scan_id"],
"scan_progress": progress,
}
@@ -66,7 +68,7 @@ def api_scans(limit: int = 20) -> list[dict]:
def run_scan(subnet: str | None = None) -> dict[str, Any]:
subnet = subnet or DEFAULT_SUBNET
scan_id = create_scan(subnet)
if not scan_state.start(scan_id):
if not scan_state.start(scan_id, subnet):
complete_scan(scan_id, "cancelled", 0, notes="Another scan was already running")
raise HTTPException(status_code=409, detail="Scan already running")
@@ -74,9 +76,13 @@ def run_scan(subnet: str | None = None) -> dict[str, Any]:
host_count = 0
try:
discovered = discover_hosts(subnet)
for host in discovered:
scan_state.set_total_hosts(len(discovered))
for idx, host in enumerate(discovered, start=1):
scan_state.set_current_host(host["ip"])
detailed = scan_host(host["ip"])
if not detailed:
scan_state.update_progress(idx, host_count)
continue
host_count += 1
if not detailed.hostname and host.get("hostname"):
@@ -87,6 +93,7 @@ def run_scan(subnet: str | None = None) -> dict[str, Any]:
detailed.vendor = host["vendor"]
upsert_host(scan_id, detailed)
scan_state.update_progress(idx, host_count)
mark_missing_devices(scan_id)
complete_scan(scan_id, "completed", host_count)