Internet health from UniFi: Needs attention line and a 24 hour strip
Lint / JS (eslint) (push) Successful in 1m10s
Lint / Python (flake8) (push) Successful in 2m31s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m26s
Lint / Python (flake8) (pull_request) Successful in 1m4s
Test / Python Tests (pytest) (push) Successful in 1m13s
Lint / JS (eslint) (pull_request) Successful in 7s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m0s
Test / Python Tests (pytest) (pull_request) Successful in 1m3s
Lint / JS (eslint) (push) Successful in 1m10s
Lint / Python (flake8) (push) Successful in 2m31s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m26s
Lint / Python (flake8) (pull_request) Successful in 1m4s
Test / Python Tests (pytest) (push) Successful in 1m13s
Lint / JS (eslint) (pull_request) Successful in 7s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m0s
Test / Python Tests (pytest) (pull_request) Successful in 1m3s
UniFi already rates the WAN every 5 minutes (fine, high latency, packet loss, down), the same timeline its Network app charts. The monitor now reads the last day of it from the dashboard API each cycle, read only, instead of Gandalf pinging on its own. - modem.wan_quality() turns the dashboard data into periods, drops and current service latencies; stored as monitor_state.wan_quality. - Needs attention: "Internet: packet loss in N of the last 12 five-minute periods" (2+ lossy periods, red), "high latency" (3+ bad periods, amber), and drops in the last hour. Stale copies are ignored. - WAN / Fiber panel: a 24 hour strip with a legend and latency now, also shown while the modem itself can't be read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+26
@@ -229,6 +229,19 @@ class UnifiClient:
|
||||
logger.error(f'UniFi system log error: {e}')
|
||||
return None
|
||||
|
||||
def get_wan_dashboard(self) -> Optional[dict]:
|
||||
"""UniFi's aggregated dashboard for the last day (WAN health timeline and service
|
||||
latencies, as the Network app charts them), or None if unavailable. Read only."""
|
||||
url = f'{self.base_url}/proxy/network/v2/api/site/{self.site_id}/aggregated-dashboard'
|
||||
try:
|
||||
resp = self.session.get(url, headers=self.headers, timeout=20, params={'historySeconds': 86400})
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
return data if isinstance(data, dict) else None
|
||||
except Exception as e:
|
||||
logger.error(f'UniFi dashboard error: {e}')
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _update_fields(params: dict) -> dict:
|
||||
"""The app and versions of an update entry; nothing for other entries."""
|
||||
@@ -1950,6 +1963,13 @@ class NetworkMonitor:
|
||||
'point toward the provider or the modem rather than the fiber.',
|
||||
)
|
||||
|
||||
def _collect_wan_quality(self) -> None:
|
||||
"""Store UniFi's WAN health timeline. If UniFi can't be read, the last copy stays
|
||||
and goes stale, and the dashboard stops drawing conclusions from it."""
|
||||
quality = modem_api.wan_quality(self.unifi.get_wan_dashboard(), time.time())
|
||||
if quality is not None:
|
||||
db.set_state('wan_quality', quality)
|
||||
|
||||
def _collect_modem(self, suppressions: list) -> None:
|
||||
"""Poll the modem, then store its status and raise any alerts."""
|
||||
try:
|
||||
@@ -2135,6 +2155,12 @@ class NetworkMonitor:
|
||||
except Exception as e:
|
||||
logger.error(f'Modem collection failed: {e}', exc_info=True)
|
||||
|
||||
# Internet quality as UniFi measures it (latency, loss, drops): for the dashboard
|
||||
try:
|
||||
self._collect_wan_quality()
|
||||
except Exception as e:
|
||||
logger.error(f'WAN quality collection failed: {e}', exc_info=True)
|
||||
|
||||
# Note on the tickets of anything that cleared this cycle (or failed to post before)
|
||||
try:
|
||||
self._post_recovery_notes()
|
||||
|
||||
Reference in New Issue
Block a user