a7a281cb11
First-party plugins (host_agent, http, snmp, traefik, unifi, docker) are now tracked under plugins/ and baked into the image, so they version atomically with core — ending the cross-repo import drift the roundtable->steward rename exposed. History for these files is preserved in the archived Roundtable-plugins repo. Plugin discovery becomes multi-root: PLUGIN_DIR (single) -> PLUGIN_DIRS (bundled first, then external) + PLUGIN_INSTALL_DIR. Bundled ships in the image; third-party plugins still mount at runtime into the external root (STEWARD_PLUGIN_DIR, default /data/plugins) and downloads/installs land there. Bundled shadows external on a name collision. - config.py: load_bootstrap returns plugin_dirs + plugin_install_dir - app.py: iterate PLUGIN_DIRS at the migration + load sites - migration_runner.py: discover_all_in() unions every plugin root - plugin_manager.py: resolve_plugin_path() (pure, first-root-wins); load / install / hot-reload span all roots; installs target the external root - settings/routes.py: _discover_plugins scans all roots, dedup bundled-first - Dockerfile: COPY plugins/ ; docker-compose: drop host bind, document external - tests/test_plugin_dirs.py: resolution, multi-root discovery, bootstrap split Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
2.5 KiB
Python
79 lines
2.5 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 fabledscryer.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 datetime import datetime, timezone
|
|
from .poller import poll_device_sync
|
|
from fabledscryer.core.alerts import record_metric
|
|
|
|
devices: list[dict] = app.config["PLUGINS"]["snmp"].get("devices", [])
|
|
if not devices:
|
|
return
|
|
|
|
loop = asyncio.get_event_loop()
|
|
now = datetime.now(timezone.utc)
|
|
|
|
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)
|