Module: check_mk
Branch: master
Commit: 96c7d5b4348873cc0d089dd01153abc276baecc4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=96c7d5b4348873…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jan 14 21:29:20 2019 +0100
7029 FIX Skip adding PING service to piggyback only hosts without IP
When a host is configured as "No agent", "No SNMP" and "No IP
address"
host it is not useful to add a "PING" service to it in case there are
other services on this host because there is no address to be pinged.
This combination of tags e.g. is used by the Dynamic configuration to
create container hosts or similar.
Change-Id: I0b0ca9c78ef4d027e4129d7d1e929aceff888b9e
---
.werks/7029 | 15 +++++++++++++++
cmk/gui/watolib/hosts_and_folders.py | 3 ++-
cmk_base/default_config/base.py | 11 +++++++++--
tests/unit/cmk_base/test_config.py | 24 ++++++++++++++++++++++++
4 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/.werks/7029 b/.werks/7029
new file mode 100644
index 0000000..86e824a
--- /dev/null
+++ b/.werks/7029
@@ -0,0 +1,15 @@
+Title: Skip adding PING service to piggyback only hosts without IP
+Level: 1
+Component: core
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1547497560
+Class: fix
+
+When a host is configured as "No agent", "No SNMP" and "No IP
address"
+host it is not useful to add a "PING" service to it in case there are
+other services on this host because there is no address to be pinged.
+
+This combination of tags e.g. is used by the Dynamic configuration to
+create hosts that represent container objects or similar.
diff --git a/cmk/gui/watolib/hosts_and_folders.py b/cmk/gui/watolib/hosts_and_folders.py
index c444125..cf2f6c2 100644
--- a/cmk/gui/watolib/hosts_and_folders.py
+++ b/cmk/gui/watolib/hosts_and_folders.py
@@ -1919,7 +1919,8 @@ class CREHost(WithPermissionsAndAttributes):
# SNMP, it needs to get the ping tag assigned.
# Because we need information from multiple attributes to get this
# information, we need to add this decision here.
- if "no-snmp" in tags and "no-agent" in tags:
+ # Skip this in case no-ip is configured: A ping check is useless in this case
+ if "no-snmp" in tags and "no-agent" in tags and not
"no-ip" in tags:
tags.add("ping")
# The following code is needed to migrate host/rule matching from <1.5
diff --git a/cmk_base/default_config/base.py b/cmk_base/default_config/base.py
index 99e11ce..8756d18 100644
--- a/cmk_base/default_config/base.py
+++ b/cmk_base/default_config/base.py
@@ -138,8 +138,15 @@ all_hosts = []
# TODO: This is a derived variable. Should be handled like others
# (hosttags, service_service_levels, ...)
host_paths = {}
-snmp_hosts = [(['snmp'], _ALL_HOSTS)]
-tcp_hosts = [(['tcp'], _ALL_HOSTS), (_NEGATE, ['snmp'], _ALL_HOSTS),
(['!ping'], _ALL_HOSTS)]
+snmp_hosts = [
+ (['snmp'], _ALL_HOSTS),
+]
+tcp_hosts = [
+ (['tcp'], _ALL_HOSTS),
+ (_NEGATE, ['snmp'], _ALL_HOSTS),
+ # Match all those that don't have ping and don't have no-agent set
+ (['!ping', '!no-agent'], _ALL_HOSTS),
+]
bulkwalk_hosts = []
snmpv2c_hosts = []
snmp_without_sys_descr = []
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 86bb413..5ae82f6 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -84,6 +84,30 @@ def test_management_address_of(monkeypatch, attrs, result):
@pytest.mark.parametrize("hostname,tags,result", [
+ ("testhost", [], True),
+ ("testhost", ["cmk-agent"], True),
+ ("testhost", ["cmk-agent", "tcp"], True),
+ ("testhost", ["snmp", "tcp"], True),
+ ("testhost", ["ping"], False),
+ ("testhost", ["no-agent", "no-snmp"], False),
+])
+def test_is_tcp_host(monkeypatch, hostname, tags, result):
+ monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ assert config.is_tcp_host(hostname) == result
+
+
+(a)pytest.mark.parametrize("hostname,tags,result"sult", [
+ ("testhost", [], False),
+ ("testhost", ["cmk-agent"], False),
+ ("testhost", ["snmp", "tcp"], True),
+ ("testhost", ["snmp"], True),
+])
+def test_is_snmp_host(monkeypatch, hostname, tags, result):
+ monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ assert config.is_snmp_host(hostname) == result
+
+
+(a)pytest.mark.parametrize("hostname,tags,result"sult", [
("testhost", [], False),
("testhost", ["all-agents"], True),
("testhost", ["special-agents"], False),