Module: check_mk
Branch: master
Commit: 35ac8516e74ea5ad877056a25b1539e7e6b79ead
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=35ac8516e74ea5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Apr 16 21:48:55 2018 +0200
5983 FIX docker_node_images: Fixed mixups between images of same repository and different
tags
The number of containers was not counted per image because the tag information
was not handled correctly in all cases.
Some containers don't explicitly state "repository:tag" but only
"repository"
as their image, depending on the "docker run" call. Check_MK is now falling
back to "latest" tag in this case.
Change-Id: I2fc33ced414d040eaf9dde683d1478cdc288d653
---
.werks/5983 | 16 ++++++++++++++++
agents/check_mk_agent.linux | 2 +-
inventory/docker_node_images | 24 ++++++++++++++++--------
3 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/.werks/5983 b/.werks/5983
new file mode 100644
index 0000000..053d6fc
--- /dev/null
+++ b/.werks/5983
@@ -0,0 +1,16 @@
+Title: docker_node_images: Fixed mixups between images of same repository and different
tags
+Level: 1
+Component: inv
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1523907880
+
+The number of containers was not counted per image because the tag information
+was not handled correctly in all cases.
+
+Some containers don't explicitly state "repository:tag" but only
"repository"
+as their image, depending on the "docker run" call. Check_MK is now falling
+back to "latest" tag in this case.
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 9682327..1f58f8e 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -976,7 +976,7 @@ if type docker > /dev/null 2>&1 ; then
echo "<<<docker_node_images>>>"
echo "[[[images]]]"
docker images --all --format "{{json .}}"
- for image in $(docker images --all --format "{{.Repository}}");
+ for image in $(docker images --all --format "{{.Repository}}:{{.Tag}}");
do
echo "[[[images_labels:$image]]]"
docker image inspect --format "{{json .Config.Labels}}"
"$image"
diff --git a/inventory/docker_node_images b/inventory/docker_node_images
index 4565a55..c9be7fa 100644
--- a/inventory/docker_node_images
+++ b/inventory/docker_node_images
@@ -35,17 +35,26 @@ def _parse_docker_node_images(info):
continue
data = json.loads(" ".join(line))
+
if section_name == "images":
- parsed.setdefault(data["Repository"], data)
+ parsed.setdefault((data["Repository"], data["Tag"]),
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)
+ parts = section_name.split(":", 2)
+ if len(parts) == 3:
+ repository, tag = parts[1:]
+ image = parsed.get((repository, tag))
+ if image is not None and data:
+ image.setdefault("__labels__", data)
elif section_name == "containers":
- image = parsed.get(data["Image"])
+ image_name = data["Image"]
+ if ":" in image_name:
+ repository, tag = image_name.split(":", 1)
+ else:
+ repository, tag = image_name, "latest"
+
+ image = parsed.get((repository, tag))
if image is not None:
image.setdefault("__containers__", []).append(data)
return parsed
@@ -57,8 +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, image in parsed.iteritems():
- tag = image["Tag"]
+ for (repo, tag), image in parsed.iteritems():
id_ = image["ID"]
inv_node.append({
"repository" : repo,