refactor: extract _annotate_suppressions helper, remove orphaned CSS
Lint / Python (flake8) (push) Successful in 45s
Lint / JS (eslint) (push) Successful in 8s
Security / Python Security (bandit) (push) Successful in 1m0s
Test / Python Tests (pytest) (push) Successful in 57s
Lint / Notify on failure (push) Has been skipped
Lint / Deploy (push) Successful in 2s
Lint / Python (flake8) (push) Successful in 45s
Lint / JS (eslint) (push) Successful in 8s
Security / Python Security (bandit) (push) Successful in 1m0s
Test / Python Tests (pytest) (push) Successful in 57s
Lint / Notify on failure (push) Has been skipped
Lint / Deploy (push) Successful in 2s
- Extract identical suppression-annotation loop from index() and api_status() into _annotate_suppressions() helper to eliminate DRY violation - Improve stuck-job error message: 'thread crash' → 'no activity for 5 minutes' (less alarming, more accurate) - Remove orphaned .events-filter-bar CSS class (never referenced in any template or JS file) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -73,8 +73,8 @@ def _purge_old_jobs_loop():
|
|||||||
for jid, j in list(_diag_jobs.items()):
|
for jid, j in list(_diag_jobs.items()):
|
||||||
if j['status'] == 'running' and j.get('created_at', 0) < stuck_cutoff:
|
if j['status'] == 'running' and j.get('created_at', 0) < stuck_cutoff:
|
||||||
j['status'] = 'done'
|
j['status'] = 'done'
|
||||||
j['result'] = {'status': 'error', 'error': 'Diagnostic timed out (thread crash)'}
|
j['result'] = {'status': 'error', 'error': 'Diagnostic abandoned — no activity for 5 minutes.'}
|
||||||
logger.error(f'Diagnostic job {jid} appeared stuck; marked as errored')
|
logger.error(f'Diagnostic job {jid} stuck (no activity for 5 min); marked done/error')
|
||||||
|
|
||||||
|
|
||||||
_purge_thread = threading.Thread(target=_purge_old_jobs_loop, daemon=True)
|
_purge_thread = threading.Thread(target=_purge_old_jobs_loop, daemon=True)
|
||||||
@@ -143,12 +143,31 @@ def require_auth(f):
|
|||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Page routes
|
# Helpers
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
_PAGE_LIMIT = 200 # max events returned per request
|
_PAGE_LIMIT = 200 # max events returned per request
|
||||||
|
|
||||||
|
|
||||||
|
def _annotate_suppressions(events: list, suppressions: list) -> None:
|
||||||
|
"""Annotate each event dict in-place with an is_suppressed bool."""
|
||||||
|
for ev in events:
|
||||||
|
sup_type = (
|
||||||
|
'unifi_device' if ev.get('event_type') == 'unifi_device_offline'
|
||||||
|
else 'interface' if ev.get('event_type') == 'interface_down'
|
||||||
|
else 'host'
|
||||||
|
)
|
||||||
|
ev['is_suppressed'] = db.check_suppressed(
|
||||||
|
suppressions, sup_type,
|
||||||
|
ev.get('target_name', ''), ev.get('target_detail', '') or '',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Page routes
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@require_auth
|
@require_auth
|
||||||
def index():
|
def index():
|
||||||
@@ -160,16 +179,7 @@ def index():
|
|||||||
last_check = db.get_state('last_check', 'Never')
|
last_check = db.get_state('last_check', 'Never')
|
||||||
snapshot = json.loads(snapshot_raw) if snapshot_raw else {}
|
snapshot = json.loads(snapshot_raw) if snapshot_raw else {}
|
||||||
suppressions = db.get_active_suppressions()
|
suppressions = db.get_active_suppressions()
|
||||||
for ev in events:
|
_annotate_suppressions(events, suppressions)
|
||||||
sup_type = (
|
|
||||||
'unifi_device' if ev.get('event_type') == 'unifi_device_offline'
|
|
||||||
else 'interface' if ev.get('event_type') == 'interface_down'
|
|
||||||
else 'host'
|
|
||||||
)
|
|
||||||
ev['is_suppressed'] = db.check_suppressed(
|
|
||||||
suppressions, sup_type,
|
|
||||||
ev.get('target_name', ''), ev.get('target_detail', '') or '',
|
|
||||||
)
|
|
||||||
recent_resolved = db.get_recent_resolved(hours=24, limit=10)
|
recent_resolved = db.get_recent_resolved(hours=24, limit=10)
|
||||||
return render_template(
|
return render_template(
|
||||||
'index.html',
|
'index.html',
|
||||||
@@ -225,16 +235,7 @@ def suppressions_page():
|
|||||||
def api_status():
|
def api_status():
|
||||||
active = db.get_active_events(limit=_PAGE_LIMIT)
|
active = db.get_active_events(limit=_PAGE_LIMIT)
|
||||||
suppressions = db.get_active_suppressions()
|
suppressions = db.get_active_suppressions()
|
||||||
for ev in active:
|
_annotate_suppressions(active, suppressions)
|
||||||
sup_type = (
|
|
||||||
'unifi_device' if ev.get('event_type') == 'unifi_device_offline'
|
|
||||||
else 'interface' if ev.get('event_type') == 'interface_down'
|
|
||||||
else 'host'
|
|
||||||
)
|
|
||||||
ev['is_suppressed'] = db.check_suppressed(
|
|
||||||
suppressions, sup_type,
|
|
||||||
ev.get('target_name', ''), ev.get('target_detail', '') or '',
|
|
||||||
)
|
|
||||||
last_check = db.get_state('last_check', 'Never')
|
last_check = db.get_state('last_check', 'Never')
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'summary': db.get_status_summary(),
|
'summary': db.get_status_summary(),
|
||||||
|
|||||||
@@ -214,8 +214,6 @@
|
|||||||
padding: 1px 7px;
|
padding: 1px 7px;
|
||||||
}
|
}
|
||||||
.g-section-actions { margin-left: auto; }
|
.g-section-actions { margin-left: auto; }
|
||||||
.events-filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
||||||
.events-filter-bar .lt-input-sm { width: 220px; }
|
|
||||||
.sev-pills { display: flex; gap: 4px; }
|
.sev-pills { display: flex; gap: 4px; }
|
||||||
.g-page-sub { font-size: .78em; color: var(--text-muted); margin-top: 4px; }
|
.g-page-sub { font-size: .78em; color: var(--text-muted); margin-top: 4px; }
|
||||||
.g-page-sub-aside { font-size: .78em; color: var(--text-muted); margin-left: 8px; }
|
.g-page-sub-aside { font-size: .78em; color: var(--text-muted); margin-left: 8px; }
|
||||||
|
|||||||
Reference in New Issue
Block a user