Module: check_mk
Branch: master
Commit: 1cc1d4622ea9b92b931cdd131429b1de6fda488b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1cc1d4622ea9b9…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Apr 6 17:06:01 2018 +0200
5959 docker_node_info: New check which monitors the status of docker daemon
Change-Id: Ida31b1be0724887a803d10d420f8631806386db0
---
.werks/5959 | 10 +++++++++
agents/check_mk_agent.linux | 3 +++
checkman/docker_node_info | 12 ++++++++++
checks/docker_node_info | 54 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 79 insertions(+)
diff --git a/.werks/5959 b/.werks/5959
new file mode 100644
index 0000000..860951b
--- /dev/null
+++ b/.werks/5959
@@ -0,0 +1,10 @@
+Title: docker_node_info: New check which monitors the status of docker daemon
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i4
+Date: 1523020454
+Class: feature
+
+
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index e102d3a..a7ea57e 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -962,6 +962,9 @@ fi
# Iterate all running containers and report piggyback data for them
if type docker > /dev/null 2>&1 ; then
+ echo "<<<docker_node_info>>>"
+ docker info --format "{{json .}}" 2>&1
+
for CONTAINER_ID in $(docker container ls -q); do
echo "<<<<$CONTAINER_ID>>>>"
diff --git a/checkman/docker_node_info b/checkman/docker_node_info
new file mode 100644
index 0000000..b90895f
--- /dev/null
+++ b/checkman/docker_node_info
@@ -0,0 +1,12 @@
+title: Docker Node Info
+agents: linux
+catalog: app/docker
+license: GPL
+distribution: check_mk
+description:
+ This check monitors the status of the docker application.
+ If the daemon is running, the check is OK, otherwise it is
+ CRIT and displays the error message.
+
+inventory:
+ One service is created.
diff --git a/checks/docker_node_info b/checks/docker_node_info
new file mode 100644
index 0000000..4839273
--- /dev/null
+++ b/checks/docker_node_info
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2018 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+
+def parse_docker_node_info(info):
+ try:
+ import json
+ return json.loads("".join(info[0]))
+ except ValueError:
+ return " ".join(info[0])
+
+
+def inventory_docker_node_info(parsed):
+ if parsed:
+ return [(None, {})]
+
+
+def check_docker_node_info(item, params, parsed):
+ if isinstance(parsed, dict):
+ # TODO use other infos from this section?
+ return 0, 'Daemon running on host %s' % parsed["Name"]
+
+ return 2, parsed
+
+
+check_info['docker_node_info'] = {
+ 'parse_function' : parse_docker_node_info,
+ 'inventory_function' : inventory_docker_node_info,
+ 'check_function' : check_docker_node_info,
+ 'service_description' : 'Docker Node Info',
+}
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", [
+ ("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", [
+ ("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"), []),
]
),
]
Module: check_mk
Branch: master
Commit: c03732e216b5535a084f2034b88f36c8a4c45be7
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c03732e216b553…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Apr 6 16:20:02 2018 +0200
Hand over REMOTE variable to docker container context
Change-Id: I7fc52bb7732a14bc8613e33a62637f1a122373b5
---
agents/check_mk_agent.linux | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index cabbc97..e102d3a 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -972,16 +972,15 @@ if type docker > /dev/null 2>&1 ; then
# the container.
# Once it comes to plugins and custom configuration the user needs to use
# a little more complex setup. Have a look at the documentation.
- # TODO: Hand over REMOTE (and other?) environment variables
AGENT_PATH=$(docker container exec "$CONTAINER_ID" which check_mk_agent 2>/dev/null)
if [ -n "$AGENT_PATH" ]; then
- docker container exec "$CONTAINER_ID" check_mk_agent
+ docker container exec --env "REMOTE=$REMOTE" "$CONTAINER_ID" check_mk_agent
else
# TODO: In case the docker part is added to the official agent script
# erase the hard coded path and replace it with 'basename "$0"'.
# In case the docker stuff remains as plugin, at least replace it with
# to get the agent path $(type check_mk_agent).
- docker container exec --env MK_FROM_NODE=1 -i "$CONTAINER_ID" bash </usr/bin/check_mk_agent
+ docker container exec --env "MK_FROM_NODE=1,REMOTE=$REMOTE" -i "$CONTAINER_ID" bash </usr/bin/check_mk_agent
fi
echo "<<<<>>>>"
Module: check_mk
Branch: master
Commit: 3e21f30e3ff3b47ae2ba9285da1c9c763278503f
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3e21f30e3ff3b4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Apr 6 15:28:10 2018 +0200
Linux agent: Find docker containers and execute agent in context
* In case the agent is running on a docker node, it iterates
all running containers and executes the Check_MK agent in
to context of the container to gather container specific
information.
* In case a check_mk_agent is already installed in the
container, then this agent is executed.
* In case there is no check_mk_agent installed, the agent
of the docker node is executed in the container.
Change-Id: I202c43919cef87a2deecc540424efa9a815af1e0
---
agents/check_mk_agent.linux | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index bca690d..4422ecd 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -952,6 +952,34 @@ if type pvecm > /dev/null 2>&1 ; then
pvecm nodes
fi
+# Iterate all running containers and report piggyback data for them
+if type docker > /dev/null 2>&1 ; then
+ for CONTAINER_ID in $(docker container ls -q); do
+ echo "<<<<$CONTAINER_ID>>>>"
+
+ # Is there a regular agent available in the container? Use it!
+ #
+ # Otherwise execute the agent of the node in the context of the container.
+ # Using this approach we should always get at least basic information from
+ # the container.
+ # Once it comes to plugins and custom configuration the user needs to use
+ # a little more complex setup. Have a look at the documentation.
+ # TODO: Hand over REMOTE (and other?) environment variables
+ AGENT_PATH=$(docker container exec "$CONTAINER_ID" which check_mk_agent 2>/dev/null)
+ if [ -n "$AGENT_PATH" ]; then
+ docker container exec "$CONTAINER_ID" check_mk_agent
+ else
+ # TODO: In case the docker part is added to the official agent script
+ # erase the hard coded path and replace it with 'basename "$0"'.
+ # In case the docker stuff remains as plugin, at least replace it with
+ # to get the agent path $(type check_mk_agent).
+ docker container exec --env MK_FROM_NODE=1 -i "$CONTAINER_ID" bash </usr/bin/check_mk_agent
+ fi
+
+ echo "<<<<>>>>"
+ done
+fi
+
# Start new liveupdate process in background on each agent execution. Starting
# a new live update process will terminate the old one automatically after
# max. 1 sec.