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:
@@ -37,11 +37,12 @@ def _reschedule(interval_minutes):
|
||||
logger.info(f"Auto-scan scheduled every {interval_minutes} minutes")
|
||||
|
||||
|
||||
def _trigger_scan_background(dept: str = None, workers: int = 5, login_delay: int = 3):
|
||||
def _trigger_scan_background(dept: str = None, workers: int = 5, login_delay: int = 3, only_ip: str = None):
|
||||
"""Run scan in a background thread. dept=None → all switches."""
|
||||
if not scanner.scan_state["running"]:
|
||||
t = threading.Thread(target=scanner.run_scan,
|
||||
kwargs={"dept": dept, "workers": workers, "login_delay": login_delay},
|
||||
kwargs={"dept": dept, "workers": workers, "login_delay": login_delay,
|
||||
"only_ip": only_ip},
|
||||
daemon=True)
|
||||
t.start()
|
||||
|
||||
@@ -132,6 +133,25 @@ def api_scan_ami():
|
||||
return jsonify({"status": "started", "dept": "AMI"})
|
||||
|
||||
|
||||
@app.route("/api/scan/switch", methods=["POST"])
|
||||
def api_scan_switch():
|
||||
"""Scan a single switch (by IP, must be in the NocoDB inventory)."""
|
||||
if scanner.scan_state["running"]:
|
||||
return jsonify({"error": "Scan already running"}), 409
|
||||
ip = ((request.get_json(silent=True) or {}).get("ip") or "").strip()
|
||||
if not ip:
|
||||
return jsonify({"error": "ip is required"}), 400
|
||||
try:
|
||||
known = any(s["ip"] == ip for s in get_switches())
|
||||
except RuntimeError as e:
|
||||
return jsonify({"error": str(e)}), 502
|
||||
if not known:
|
||||
return jsonify({"error": f"{ip} is not an active switch in NocoDB"}), 404
|
||||
workers, login_delay = _scan_params()
|
||||
_trigger_scan_background(workers=workers, login_delay=login_delay, only_ip=ip)
|
||||
return jsonify({"status": "started", "ip": ip})
|
||||
|
||||
|
||||
@app.route("/api/scan/abort", methods=["POST"])
|
||||
def api_scan_abort():
|
||||
"""Request the in-progress scan to stop after in-flight switches finish."""
|
||||
|
||||
Reference in New Issue
Block a user