- prune_by_age(column) registers a time-series column with the hourly cleanup; Traefik (metrics, access summaries, global stats) and UniFi (WAN, client, WLAN, DPI, events, alarms, speedtests) register theirs in setup(). - Alert events join monitor results and Ansible runs on data.retention_days, read from Settings each run; Ansible run log files older than it are deleted. - audit.retention_days (365) keeps the audit log longer, set on Settings > General. - metric_series.points reads metrics.retention.raw_days, so the chart's raw/rollup seam is where the rollup put it (RAW_DAYS removed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
# plugins/unifi/__init__.py
|
|
from __future__ import annotations
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from quart import Quart
|
|
|
|
_app: "Quart | None" = None
|
|
|
|
|
|
def setup(app: "Quart") -> None:
|
|
global _app
|
|
_app = app
|
|
from .models import ( # noqa: F401
|
|
UnifiWanStat, UnifiClientSnapshot, UnifiWlanStat, UnifiDpiSnapshot,
|
|
UnifiDevice, UnifiKnownClient, UnifiEvent, UnifiAlarm,
|
|
UnifiSpeedtestResult, UnifiNetwork, UnifiPortForward, UnifiFwRule,
|
|
)
|
|
from steward.core.cleanup import prune_by_age
|
|
# Samples and history older than data.retention_days are pruned by the
|
|
# cleanup (#5155). Devices, known clients and config tables are current state.
|
|
for column in (UnifiWanStat.scraped_at, UnifiClientSnapshot.scraped_at,
|
|
UnifiWlanStat.scraped_at, UnifiDpiSnapshot.scraped_at,
|
|
UnifiEvent.event_time, UnifiAlarm.alarm_time,
|
|
UnifiSpeedtestResult.run_at):
|
|
prune_by_age(column)
|
|
|
|
|
|
def get_scheduled_tasks() -> list:
|
|
from .scheduler import make_poll_task
|
|
return [make_poll_task(_app)]
|
|
|
|
|
|
def get_blueprint():
|
|
from .routes import unifi_bp
|
|
return unifi_bp
|
|
|
|
|
|
def get_nav() -> list[dict]:
|
|
# Surfaces in the sidebar's Infrastructure group (UniFi network overview).
|
|
return [{"label": "UniFi", "href": "/plugins/unifi/"}]
|
|
|
|
|
|
def get_alert_metrics() -> dict[str, list[str]]:
|
|
"""What scheduler.py records: the WAN (resource "wan") and the client count
|
|
(resource "clients")."""
|
|
return {"unifi": ["is_up", "latency_ms", "total_clients"]}
|