feat: Phase 3 & 4 — monitoring, discovery, polish, deployment

Phase 3 — Discovery & Monitoring:
- Network scanner: nmap wrapper + mock fallback, fingerprint service (35 signatures)
- Status checker: ping/http/https/tcp/ssh/prometheus/health per-node checks
- APScheduler: status checks every 60s, WebSocket broadcast
- WebSocket /ws/status: live node status updates to frontend
- Sidebar panels: Pending Devices, Hidden Devices, Scan History
- Auth token persisted to localStorage (survive page refresh)
- 24 new backend tests (scan flow + status_checker)

Phase 4 — Polish & Deployment:
- Auto-layout: Dagre hierarchical TB via Toolbar button
- Export PNG: html-to-image download via Toolbar button
- Scan config modal: CIDR ranges + check interval, GET/POST /api/v1/scan/config
- Dockerfile.backend (Python 3.13 slim + nmap), Dockerfile.frontend (nginx)
- docker-compose.yml with data volume and NET_RAW cap for ping
- scripts/lxc-install.sh: Proxmox VE systemd bootstrap
- README.md: quick-start, config reference, stack overview
This commit is contained in:
Pouzor
2026-03-07 00:45:50 +01:00
parent 44a448e26d
commit 0bd714a68b
26 changed files with 1778 additions and 25 deletions
+66
View File
@@ -0,0 +1,66 @@
"""APScheduler setup for background scan and status check jobs."""
import logging
from datetime import UTC, datetime
import yaml
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from sqlalchemy import select
from app.core.config import settings
from app.db.database import AsyncSessionLocal
from app.db.models import Node
from app.services.status_checker import check_node
logger = logging.getLogger(__name__)
scheduler = AsyncIOScheduler()
async def _run_status_checks() -> None:
"""Check all nodes and broadcast results via WebSocket."""
from app.api.routes.status import broadcast_status # avoid circular import
async with AsyncSessionLocal() as db:
result = await db.execute(select(Node))
nodes = result.scalars().all()
for node in nodes:
if not node.check_method:
continue
try:
result = await check_node(node.check_method, node.check_target, node.ip)
async with AsyncSessionLocal() as db:
n = await db.get(Node, node.id)
if n:
n.status = result["status"]
n.response_time_ms = result["response_time_ms"]
n.last_seen = datetime.now(UTC) if result["status"] == "online" else n.last_seen
await db.commit()
await broadcast_status(
node_id=node.id,
status=result["status"],
checked_at=datetime.now(UTC).isoformat(),
response_time_ms=result["response_time_ms"],
)
except Exception as exc:
logger.error("Status check failed for node %s: %s", node.id, exc)
def _load_interval() -> int:
try:
with open(settings.config_path) as f:
cfg = yaml.safe_load(f)
return int(cfg.get("status_checker", {}).get("interval_seconds", 60))
except Exception:
return 60
def start_scheduler() -> None:
interval = _load_interval()
scheduler.add_job(_run_status_checks, "interval", seconds=interval, id="status_checks")
scheduler.start()
logger.info("Scheduler started — status checks every %ds", interval)
def stop_scheduler() -> None:
scheduler.shutdown(wait=False)