Module: check_mk
Branch: master
Commit: 1b635f1ac31e92f5c296c483326880efda052af9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1b635f1ac31e92…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Mon Feb 11 13:51:18 2019 +0100
mk_docker: extend new include file
Change-Id: I927f3842a40eb845e6fab1bb375080efd48c9a9d
---
checks/docker.include | 24 +++++++++++++++++++++++-
checks/docker_container_status | 7 ++++---
inventory/docker_node_network | 24 +++++++++++++++---------
3 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/checks/docker.include b/checks/docker.include
index fe7230e..21f60b0 100644
--- a/checks/docker.include
+++ b/checks/docker.include
@@ -23,9 +23,31 @@
# 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.
+import json
+
+
+def docker_json_get_obj(line):
+ '''return one json object (or None)'''
+ try:
+ return json.loads(" ".join(line))
+ except ValueError:
+ return None
+
+
+def docker_get_version(info):
+ try:
+ if info[0][0] == '@docker_version_info':
+ return json.loads(info[0][1])
+ except IndexError:
+ pass
+ return None
+
+
+def docker_get_short_id(string):
+ return string.split(":", 1)[-1][:12]
def docker_format_labels(labels):
if isinstance(labels, dict):
labels = labels.iteritems()
- return ", ".join(["%s: %s" % item for item in labels])
+ return ", ".join("%s: %s" % item for item in sorted(labels))
diff --git a/checks/docker_container_status b/checks/docker_container_status
index b1c207c..9a22335 100644
--- a/checks/docker_container_status
+++ b/checks/docker_container_status
@@ -36,10 +36,9 @@ def parse_docker_container_status(info):
if not info or not info[0]:
return
- json_raw_data = " ".join(info[0])
+ parsed = docker_json_get_obj(info[0]) or {}
- import json
- return json.loads(json_raw_data)
+ return parsed
#.
@@ -78,6 +77,7 @@ check_info["docker_container_status.health"] = {
"inventory_function": inventory_docker_container_status_health,
"check_function": check_docker_container_status_health,
"service_description": "Docker container health",
+ 'includes': ['docker.include'],
}
#.
@@ -108,4 +108,5 @@ check_info['docker_container_status'] = {
'inventory_function': discover_single,
'check_function': check_docker_container_status,
'service_description': 'Docker container status',
+ 'includes': ['docker.include'],
}
diff --git a/inventory/docker_node_network b/inventory/docker_node_network
index f2d58dc..cf21855 100644
--- a/inventory/docker_node_network
+++ b/inventory/docker_node_network
@@ -25,15 +25,21 @@
# Boston, MA 02110-1301 USA.
+def parse_docker_network(info):
+
+ networks = parse_legacy_docker_network_inspect(info) # pylint:
disable=undefined-variable
+ return dict((n["Id"], n) for n in networks)
+
+
def inv_docker_node_network_networks(info, inventory_tree, status_data_tree):
- parsed = parse_legacy_docker_network_inspect(info)
- for network in parsed:
+ parsed = parse_docker_network(info)
+ for network_id, network in parsed.iteritems():
containers = []
- for container_id, container in network["Containers"].items():
+ for container_id, container in network["Containers"].iteritems():
containers.append({
"name": container["Name"],
- "id": _legacy_docker_trunk_id(container_id),
+ "id": docker_get_short_id(container_id), # pylint:
disable=undefined-variable
"ipv4_address": container["IPv4Address"],
"ipv6_address": container["IPv6Address"],
"mac_address": container["MacAddress"],
@@ -53,7 +59,7 @@ def inv_docker_node_network_networks(info, inventory_tree,
status_data_tree):
network_ = {
"name": network_name,
- "network_id": _legacy_docker_trunk_id(network["Id"]),
+ "network_id": docker_get_short_id(network_id), # pylint:
disable=undefined-variable
"scope": network["Scope"],
}
@@ -62,13 +68,13 @@ def inv_docker_node_network_networks(info, inventory_tree,
status_data_tree):
except KeyError:
pass
- labels = sorted(["%s: %s" % (k, v) for k, v in
network.get("Labels", {}).items()])
+ labels = docker_format_labels(network.get("Labels", {}))
if labels:
- network_["labels"] = ", ".join(labels)
+ network_["labels"] = labels
inventory_networks.update(network_)
-inv_info["docker_node_network.networks"] = {
- "includes": ["legacy_docker.include"],
+inv_info["docker_node_network.networks"] = { # pylint:
disable=undefined-variable
+ "includes": ["docker.include",
"legacy_docker.include"],
"inv_function": inv_docker_node_network_networks,
}