Module: check_mk
Branch: master
Commit: d44bbe19e598af22668ff69f6287754abcfd118a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d44bbe19e598af…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Apr 23 07:34:22 2018 +0200
6025 docker_node_network: Inventory information about docker networks
Change-Id: Id015cb46fae8d3a8bcbc7356fd09aa7e89e1fb50
---
.werks/6025 | 10 +++++++
agents/check_mk_agent.linux | 4 +++
inventory/docker_node_network | 68 ++++++++++++++++++++++++++++++++++++++++++
web/plugins/views/inventory.py | 13 ++++++++
4 files changed, 95 insertions(+)
diff --git a/.werks/6025 b/.werks/6025
new file mode 100644
index 0000000..5b89ddb
--- /dev/null
+++ b/.werks/6025
@@ -0,0 +1,10 @@
+Title: docker_node_network: Inventory information about docker networks
+Level: 1
+Component: inv
+Compatible: compat
+Edition: cre
+Version: 1.5.0b2
+Date: 1524388763
+Class: feature
+
+
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 28fb702..4f1738b 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -996,6 +996,10 @@ if type docker > /dev/null 2>&1 ; then
echo "[[[containers]]]"
docker container ls --all --format "{{json .}}"
+ echo "<<<docker_node_network:sep(0)>>>"
+ NETWORK_IDS=$(docker network ls -f 'driver=bridge'
--format='{{.ID}}')
+ docker network inspect "$NETWORK_IDS"
+
# For the container status, we want information about *all* containers
for CONTAINER_ID in $(docker container ls -q --all); do
echo "<<<<${CONTAINER_ID}>>>>"
diff --git a/inventory/docker_node_network b/inventory/docker_node_network
new file mode 100644
index 0000000..0dba8d9
--- /dev/null
+++ b/inventory/docker_node_network
@@ -0,0 +1,68 @@
+#!/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_node_network(info):
+ import json
+ return json.loads("".join([ l[0] for l in info ]))
+
+
+def inv_docker_node_network_networks(info, inventory_tree, status_data_tree):
+ parsed = _parse_docker_node_network(info)
+
+ inventory_networks =
inventory_tree.get_list("software.applications.docker.networks:")
+ status_networks =
status_data_tree.get_list("software.applications.docker.networks:")
+
+ for network in parsed:
+ labels = sorted(["%s: %s" % (k,v) for k,v in
network["Labels"].items()])
+
+ containers = []
+ for container_id, container in network["Containers"].items():
+ containers.append({
+ "name" : container["Name"],
+ "id" : container_id[:12],
+ "ipv4_address" : container["IPv4Address"],
+ "ipv6_address" : container["IPv6Address"],
+ "mac_address" : container["MacAddress"],
+ })
+
+ status_networks.append({
+ "name" : network["Name"],
+ "containers" : containers,
+ })
+
+ inventory_networks.append({
+ "name" : network["Name"],
+ "host_ifname" :
network["Options"]["com.docker.network.bridge.name"],
+ "labels" : ", ".join(labels),
+ "network_id" : network["Id"][:12],
+ "scope" : network["Scope"],
+ })
+
+
+inv_info["docker_node_network.networks"] = {
+ "inv_function": inv_docker_node_network_networks,
+}
diff --git a/web/plugins/views/inventory.py b/web/plugins/views/inventory.py
index 12e69de..add9516 100644
--- a/web/plugins/views/inventory.py
+++ b/web/plugins/views/inventory.py
@@ -706,6 +706,19 @@ inventory_displayhints.update({
"keyorder" : [ "port", "protocol",
"host_addresses" ],
},
+ ".software.applications.docker.networks:*.": {
+ "title": "Network %d",
+ },
+ ".software.applications.docker.networks:*.containers:": {
+ "keyorder" : [ "name", "id",
"ipv4_address", "ipv6_address", "mac_address" ],
+ },
+ ".software.applications.docker.networks:*.containers:*.ipv4_address": {
+ "title" : _("IPv4 address"),
+ },
+ ".software.applications.docker.networks:*.containers:*.ipv6_address": {
+ "title" : _("IPv6 address"),
+ },
+
".software.applications.citrix." : {
"title" : _("Citrix") },
".software.applications.citrix.controller." : {
"title" : _("Controller") },
".software.applications.citrix.controller.controller_version" : {
"title" : _("Controller Version"), },