Add terminal-style scan log panel
scan_state now accumulates log_lines per switch result. The status bar is replaced with a dark terminal panel showing a summary header [done/total ✓ok ✗fail | now: hostname] and a scrolling per-switch log with green/red colouring and timestamps. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+15
-3
@@ -21,6 +21,7 @@ scan_state = {
|
||||
"ok": 0,
|
||||
"fail": 0,
|
||||
"errors": [],
|
||||
"log_lines": [],
|
||||
"last_scan": None,
|
||||
"dept_filter": None, # None = all, "ELEC" or "GW" = dept-only
|
||||
}
|
||||
@@ -56,6 +57,7 @@ def run_scan(dept: str = None, workers: int = 5, login_delay: int = 3):
|
||||
"ok": 0,
|
||||
"fail": 0,
|
||||
"errors": [],
|
||||
"log_lines": [],
|
||||
"dept_filter": dept,
|
||||
})
|
||||
|
||||
@@ -63,6 +65,8 @@ def run_scan(dept: str = None, workers: int = 5, login_delay: int = 3):
|
||||
clear_links() # Fresh start for links each scan
|
||||
|
||||
def on_progress(done, total, ip, result):
|
||||
from datetime import datetime
|
||||
ts = datetime.now().strftime("%H:%M:%S")
|
||||
scan_state["done"] = done
|
||||
scan_state["total"] = total
|
||||
scan_state["current_ip"] = ip
|
||||
@@ -70,6 +74,12 @@ def run_scan(dept: str = None, workers: int = 5, login_delay: int = 3):
|
||||
if result["success"]:
|
||||
scan_state["ok"] += 1
|
||||
scan_state["current_hostname"] = result.get("hostname", ip)
|
||||
vendor = result.get("vendor", "")
|
||||
n = len(result.get("neighbors", []))
|
||||
scan_state["log_lines"].append({
|
||||
"ts": ts, "ok": True,
|
||||
"text": f"✓ {result['hostname']} ({ip}) [{vendor}] — {n} neighbor{'s' if n != 1 else ''}",
|
||||
})
|
||||
|
||||
upsert_switch(
|
||||
chassis_id=result["chassis_id"],
|
||||
@@ -100,9 +110,11 @@ def run_scan(dept: str = None, workers: int = 5, login_delay: int = 3):
|
||||
)
|
||||
else:
|
||||
scan_state["fail"] += 1
|
||||
scan_state["errors"].append({
|
||||
"ip": ip,
|
||||
"error": result.get("error", "Unknown error")
|
||||
error = result.get("error", "Unknown error")
|
||||
scan_state["errors"].append({"ip": ip, "error": error})
|
||||
scan_state["log_lines"].append({
|
||||
"ts": ts, "ok": False,
|
||||
"text": f"✗ {ip} — {error}",
|
||||
})
|
||||
|
||||
scan_all_switches(switches, progress_callback=on_progress, max_workers=workers, login_delay=login_delay)
|
||||
|
||||
Reference in New Issue
Block a user