Add single-switch scan

New "Scan Switch" header button reuses the Test Connection picker and
posts to /api/scan/switch, which runs the normal scan pipeline on one
switch from the NocoDB inventory. Like a dept scan it does not clear
links first, so the rest of the map is left in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dcstephenson
2026-10-01 15:18:01 -05:00
parent e589f76387
commit 92ded499d5
3 changed files with 70 additions and 9 deletions
+8 -4
View File
@@ -39,10 +39,12 @@ def request_abort():
return False
def run_scan(dept: str = None, workers: int = 5, login_delay: int = 3):
def run_scan(dept: str = None, workers: int = 5, login_delay: int = 3, only_ip: str = None):
"""
Full scan: fetch switch IPs from NocoDB → SSH all → parse → store → export.
dept: None = all active switches, "ELEC" or "GW" = dept-filtered.
only_ip: scan just that one switch from the list; like a dept scan, it
leaves every other switch's links in place.
"""
global scan_state
@@ -54,6 +56,8 @@ def run_scan(dept: str = None, workers: int = 5, login_delay: int = 3):
# Fetch switch list from NocoDB (or fallback)
switches = get_switches(dept=dept)
if only_ip:
switches = [s for s in switches if s["ip"] == only_ip]
if not switches:
logger.error("NocoDB returned no switches — aborting scan.")
@@ -72,13 +76,13 @@ def run_scan(dept: str = None, workers: int = 5, login_delay: int = 3):
"fail": 0,
"errors": [],
"log_lines": [],
"dept_filter": dept,
"dept_filter": dept or only_ip,
"aborted": False,
})
scan_id = log_scan_start()
if dept is None:
clear_links() # Full scan only — dept scans upsert without wiping other depts
if dept is None and only_ip is None:
clear_links() # Full scan only — dept/single-switch scans upsert without wiping the rest
def on_progress(done, total, ip, result):
from datetime import datetime