fix: the SNMP agent setup sends only what os-net-snmp 26.x knows (#36)
driver / lint (pull_request) Successful in 15s
driver / standard (pull_request) Failing after 16s
driver / types (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 1m1s
driver / test (3.12) (pull_request) Successful in 1m9s
driver / lowest (pull_request) Successful in 31s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 58s
CI / driver (pull_request) Failing after 2m15s
driver / publish (pull_request) Skipped

The configure step posted contact, location, sysobjid and bindip, and
listen in the shape get returns. OPNsense 26.x refuses a field its model
does not have with HTTP 500, so the setup failed on every current box.
It now sends syscontact/syslocation, listen as a string, and contact and
location only when the caller gives them: an empty one would have blanked
the operator's.
This commit is contained in:
Christian Manivong committed 2026-10-31 07:17:04 +01:00
1 parent c02a745bb3
commit 8bf76aa346
3 files changed
+53 -21

No files matched your search

+12 -17
View File
@@ -2438,6 +2438,8 @@ class OPNsenseDriver(
#: old any-source rule is recognised by its older description.
_SNMP_RULE_PREFIX = "napalm-opnsense: SNMP from "
_SNMP_RULE_OLD = "[netork] Allow SNMP"
#: The caller's system values and the os-net-snmp fields they go to.
_SNMP_SYSTEM_FIELDS = {"contact": "syscontact", "location": "syslocation"}
def _install_snmp_agent(self) -> FixStepOutcomeDict:
# Installing over an installed os-net-snmp starts an async reinstall that
@@ -2458,28 +2460,21 @@ class OPNsenseDriver(
raise ValueError("the community must be one word without quotes or #")
listen = settings.get("listen") or self.hostname
try:
listen_val = {str(ipaddress.ip_address(listen)): {"selected": 1}}
listen_val = str(ipaddress.ip_address(listen))
except ValueError:
listen_val = {} # a DNS name binds nothing; snmpd then listens everywhere
result = self._post(
"/api/netsnmp/general/set",
{
"general": {
"enabled": "1",
"community": community,
"contact": settings.get("contact", ""),
"location": settings.get("location", ""),
"sysobjid": "",
"bindip": "",
"listen": listen_val,
}
},
)
listen_val = "" # a DNS name binds nothing; snmpd then listens everywhere
general = {"enabled": "1", "community": community, "listen": listen_val}
# Only what the caller gives: an empty one would blank the operator's.
for key, field in self._SNMP_SYSTEM_FIELDS.items():
if settings.get(key):
general[field] = settings[key]
# The plugin's model refuses any field it does not have, with a 500 (#36).
result = self._post("/api/netsnmp/general/set", {"general": general})
if result.get("result") != "saved":
return {"ok": False, "output": f"configuration refused: {result}"}
return {
"ok": True,
"output": f"community set, listen {list(listen_val) or 'all addresses'}",
"output": f"community set, listen {listen_val or 'all addresses'}",
}
def _allow_snmp_sources(self, settings: SnmpAgentSettingsDict) -> FixStepOutcomeDict: