get_network gives the WAN, clients, Wi-Fi networks, speed tests and devices by status; list_devices, list_clients (everyone seen, or the newest poll's top talkers), list_network_events, list_alarms and get_network_config (networks, port forwards, firewall rules) read what the poller stored. get_overview names the WAN down while the poll is current, a device offline or degraded that the controller still reports, and active alarms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
1.8 KiB
Python
58 lines
1.8 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"]}
|
|
|
|
|
|
def register_mcp_tools(register) -> None:
|
|
from .mcp_tools import register_tools
|
|
register_tools(register)
|
|
|
|
|
|
async def mcp_overview(db) -> list[dict]:
|
|
from .mcp_tools import mcp_overview as findings
|
|
return await findings(db)
|