Module: check_mk
Branch: master
Commit: 2394633770c08968eeb4346b4b354b674353ecd7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2394633770c089…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Apr 5 14:08:23 2018 +0200
5945 Hosts can now be configured without IP address
It is now possible to configure hosts in Check_MK that have no IP address configured.
This is useful e.g. in case a host is only monitored using piggyback data from another
host.
In previous versions of Check_MK a fake IP address had to be configured for each host
to prevent warning messages during config generation and during monitoring.
To configure a host without IP, simply set the "IP address family" attribute of
a host
to "No IP".
The host check of these hosts will always report "UP" by default. To override
this, you
can use the rule set "Host check command".
Change-Id: I7870d6c2072c8781488f983d4072065340eb755c
---
.werks/5945 | 21 +++++++++++++++++++++
cmk_base/config.py | 16 ++++++++++++++--
cmk_base/core_config.py | 2 ++
cmk_base/ip_lookup.py | 4 ++++
tests/unit/cmk_base/test_config.py | 26 ++++++++++++++++++++++++++
web/htdocs/watolib.py | 1 +
6 files changed, 68 insertions(+), 2 deletions(-)
diff --git a/.werks/5945 b/.werks/5945
new file mode 100644
index 0000000..43f436a
--- /dev/null
+++ b/.werks/5945
@@ -0,0 +1,21 @@
+Title: Hosts can now be configured without IP address
+Level: 1
+Component: core
+Compatible: compat
+Edition: cre
+Version: 1.5.0i4
+Date: 1522929824
+Class: feature
+
+It is now possible to configure hosts in Check_MK that have no IP address configured.
+This is useful e.g. in case a host is only monitored using piggyback data from another
+host.
+
+In previous versions of Check_MK a fake IP address had to be configured for each host
+to prevent warning messages during config generation and during monitoring.
+
+To configure a host without IP, simply set the "IP address family" attribute of
a host
+to "No IP".
+
+The host check of these hosts will always report "UP" by default. To override
this, you
+can use the rule set "Host check command".
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 96d3767..e964cdb 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -679,8 +679,20 @@ def is_ipv6_host(hostname):
def is_ipv4_host(hostname):
- # Either explicit IPv4 or implicit (when host is not an IPv6 host)
- return "ip-v4" in tags_of_host(hostname) or "ip-v6" not in
tags_of_host(hostname)
+ """Whether or not the given host is configured to be monitored via
IPv4.
+ This is the case when it is set to be explicit IPv4 or implicit
+ (when host is not an IPv6 host and not a "No IP" host)"""
+ tags = tags_of_host(hostname)
+
+ if "ip-v4" in tags:
+ return True
+
+ return "ip-v6" not in tags and "no-ip" not in tags
+
+
+def is_no_ip_host(hostname):
+ """Whether or not the given host is configured not to be monitored via
IP"""
+ return "no-ip" in tags_of_host(hostname)
#
# Management board
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 0f81d26..ce7ec8e 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -88,6 +88,8 @@ def host_check_command(hostname, ip, is_clust,
hostcheck_commands_to_define=None
values = rulesets.host_extra_conf(hostname, config.host_check_commands)
if values:
value = values[0]
+ elif config.is_no_ip_host(hostname):
+ value = "ok"
elif config.monitoring_core == "cmc":
value = "smart"
else:
diff --git a/cmk_base/ip_lookup.py b/cmk_base/ip_lookup.py
index d061ed0..e53793d 100644
--- a/cmk_base/ip_lookup.py
+++ b/cmk_base/ip_lookup.py
@@ -118,6 +118,10 @@ def cached_dns_lookup(hostname, family):
cache[cache_id] = cached_ip
return cached_ip
+ if config.is_no_ip_host(hostname):
+ cache[cache_id] = None
+ return None
+
# Now do the actual DNS lookup
try:
ipa = socket.getaddrinfo(hostname, None, family == 4 and socket.AF_INET or
socket.AF_INET6)[0][4][0]
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
new file mode 100644
index 0000000..a0e0e23
--- /dev/null
+++ b/tests/unit/cmk_base/test_config.py
@@ -0,0 +1,26 @@
+import pytest
+
+import cmk_base.config as config
+
+(a)pytest.mark.parametrize("hostname,tags,result"sult", [
+ ("testhost", [], True),
+ ("testhost", ["ip-v4"], True),
+ ("testhost", ["ip-v4", "ip-v6"], True),
+ ("testhost", ["ip-v6"], False),
+ ("testhost", ["no-ip"], False),
+])
+def test_is_ipv4_host(monkeypatch, hostname, tags, result):
+ monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ assert config.is_ipv4_host(hostname) == result
+
+
+(a)pytest.mark.parametrize("hostname,tags,result"sult", [
+ ("testhost", [], False),
+ ("testhost", ["ip-v4"],False),
+ ("testhost", ["ip-v4", "ip-v6"], False),
+ ("testhost", ["ip-v6"], False),
+ ("testhost", ["no-ip"], True),
+])
+def test_is_no_ip_host(monkeypatch, hostname, tags, result):
+ monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ assert config.is_no_ip_host(hostname) == result
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 89109c1..6c895f9 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -6152,6 +6152,7 @@ def register_builtin_host_tags():
("ip-v4-only", _("IPv4 only"), ["ip-v4"]),
("ip-v6-only", _("IPv6 only"), ["ip-v6"]),
("ip-v4v6", _("IPv4/IPv6 dual-stack"),
["ip-v4", "ip-v6"]),
+ ("no-ip", _("No IP"), []),
]
),
]