Cutsheet trace mode and mismatch alerts
Lint / Python (flake8) (push) Successful in 1m8s
Security / Python Security (bandit) (push) Successful in 56s
Test / Python Tests (pytest) (push) Successful in 43s
Lint / Python (flake8) (pull_request) Successful in 50s
Lint / JS (eslint) (pull_request) Successful in 30s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 55s
Test / Python Tests (pytest) (pull_request) Successful in 50s
Lint / JS (eslint) (push) Successful in 16m17s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / Python (flake8) (push) Successful in 1m8s
Security / Python Security (bandit) (push) Successful in 56s
Test / Python Tests (pytest) (push) Successful in 43s
Lint / Python (flake8) (pull_request) Successful in 50s
Lint / JS (eslint) (pull_request) Successful in 30s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 55s
Test / Python Tests (pytest) (pull_request) Successful in 50s
Lint / JS (eslint) (push) Successful in 16m17s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Trace a cord: pick a panel port, press Start, and unplug the cord at the panel. The page polls a new admin-only endpoint that reads every switch port's state from UniFi (cached 2 s), shows the one port that dropped with a button to record the cable, and confirms when it's plugged back in. Several ports dropping at once, or none within 3 minutes, is explained rather than guessed at. Mismatch alerts: the monitor runs the cutsheet check every poll. Each mismatched installed run (wrong neighbor, no link, missing port, port conflict) keeps one cable_mismatch event on its switch, resolved when fixed, and opens a P4 ticket after cutsheet.mismatch_ticket_hours (default 24, 0 never). Suppressing the switch or port stops the ticket. Also fixes buttons with the hidden attribute still showing, which left a Delete button on the new-cable form. Closes #12 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cd602fdacf
commit
86aa29b378
11 files changed
+446
-1
No files matched your search
@@ -24,7 +24,7 @@ import cutsheet
|
||||
import db
|
||||
import devices
|
||||
import diagnose
|
||||
from monitor import PulseClient
|
||||
from monitor import PulseClient, UnifiClient
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
@@ -1014,6 +1014,37 @@ def api_cutsheet_port_label(item_id: int, port: str):
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
_live_ports_cache: dict = {'at': 0.0, 'data': None, 'client': None}
|
||||
_live_ports_lock = threading.Lock()
|
||||
_LIVE_PORTS_TTL = 2.0
|
||||
|
||||
|
||||
@app.route('/api/cutsheet/live-ports')
|
||||
@require_auth
|
||||
@require_admin
|
||||
def api_cutsheet_live_ports():
|
||||
"""Current up/down state of every switch port, read from UniFi now.
|
||||
|
||||
Trace mode polls this while someone unplugs a cord, to see which port dropped.
|
||||
The monitor's cached state is minutes old, so it can't be used for this.
|
||||
"""
|
||||
with _live_ports_lock:
|
||||
now = time.time()
|
||||
if _live_ports_cache['data'] is None or now - _live_ports_cache['at'] > _LIVE_PORTS_TTL:
|
||||
if _live_ports_cache['client'] is None:
|
||||
_live_ports_cache['client'] = UnifiClient(_config()['unifi'])
|
||||
raw = _live_ports_cache['client'].get_switch_ports()
|
||||
if raw is None:
|
||||
return jsonify({'error': 'The UniFi controller did not answer'}), 502
|
||||
_live_ports_cache['data'] = {
|
||||
sw: {str(p['port_idx']): {'up': bool(p.get('up')), 'name': name}
|
||||
for name, p in (d.get('ports') or {}).items() if p.get('port_idx') is not None}
|
||||
for sw, d in raw.items()
|
||||
}
|
||||
_live_ports_cache['at'] = now
|
||||
return jsonify({'switches': _live_ports_cache['data'], 'at': _live_ports_cache['at']})
|
||||
|
||||
|
||||
@app.route('/api/cutsheet/cables.csv')
|
||||
@require_auth
|
||||
def api_cutsheet_export():
|
||||
|
||||
Reference in new issue
Block a user