Module: check_mk
Branch: master
Commit: bce48510f991d59ee2779e023b8346127c7d97a9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bce48510f991d5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat May 26 18:30:09 2018 +0200
6176 docker_node_images.containers: Show table of containers for docker nodes
When you enable the structured status data in the "HW/SW inventory" ruleset,
you now get a table of docker containers in the inventory tree of docker
nodes.
Change-Id: Ibbe1b96467f28ee231a33754abf734e1d71ed888
---
.werks/6176 | 13 +++++++++
inventory/docker_node_images | 62 ++++++++++++++++++++++++++++++++++++++++--
web/plugins/views/inventory.py | 7 +++++
3 files changed, 79 insertions(+), 3 deletions(-)
diff --git a/.werks/6176 b/.werks/6176
new file mode 100644
index 0000000..e20424f
--- /dev/null
+++ b/.werks/6176
@@ -0,0 +1,13 @@
+Title: docker_node_images.containers: Show table of containers for docker nodes
+Level: 1
+Component: inv
+Class: feature
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1527352133
+
+When you enable the structured status data in the "HW/SW inventory" ruleset,
+you now get a table of docker containers in the inventory tree of docker
+nodes.
diff --git a/inventory/docker_node_images b/inventory/docker_node_images
index 5757723..a260e55 100644
--- a/inventory/docker_node_images
+++ b/inventory/docker_node_images
@@ -66,7 +66,7 @@ def inv_docker_node_images(info, inventory_tree, status_data_tree):
inv_node = inventory_tree.get_list(path)
status_node = status_data_tree.get_list(path)
- for (repo, tag), image in parsed.iteritems():
+ for (repo, tag), image in sorted(parsed.iteritems()):
id_ = image["ID"]
inv_node.append({
"repository" : repo,
@@ -74,8 +74,7 @@ def inv_docker_node_images(info, inventory_tree, status_data_tree):
"id" : id_,
"creation" : image["CreatedAt"],
"size" : image["VirtualSize"],
- "labels" : ", ".join([": ".join(e)
- for e in image.get("__labels__",
{}).items()]),
+ "labels" :
_format_labels(image.get("__labels__", {}).items()),
})
status_node.append({
@@ -90,3 +89,60 @@ inv_info['docker_node_images'] = {
'inv_function' : inv_docker_node_images,
'has_status_data' : True,
}
+
+
+def _parse_docker_node_containers(info):
+ import json
+ parsed = {}
+ section_name = None
+ for line in info:
+ if line[0].startswith("[[[") and line[0].endswith("]]]"):
+ section_name = line[0][3:-3]
+ continue
+
+ if section_name != "containers":
+ continue
+
+ data = json.loads(" ".join(line))
+
+ image_name = data["Image"]
+ if ":" in image_name:
+ data["Repository"], data["Tag"] =
image_name.split(":", 1)
+ else:
+ data["Repository"], data["Tag"] = image_name,
"latest"
+
+ data["Labels"] = [ p.split("=", 1) for p in
data["Labels"].split(",") ]
+
+ parsed[data["ID"]] = data
+
+
+ return parsed
+
+
+def inv_docker_node_images_containers(info, inventory_tree, status_data_tree):
+ parsed = _parse_docker_node_containers(info)
+ status_node =
status_data_tree.get_list("software.applications.docker.containers:")
+
+ for id_, container in sorted(parsed.iteritems()):
+ status_node.append({
+ "id" : id_,
+ "repository" : container["Repository"],
+ "tag" : container["Tag"],
+ "name" : container["Names"],
+ "creation" : container["CreatedAt"],
+ "labels" :
_format_labels(container["Labels"]),
+ "status" : container["Status"],
+ })
+
+
+def _format_labels(labels):
+ return ", ".join([ ": ".join(p) for p in labels ])
+
+# TODO: This section contains also information about the containers. We should
+# better split it into multiple sections and add them to the different plugins
+# using the extra_sections feature. In case this is not possible for the inventory
+# plugins at the moment we should make it possible.
+inv_info['docker_node_images.containers'] = {
+ 'inv_function' : inv_docker_node_images_containers,
+ 'has_status_data' : True,
+}
diff --git a/web/plugins/views/inventory.py b/web/plugins/views/inventory.py
index dce6a50..6eaa7e1 100644
--- a/web/plugins/views/inventory.py
+++ b/web/plugins/views/inventory.py
@@ -777,6 +777,13 @@ inventory_displayhints.update({
".software.applications.docker.images:*.id" : { "title" :
_("ID"), },
".software.applications.docker.images:*.amount_containers" : {
"title" : _("# Containers"), },
+ # Node containers
+ ".software.applications.docker.containers:": {
+ "title" : _("Containers"),
+ "keyorder": ["id", "repository", "tag",
"creation", "name", "creation", "labels",
"status"],
+ "view" : "invdockercontainers_of_host",
+ },
+ ".software.applications.docker.containers:*.id" : {
"title" : _("ID"), },
".software.applications.docker.networks.*.": {
"title": "Network %s",