feat(zabbix): an active-only agent closes the port netOrk opened for it (NetOrk/netork#2693)

Every rule the firewall step adds in firewalld, ufw or iptables is recorded in
napalm-device-types' opened_ports record, only when the firewall did not have
it before. For an active-only agent, _revoke_zabbix_agent_sources removes
exactly the agent's recorded rules and reports what is left for the port.
This commit is contained in:
Christian Manivong committed 2026-11-26 08:19:19 +01:00
1 parent 04ff633290
commit a3b9e4a02d
8 files changed
+516 -37

No files matched your search

+14 -3
View File
@@ -5,7 +5,8 @@ For a host without a container engine (NetOrk/netork#2571). The template install
Zabbix's own repository too -- and enables and restarts its service. This writes the
caller's values into ``/etc/zabbix/zabbix_agentd.conf`` (where both put it), adds
Zabbix's repository where the host's own packages have none, and opens the port in
whichever firewall runs.
whichever firewall runs -- or, for an active-only agent, closes what netOrk opened
for it before.
"""
from __future__ import annotations
@@ -13,6 +14,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from napalm_device_types import (
ZABBIX_AGENT_PURPOSE,
FixStepOutcomeDict,
ZabbixAgentMixin,
ZabbixAgentSettingsDict,
@@ -58,7 +60,14 @@ class LinuxZabbixAgentMixin(ZabbixAgentMixin):
return {"ok": True, "output": "; ".join(changes)}
def _allow_zabbix_agent_sources(self, settings: ZabbixAgentSettingsDict) -> FixStepOutcomeDict:
return self._allow_sources(settings["allowed_sources"], int(settings["listen_port"]), "tcp")
return self._allow_sources(
settings["allowed_sources"], int(settings["listen_port"]), "tcp", ZABBIX_AGENT_PURPOSE
)
def _revoke_zabbix_agent_sources(self, settings: ZabbixAgentSettingsDict) -> FixStepOutcomeDict:
"""For an active-only agent: remove the rules recorded for the agent on an
earlier passive run, whatever port they opened (NetOrk/netork#2693)."""
return self._revoke_sources(ZABBIX_AGENT_PURPOSE, int(settings["listen_port"]), "tcp")
if TYPE_CHECKING: # pragma: no cover - the driver's
@@ -76,5 +85,7 @@ class LinuxZabbixAgentMixin(ZabbixAgentMixin):
def _install_file_as_root(self, path: str, content: str) -> CommandResult: ...
def _allow_sources(
self, allowed: list[str], port: int, proto: str
self, allowed: list[str], port: int, proto: str, purpose: str
) -> FixStepOutcomeDict: ...
def _revoke_sources(self, purpose: str, port: int, proto: str) -> FixStepOutcomeDict: ...