Module: check_mk
Branch: master
Commit: 6f21f6c526744ff21b76394bf9376f780bc09e55
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6f21f6c526744f…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Feb 7 13:52:30 2019 +0100
docker: preparing for new plugin 2
Change-Id: Iff89ec1c0a56f05f3e7330732af3244a019e9e2d
---
checks/docker.include | 31 +++++++++++++++++++++++++++++++
inventory/docker_container_labels | 3 ++-
inventory/docker_node_images | 12 +++---------
3 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/checks/docker.include b/checks/docker.include
new file mode 100644
index 0000000..fe7230e
--- /dev/null
+++ b/checks/docker.include
@@ -0,0 +1,31 @@
+#!/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 docker_format_labels(labels):
+ if isinstance(labels, dict):
+ labels = labels.iteritems()
+ return ", ".join(["%s: %s" % item for item in labels])
diff --git a/inventory/docker_container_labels b/inventory/docker_container_labels
index beeeb88..00ae4af 100644
--- a/inventory/docker_container_labels
+++ b/inventory/docker_container_labels
@@ -29,9 +29,10 @@ def inv_docker_container_labels(info, inventory_tree):
import json
data = json.loads(" ".join(info[0]))
container =
inventory_tree.get_dict("software.applications.docker.container.")
- container["labels"] = ", ".join(["%s: %s" % (k, v) for
k, v in data.items()])
+ container["labels"] = docker_format_labels(data)
inv_info['docker_container_labels'] = {
+ 'includes': ['docker.include'],
'inv_function': inv_docker_container_labels,
}
diff --git a/inventory/docker_node_images b/inventory/docker_node_images
index 5e8bbb6..b015389 100644
--- a/inventory/docker_node_images
+++ b/inventory/docker_node_images
@@ -39,7 +39,7 @@ def inv_docker_node_images(info, inventory_tree, status_data_tree):
"id": image["ID"],
"creation": image["CreatedAt"],
"size": image["VirtualSize"],
- "labels": _format_labels(image.get("__labels__", {})),
+ "labels": docker_format_labels(image.get("__labels__",
{})),
})
status_node.append({
@@ -59,19 +59,13 @@ def inv_docker_node_images(info, inventory_tree, status_data_tree):
"tag": container["Tag"],
"name": container["Names"],
"creation": container["CreatedAt"],
- "labels": _format_labels(container["Labels"]),
+ "labels": docker_format_labels(container["Labels"]),
"status": container["Status"],
})
-def _format_labels(labels):
- if isinstance(labels, dict):
- labels = labels.iteritems()
- return ", ".join(["%s: %s" % item for item in labels])
-
-
inv_info['docker_node_images'] = {
- 'includes': ['legacy_docker.include'],
+ 'includes': ['docker.include', 'legacy_docker.include'],
'inv_function': inv_docker_node_images,
'has_status_data': True,
}