Add AT&T modem monitoring and device pages; replace Link Debug
Lint / Python (flake8) (pull_request) Successful in 2m6s
Lint / JS (eslint) (pull_request) Successful in 18s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 2m11s
Test / Python Tests (pytest) (pull_request) Successful in 2m20s
Lint / JS (eslint) (push) Successful in 10s
Lint / Python (flake8) (push) Successful in 1m58s
Lint / Notify on failure (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m58s
Lint / Deploy (push) Successful in 4s
Test / Python Tests (pytest) (push) Successful in 58s
Lint / Python (flake8) (pull_request) Successful in 2m6s
Lint / JS (eslint) (pull_request) Successful in 18s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 2m11s
Test / Python Tests (pytest) (pull_request) Successful in 2m20s
Lint / JS (eslint) (push) Successful in 10s
Lint / Python (flake8) (push) Successful in 1m58s
Lint / Notify on failure (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m58s
Lint / Deploy (push) Successful in 4s
Test / Python Tests (pytest) (push) Successful in 58s
Modem and WAN: - Poll the BGW320 status pages read-only for light levels, PON and WAN state, with a WAN / Fiber panel, 7-day Rx trend, and alerts on WAN down, optical limits, and Rx drift - Read WAN outages and Smart Power restarts from the UniFi system log, since outages can be over between 5 minute polls Device pages: - Add device search to the dashboard and a page per host, switch, router, AP, PDU, or modem - Move all Link Debug data into expandable rows there; /links redirects - Collect UDM ports and UniFi device details (firmware, load, WAN, outlets) - Reorder the dashboard Monitoring fixes: - Alert when a configured host stops reporting: its series disappear rather than reporting down, so a dead host never raised an alert - Alert on Prometheus outages instead of blanking the dashboard - Treat a failed Pulse ping as unknown rather than host unreachable - Stop new switch ports reporting lifetime bytes as one interval's rate - Run database sessions in UTC: other server time zones shifted displayed ages and timed suppression expiries Also log every avatar 404 reason, add a favicon, and correct the WAN link labels (1G on Port 9, not 10G SFP+). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #4.
This commit is contained in:
1 parent
e1716d5228
commit
e32499b7f6
25 files changed
+3120
-821
No files matched your search
@@ -18,9 +18,10 @@ import uuid
|
||||
from datetime import datetime, timezone
|
||||
from functools import wraps
|
||||
|
||||
from flask import Flask, jsonify, make_response, render_template, request, send_file
|
||||
from flask import Flask, jsonify, make_response, redirect, render_template, request, send_file, url_for
|
||||
|
||||
import db
|
||||
import devices
|
||||
import diagnose
|
||||
from monitor import PulseClient
|
||||
|
||||
@@ -196,6 +197,18 @@ def _annotate_suppressions(events: list, suppressions: list) -> None:
|
||||
ev['is_suppressed'] = db.check_suppressed(suppressions, 'host', name, detail)
|
||||
|
||||
|
||||
def _state_json(key: str) -> dict:
|
||||
"""Return a monitor_state JSON blob as a dict, or {} if missing or unreadable."""
|
||||
raw = db.get_state(key)
|
||||
if not raw:
|
||||
return {}
|
||||
try:
|
||||
return json.loads(raw)
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to parse {key} JSON: {e}')
|
||||
return {}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Page routes
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -235,8 +248,14 @@ def index():
|
||||
@app.route('/links')
|
||||
@require_auth
|
||||
def links_page():
|
||||
user = _get_user()
|
||||
return render_template('links.html', user=user)
|
||||
"""Link Debug moved to the per-device pages; keep old bookmarks working."""
|
||||
return redirect(url_for('index'))
|
||||
|
||||
|
||||
@app.route('/device/<path:name>')
|
||||
@require_auth
|
||||
def device_page(name: str):
|
||||
return render_template('device.html', user=_get_user(), device_name=name)
|
||||
|
||||
|
||||
@app.route('/inspector')
|
||||
@@ -315,6 +334,60 @@ def api_links():
|
||||
return jsonify({'hosts': {}, 'unifi_switches': {}, 'updated': None})
|
||||
|
||||
|
||||
@app.route('/api/modem')
|
||||
@require_auth
|
||||
def api_modem():
|
||||
"""Latest WAN modem status plus optical history for the trend chart."""
|
||||
try:
|
||||
hours = max(1, min(int(request.args.get('hours', 168)), 2160))
|
||||
except ValueError:
|
||||
return jsonify({'error': 'hours must be an integer'}), 400
|
||||
|
||||
raw = db.get_state('modem_stats')
|
||||
if not raw:
|
||||
return jsonify({'configured': False})
|
||||
try:
|
||||
data = json.loads(raw)
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to parse modem_stats JSON: {e}')
|
||||
return jsonify({'configured': False})
|
||||
|
||||
# A history failure shouldn't take the current readings down with it.
|
||||
try:
|
||||
# Keep roughly 200 points regardless of range; never finer than the 5 min poll.
|
||||
data['history'] = db.get_modem_history(hours, max(300, hours * 3600 // 200))
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to load modem history: {e}')
|
||||
data['history'] = []
|
||||
data['wan_history'] = _state_json('wan_history')
|
||||
data['configured'] = True
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
@app.route('/api/devices')
|
||||
@require_auth
|
||||
def api_devices():
|
||||
"""Device list for the home page search."""
|
||||
return jsonify({'devices': devices.build_index(
|
||||
_state_json('network_snapshot'), _state_json('link_stats'), _state_json('modem_stats'),
|
||||
)})
|
||||
|
||||
|
||||
@app.route('/api/device/<path:name>')
|
||||
@require_auth
|
||||
def api_device(name: str):
|
||||
"""Everything known about one device, for its detail page."""
|
||||
detail = devices.device_detail(
|
||||
name, _state_json('network_snapshot'), _state_json('link_stats'), _state_json('modem_stats'),
|
||||
)
|
||||
if detail is None:
|
||||
return jsonify({'error': f'No device named "{name}"'}), 404
|
||||
events = db.get_events_for_target(name)
|
||||
_annotate_suppressions(events, db.get_active_suppressions())
|
||||
detail['events'] = events
|
||||
return jsonify(detail)
|
||||
|
||||
|
||||
@app.route('/api/events')
|
||||
@require_auth
|
||||
def api_events():
|
||||
@@ -559,6 +632,7 @@ def api_avatar():
|
||||
|
||||
ldap_cfg = _config().get('ldap', {})
|
||||
if not ldap_cfg.get('host') or not ldap_cfg.get('bind_dn'):
|
||||
logger.warning('Avatar unavailable: config.json has no ldap.host / ldap.bind_dn')
|
||||
return '', 404
|
||||
|
||||
# Build a safe cache filename from the username (alphanumeric + - _ .)
|
||||
@@ -589,6 +663,7 @@ def api_avatar():
|
||||
# Skip LDAP if we already know this user has no avatar
|
||||
try:
|
||||
if os.path.exists(sentinel) and now - os.path.getmtime(sentinel) < cache_ttl:
|
||||
logger.info(f'Avatar for {username!r}: cached "no photo" marker is still valid')
|
||||
return '', 404
|
||||
except OSError:
|
||||
pass
|
||||
@@ -627,6 +702,7 @@ def api_avatar():
|
||||
pass
|
||||
|
||||
if not avatar_data or len(avatar_data) < 100:
|
||||
logger.warning(f'Avatar for {username!r}: LDAP has no photo (or no user with that uid)')
|
||||
with open(sentinel, 'w'):
|
||||
pass
|
||||
return '', 404
|
||||
|
||||
Reference in new issue
Block a user