feat(zabbix): a native Zabbix agent through ZabbixAgentMixin (NetOrk/netork#2571)
driver / lint (pull_request) Successful in 14s
driver / standard (pull_request) Successful in 17s
driver / types (pull_request) Successful in 59s
driver / test (3.13) (pull_request) Successful in 57s
driver / test (3.12) (pull_request) Successful in 1m2s
driver / lowest (pull_request) Successful in 40s
driver / build (pull_request) Successful in 37s
driver / security (pull_request) Successful in 1m17s
CI / driver (pull_request) Successful in 2m32s
driver / publish (pull_request) Skipped

configure_zabbix_agent(settings) installs zabbix-agent from the host's packages,
and where they have none, from Zabbix's repository for the server's release
line. It writes the caller's values into /etc/zabbix/zabbix_agentd.conf (the old
file stays as .bak) and opens tcp/ListenPort for the allowed sources in
firewalld, ufw or iptables.

The firewall step of the SNMP agent is the shared _allow_sources(allowed, port,
proto) now, in _open_port.py; the rules it writes for udp/161 are the same.
Needs napalm-device-types 4.40.0.
This commit is contained in:
Christian Manivong committed 2026-11-17 04:58:46 +01:00
1 parent 0e1c4e7927
commit 2521f9f462
8 files changed
+360 -25

No files matched your search

+5 -21
View File
@@ -78,6 +78,7 @@ from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutExc
from napalm_linux._dpkg import DPKG_QUERY_COMMAND, parse_dpkg_query
from napalm_linux._hostname import HostnameMixin
from napalm_linux._local_accounts import LinuxLocalAccountsMixin
from napalm_linux._open_port import OpenPortMixin
from napalm_linux._ping import parse_ping, ping_command
from napalm_linux._posix import LinuxPosixMixin
from napalm_linux._readings import LinuxProcessReadingsMixin
@@ -87,11 +88,10 @@ from napalm_linux._shell import expect_for, prepare_shell, sudo_without_password
from napalm_linux._snmp_agent import (
_SNMP_INSTALL,
_SNMPD_CONF,
_source,
firewalld_allow_snmp,
render_snmpd_conf,
)
from napalm_linux._sudo_history import LinuxSudoHistoryMixin
from napalm_linux._zabbix_agent import LinuxZabbixAgentMixin
logger = logging.getLogger("napalm_linux")
@@ -272,6 +272,8 @@ class LinuxDriver(
LinuxSudoHistoryMixin,
LinuxLocalAccountsMixin,
SnmpAgentMixin,
LinuxZabbixAgentMixin,
OpenPortMixin,
EnsurePackageMixin,
AptProxyMixin,
KernelFactsMixin,
@@ -1796,25 +1798,7 @@ class LinuxDriver(
return {"ok": True, "output": f"wrote {_SNMPD_CONF}"}
def _allow_snmp_sources(self, settings: SnmpAgentSettingsDict) -> FixStepOutcomeDict:
sources = [_source(s) for s in settings.get("allowed_sources", [])]
if not sources:
return {"ok": True, "output": "no sources given; firewall unchanged"}
# firewalld first: its hosts have iptables too, and an iptables ACCEPT does
# not lift firewalld's reject (both are nftables tables; a drop in either wins).
if self._send("systemctl is-active firewalld 2>/dev/null") == "active":
done = f"udp/161 open in firewalld for {', '.join(sources)}"
return self._root_outcome(firewalld_allow_snmp(sources), 60, done)
if self._send("command -v ufw 2>/dev/null"):
rules = [f"ufw allow from {s} to any port 161 proto udp" for s in sources]
elif self._send("command -v iptables 2>/dev/null"):
rules = [
f"{{ iptables -C INPUT -s {s} -p udp --dport 161 -j ACCEPT 2>/dev/null"
f" || iptables -I INPUT -s {s} -p udp --dport 161 -j ACCEPT; }}"
for s in sources
]
else:
return {"ok": True, "output": "no host firewall (ufw, iptables); nothing to open"}
return self._root_outcome(" && ".join(rules), 30, f"udp/161 open for {', '.join(sources)}")
return self._allow_sources(settings.get("allowed_sources", []), 161, "udp")
def _start_snmp_agent(self) -> FixStepOutcomeDict:
return self._root_outcome(