feat(zabbix): an agent that only connects out listens on no port (NetOrk/netork#2683)
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m7s
driver / test (3.12) (pull_request) Successful in 1m21s
driver / test (3.13) (pull_request) Successful in 1m13s
driver / lowest (pull_request) Successful in 37s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 55s
CI / driver (pull_request) Successful in 55s
driver / publish (pull_request) Skipped

ZabbixAgentSettingsDict.active_only: zabbix_agent_config writes
StartAgents=0 and comments Server out (mandatory only while StartAgents
is not 0); ServerActive is required instead. configure_zabbix_agent's
firewall step opens nothing for it. An agent that is not active only gets
a StartAgents=0 line commented out.
This commit is contained in:
christianmanivong committed 2026-11-25 21:24:39 +01:00
1 parent e729b935a4
commit b1ea364674
5 files changed
+143 -14

No files matched your search

+80
View File
@@ -97,6 +97,75 @@ class TestConfig:
assert text.count("Server=zabbix.example.com\n") == 2
ACTIVE_ONLY = {**SETTINGS, "active_only": True, "allowed_sources": []}
class TestActiveOnly:
"""A site whose agents only connect out (NetOrk/netork#2683): no passive listener.
Zabbix's ``StartAgents=0`` disables passive checks and the agent listens on no
port; ``Server`` is mandatory only while ``StartAgents`` is not 0, so nothing is
left that may ask.
"""
def test_it_starts_no_listener_and_lets_nobody_ask(self):
text, changes = zabbix_agent_config(SAMPLE, ACTIVE_ONLY)
assert text.endswith("StartAgents=0\n")
assert "\n# Server=127.0.0.1\n" in text
assert "\nServer=" not in text
assert "\nServerActive=zabbix.example.com\n" in text
assert "\nHostname=ap-1og\n" in text
assert "StartAgents: (not set) → 0" in changes
assert "Server: 127.0.0.1 → (not set)" in changes
def test_a_listener_count_of_its_own_becomes_none(self):
text, changes = zabbix_agent_config("StartAgents=5\n", ACTIVE_ONLY)
assert text.startswith("StartAgents=0\n")
assert "StartAgents: 5 → 0" in changes
def test_a_file_that_already_says_it_changes_nothing(self):
text, _ = zabbix_agent_config(SAMPLE, ACTIVE_ONLY)
again, changes = zabbix_agent_config(text, ACTIVE_ONLY)
assert again == text
assert changes == []
def test_a_passive_agent_listens_again(self):
"""An agent that was active only before: ``StartAgents=0`` would keep it deaf."""
text, _ = zabbix_agent_config(SAMPLE, ACTIVE_ONLY)
again, changes = zabbix_agent_config(text, SETTINGS)
assert "\n# StartAgents=0\n" in again
assert "\nServer=zabbix.example.com\n" in again
assert "StartAgents: 0 → (not set)" in changes
def test_a_passive_agent_keeps_its_own_listener_count(self):
text, changes = zabbix_agent_config("StartAgents=5\n", SETTINGS)
assert text.startswith("StartAgents=5\n")
assert not any(c.startswith("StartAgents") for c in changes)
def test_it_needs_somewhere_to_send_its_checks(self):
with pytest.raises(ValueError):
check_zabbix_agent_settings({**ACTIVE_ONLY, "server_active": ""})
def test_it_needs_no_server_that_may_ask(self):
check_zabbix_agent_settings({**ACTIVE_ONLY, "server": ""})
def test_a_server_that_is_not_addresses_is_still_refused(self):
with pytest.raises(ValueError):
check_zabbix_agent_settings({**ACTIVE_ONLY, "server": "a\nb"})
@pytest.mark.parametrize("value", ["yes", 1, None])
def test_active_only_is_a_bool(self, value):
with pytest.raises(ValueError):
check_zabbix_agent_settings({**SETTINGS, "active_only": value})
class TestSettings:
@pytest.mark.parametrize(
"server",
@@ -327,6 +396,17 @@ class TestZabbixAgentMixin:
assert result["success"] is True
assert agent.calls[0] == ("ensure_package", "zabbix-agent")
def test_an_active_only_agent_opens_no_port(self):
"""NetOrk/netork#2683: nothing listens, so nothing is let through."""
agent = _Agent()
result = agent.configure_zabbix_agent({**ACTIVE_ONLY, "allowed_sources": ["10.0.0.1"]})
assert result["success"] is True
assert not [c for c in agent.calls if c[0] == "firewall"]
assert [s["step"] for s in result["steps"]] == ["install", "configure", "firewall", "start"]
assert "active only" in result["steps"][2]["output"]
def test_a_closed_firewall_starts_nothing(self):
agent = _Agent(refuse=frozenset({"firewall"}))