Module: check_mk
Branch: master
Commit: 78146957ae75c8ce630c095de7aa013d05d4554e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=78146957ae75c8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Apr 23 07:22:10 2018 +0200
6024 docker_container_network: Show nodes networks and ports
Change-Id: Ib81a13e403006c9da20c7d9ca023c6c9340de9ea
---
.werks/6024 | 10 +++++
agents/check_mk_agent.linux | 4 ++
inventory/docker_container_labels | 4 +-
inventory/docker_container_network | 76 ++++++++++++++++++++++++++++++++++++++
web/plugins/views/inventory.py | 16 ++++++++
5 files changed, 108 insertions(+), 2 deletions(-)
diff --git a/.werks/6024 b/.werks/6024
new file mode 100644
index 0000000..dbbf4e3
--- /dev/null
+++ b/.werks/6024
@@ -0,0 +1,10 @@
+Title: docker_container_network: Show nodes networks and ports
+Level: 1
+Component: inv
+Compatible: compat
+Edition: cre
+Version: 1.5.0b2
+Date: 1524345439
+Class: feature
+
+
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index b172403..28fb702 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -1007,6 +1007,10 @@ if type docker > /dev/null 2>&1 ; then
echo "<<<docker_container_labels>>>"
docker inspect "$CONTAINER_ID" --format='{{json
.Config.Labels}}'
+
+ echo "<<<docker_container_network>>>"
+ docker inspect "$CONTAINER_ID" --format='{{json
.NetworkSettings}}'
+
echo "<<<<>>>>"
done
diff --git a/inventory/docker_container_labels b/inventory/docker_container_labels
index 1469423..9b0021d 100644
--- a/inventory/docker_container_labels
+++ b/inventory/docker_container_labels
@@ -28,8 +28,8 @@
def inv_docker_container_labels(info, inventory_tree):
import json
data = json.loads(" ".join(info[0]))
- container_labels =
inventory_tree.get_dict("software.applications.docker.container.")
- container_labels["labels"] = ", ".join(["%s: %s" %
(k,v) for k,v in data.items()])
+ container =
inventory_tree.get_dict("software.applications.docker.container.")
+ container["labels"] = ", ".join(["%s: %s" % (k,v) for
k,v in data.items()])
inv_info['docker_container_labels'] = {
diff --git a/inventory/docker_container_network b/inventory/docker_container_network
new file mode 100644
index 0000000..ce77be6
--- /dev/null
+++ b/inventory/docker_container_network
@@ -0,0 +1,76 @@
+#!/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_container_network(info):
+ import json
+ return json.loads(" ".join(info[0]))
+
+
+def inv_docker_container_network_networks(info, inventory_tree):
+ parsed = _parse_docker_container_network(info)
+
+ networks =
inventory_tree.get_list("software.applications.docker.container.networks:")
+
+ for network_name, network in parsed["Networks"].items():
+ networks.append({
+ "name" : network_name,
+ "network_id" : network["NetworkID"],
+ "ip_address" : network["IPAddress"],
+ "ip_prefixlen" : network["IPPrefixLen"],
+ "gateway" : network["Gateway"],
+ "mac_address" : network["MacAddress"],
+ })
+
+
+inv_info["docker_container_network.networks"] = {
+ "inv_function": inv_docker_container_network_networks,
+}
+
+
+def inv_docker_container_network_ports(info, inventory_tree):
+ parsed = _parse_docker_container_network(info)
+
+ ports =
inventory_tree.get_list("software.applications.docker.container.ports:")
+
+ for container_port_spec, host_ports in parsed["Ports"].items():
+ port, proto = container_port_spec.split("/", 1)
+
+ if host_ports:
+ host_addresses = ", ".join([ "%s:%s" %
(hp["HostIp"], hp["HostPort"]) for hp in host_ports ])
+ else:
+ host_addresses = ""
+
+ ports.append({
+ "port" : int(port),
+ "protocol" : proto,
+ "host_addresses" : host_addresses,
+ })
+
+
+inv_info["docker_container_network.ports"] = {
+ "inv_function": inv_docker_container_network_ports,
+}
diff --git a/web/plugins/views/inventory.py b/web/plugins/views/inventory.py
index e7098f1..12e69de 100644
--- a/web/plugins/views/inventory.py
+++ b/web/plugins/views/inventory.py
@@ -690,6 +690,22 @@ inventory_displayhints.update({
},
".software.applications.check_mk.cluster.nodes:" : {
"title" : _("Nodes"),},
+ ".software.applications.docker.container.": {
+ "title" : _("Container"),
+ },
+ ".software.applications.docker.container.node_name": {
+ "title" : _("Node name"),
+ },
+ ".software.applications.docker.container.networks:": {
+ "title" : _("Networks"),
+ "keyorder" : [ "name", "ip_address",
"ip_prefixlen", "gateway",
+ "mac_address", "network_id" ],
+ },
+ ".software.applications.docker.container.ports:": {
+ "title" : _("Ports"),
+ "keyorder" : [ "port", "protocol",
"host_addresses" ],
+ },
+
".software.applications.citrix." : {
"title" : _("Citrix") },
".software.applications.citrix.controller." : {
"title" : _("Controller") },
".software.applications.citrix.controller.controller_version" : {
"title" : _("Controller Version"), },