af60ca446d
The fabledscryer->steward rename had only ever reached host_agent. The other five bundled plugins (http, snmp, traefik, unifi, docker) still imported `from fabledscryer.*` (package no longer exists) and read FABLEDSCRYER_* env vars — so every one of them was broken at import since the original rebrand. CI stayed green only because none are enabled by default and migrations don't import plugin modules. Now that they version in-tree, complete the rename: - fabledscryer.* -> steward.* imports across all five plugins - FABLEDSCRYER_* -> STEWARD_* in plugin migration env.py files - author/repository/homepage + user-facing 'Fabled Scryer' strings -> Steward - snmp/scheduler.py: also drop dead `now`/datetime; record_metric from steward Adds tests/test_no_legacy_names.py — fails if 'scryer'/'roundtable' ever reappear in shipped code (the drift bit twice; this stops a third time). Also clears pre-existing ruff lint debt (unused imports, semicolon statements, mid-file import) surfaced by the new lint lane. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
# plugins/snmp/scheduler.py
|
|
from __future__ import annotations
|
|
import asyncio
|
|
import logging
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from quart import Quart
|
|
|
|
from steward.core.scheduler import ScheduledTask
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def make_poll_task(app: "Quart") -> ScheduledTask:
|
|
interval = app.config["PLUGINS"]["snmp"].get("poll_interval_seconds", 60)
|
|
|
|
async def poll() -> None:
|
|
await _do_poll(app)
|
|
|
|
return ScheduledTask(
|
|
name="snmp_poll",
|
|
coro_factory=poll,
|
|
interval_seconds=int(interval),
|
|
run_on_startup=True,
|
|
)
|
|
|
|
|
|
async def _do_poll(app: "Quart") -> None:
|
|
from .poller import poll_device_sync
|
|
from steward.core.alerts import record_metric
|
|
|
|
devices: list[dict] = app.config["PLUGINS"]["snmp"].get("devices", [])
|
|
if not devices:
|
|
return
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
async with app.db_sessionmaker() as session:
|
|
async with session.begin():
|
|
for device in devices:
|
|
if not isinstance(device, dict):
|
|
continue
|
|
name = device.get("name") or device.get("host", "unknown")
|
|
host = device.get("host", "")
|
|
port = int(device.get("port", 161))
|
|
community = device.get("community", "public")
|
|
version = str(device.get("version", "2c"))
|
|
oids = device.get("oids", [])
|
|
|
|
if not host or not oids:
|
|
continue
|
|
|
|
try:
|
|
readings = await loop.run_in_executor(
|
|
None,
|
|
poll_device_sync,
|
|
host, port, community, version, oids,
|
|
)
|
|
except Exception:
|
|
logger.exception("SNMP poll failed for device %s (%s)", name, host)
|
|
continue
|
|
|
|
for label, value in readings.items():
|
|
await record_metric(
|
|
session=session,
|
|
source_module="snmp",
|
|
resource_name=name,
|
|
metric_name=label,
|
|
value=value,
|
|
)
|
|
|
|
if readings:
|
|
logger.debug("SNMP polled %s (%s): %d OID(s)", name, host, len(readings))
|
|
else:
|
|
logger.debug("SNMP polled %s (%s): no readings", name, host)
|