Module: check_mk
Branch: master
Commit: 838fc7ede4371a95df6efb3a1c0ba2517bccc96c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=838fc7ede4371a…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Apr 6 15:16:35 2018 +0200
5960 docker_images: Inventorizes information about repository, tag, ID, creation time,
size, labels and the amount of containers of docker images
Change-Id: Iaa2598b4fd518c737371adb0dcd35e67a7786103
---
.werks/5960 | 10 +++++
agents/check_mk_agent.linux | 13 ++++++-
inventory/docker_images | 85 ++++++++++++++++++++++++++++++++++++++++++
web/plugins/views/inventory.py | 6 +++
4 files changed, 113 insertions(+), 1 deletion(-)
diff --git a/.werks/5960 b/.werks/5960
new file mode 100644
index 0000000..0a06e02
--- /dev/null
+++ b/.werks/5960
@@ -0,0 +1,10 @@
+Title: docker_images: Inventorizes information about repository, tag, ID, creation time,
size, labels and the amount of containers of docker images
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i4
+Date: 1523020483
+Class: feature
+
+
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index a7ea57e..4fcb74f 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -60,7 +60,7 @@ SPOOLDIR=$MK_VARDIR/spool
# close standard input (for security reasons) and stderr when not
# explicitly in debug mode.
# When the nodes agent is executed by a e.g. docker node in a container,
-# then don't close stdin, because the agent is piped through it in this
+# then don't close stdin, because the agent is piped through it in this
# case.
if [ "$1" = -d ]
then
@@ -965,6 +965,17 @@ if type docker > /dev/null 2>&1 ; then
echo "<<<docker_node_info>>>"
docker info --format "{{json .}}" 2>&1
+ echo "<<<docker_images>>>"
+ echo "[[[images]]]"
+ docker images --all --format "{{json .}}"
+ for image in $(docker images --all --format "{{.Repository}}");
+ do
+ echo "[[[images_labels:$image]]]"
+ docker image inspect --format "{{json .Config.Labels}}" $image
+ done
+ echo "[[[containers]]]"
+ docker container ls --all --format "{{json .}}"
+
for CONTAINER_ID in $(docker container ls -q); do
echo "<<<<$CONTAINER_ID>>>>"
diff --git a/inventory/docker_images b/inventory/docker_images
new file mode 100644
index 0000000..d6ab2a4
--- /dev/null
+++ b/inventory/docker_images
@@ -0,0 +1,85 @@
+#!/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_images(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
+
+ data = json.loads(" ".join(line))
+ if section_name == "images":
+ data = json.loads(" ".join(line))
+ parsed.setdefault(data["Repository"], data)
+
+ elif section_name.startswith("images_labels"):
+ _, image_id = section_name.split(":", 1)
+ image = parsed.get(image_id)
+ if image is not None and data:
+ image.setdefault("__labels__", data)
+
+ elif section_name == "containers":
+ image = parsed.get(data["Image"])
+ if image is not None:
+ image.setdefault("__containers__", []).append(data)
+ return parsed
+
+
+def inv_docker_images(info, inventory_tree, status_data_tree):
+ parsed = _parse_docker_images(info)
+ path = "software.applications.docker.images:"
+ inv_node = inventory_tree.get_list(path)
+ status_node = status_data_tree.get_list(path)
+
+ for repo, image in parsed.iteritems():
+ tag = image["Tag"]
+ id_ = image["ID"]
+ inv_node.append({
+ "repository" : repo,
+ "tag" : tag,
+ "id" : id_,
+ "creation" : image["CreatedAt"],
+ "size" : image["VirtualSize"],
+ "labels" : ", ".join([": ".join(e)
+ for e in image.get("__labels__",
{}).items()]),
+ })
+
+ status_node.append({
+ "repository" : repo,
+ "tag" : tag,
+ "id" : id_,
+ "amount_containers" : len(image.get("__containers__",
[])),
+ })
+
+
+inv_info['docker_images'] = {
+ 'inv_function' : inv_docker_images,
+ 'has_status_data' : True,
+}
diff --git a/web/plugins/views/inventory.py b/web/plugins/views/inventory.py
index 29d7724..0bc887c 100644
--- a/web/plugins/views/inventory.py
+++ b/web/plugins/views/inventory.py
@@ -776,6 +776,12 @@ inventory_displayhints.update({
},
".software.applications.mssql.instances:*.clustered" : { "title"
: _("Clustered"), "paint" : "mssql_is_clustered"},
+ ".software.applications.docker." : { "title" :
_("Docker") },
+ ".software.applications.docker.images:" : { "title" :
_("Images"),
+ "keyorder":
["repository", "tag", "id", "creation",
"size", "labels", "amount_containers"],
+ },
+ ".software.applications.docker.images:*.id" : { "title" :
_("ID"), },
+
".networking." : { "title" :
_("Networking"), "icon" : "networking" },
".networking.total_interfaces" : { "title" :
_("Interfaces"), "paint" : "count", },
".networking.total_ethernet_ports" : { "title" :
_("Ports"), "paint" : "count", },