The operator, reviewing SNMP on #5214: "this system looks incomplete like there's something missing from it". The one device shown was plugin.yaml's example (core-switch 192.168.1.1, community public), polled every minute; devices could only be defined by editing YAML in the image; a failed poll was logged at DEBUG and stored nowhere, so the page said "waiting for the next poll" forever; v3 ran as v2c; counters showed as lifetime totals. - Devices are rows (snmp_devices, migration snmp_001): address, port, v1/v2c community or a v3 user with auth/priv protocols and keys (secrets encrypted), presets plus custom readings, an optional host binding, and the newest poll's outcome. The YAML device list and its example are gone. - The SNMP page adds, edits and deletes them (admin, audited, with get_audit_entities so the audit log names and links a device). Readings come from presets (system uptime, interface traffic by number, UPS-MIB, Linux net-snmp) and custom "OID name [unit]" lines. - One GET per device with every OID, devices polled at once. The outcome is written to the row in words ("No reply from … within 5 s. Check the address and port, that SNMP is on, and the community"), with readings it lacks. v1's whole-request error drops that OID and asks again. SNMPv3 signs in with USM (MD5/SHA-1/SHA-2, DES/3DES/AES). - Test asks the unsaved form's device for its name, description, uptime and interfaces by number. It is an admin's explicit action; every page reads only stored rows (System 178's ruling). - Each reading has a unit; a counter is stored as a per-second rate (bytes as bit/s), a reset or wrap skipped. The page, widget and host panel say values in units and why a device is silent; the device page draws a chart per reading on a dated axis. Tests: readings and presets, the form and its secrets, v3 checks, rates, the poller against a stand-in pysnmp (one GET, v1 retry, timeout wording, USM), the pages, and an integration test of the poll writing outcomes and rates on Postgres. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
2.2 KiB
Python
50 lines
2.2 KiB
Python
"""SNMP devices are rows edited on the SNMP page
|
|
|
|
Devices lived in plugin.yaml's config, which the UI could not edit, and a poll
|
|
that failed left no trace. A row per device holds what to ask and how, and the
|
|
newest poll's outcome (milestone 491).
|
|
|
|
Revision ID: snmp_001_devices
|
|
Revises: (none — a branch off core via depends_on)
|
|
Create Date: 2026-10-08
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "snmp_001_devices"
|
|
down_revision: Union[str, None] = None
|
|
branch_labels: Union[str, Sequence[str], None] = "snmp"
|
|
depends_on: Union[str, Sequence[str], None] = ("0004_app_settings",)
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"snmp_devices",
|
|
sa.Column("id", sa.String(36), primary_key=True),
|
|
sa.Column("name", sa.String(100), nullable=False, unique=True),
|
|
sa.Column("address", sa.String(255), nullable=False),
|
|
sa.Column("port", sa.Integer, nullable=False, server_default="161"),
|
|
sa.Column("version", sa.String(3), nullable=False, server_default="2c"),
|
|
sa.Column("community", sa.Text, nullable=False, server_default=""),
|
|
sa.Column("v3_user", sa.String(100), nullable=False, server_default=""),
|
|
sa.Column("v3_auth", sa.String(16), nullable=False, server_default="none"),
|
|
sa.Column("v3_auth_key", sa.Text, nullable=False, server_default=""),
|
|
sa.Column("v3_priv", sa.String(16), nullable=False, server_default="none"),
|
|
sa.Column("v3_priv_key", sa.Text, nullable=False, server_default=""),
|
|
sa.Column("presets", sa.JSON, nullable=False, server_default="[]"),
|
|
sa.Column("interfaces", sa.String(255), nullable=False, server_default=""),
|
|
sa.Column("custom", sa.Text, nullable=False, server_default=""),
|
|
sa.Column("host_id", sa.String(36), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("last_polled_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("last_ok_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("last_error", sa.Text, nullable=True),
|
|
sa.Column("missing", sa.JSON, nullable=False, server_default="[]"),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("snmp_devices")
|