Set version to 1.5.0b9
[check_mk.git] / inventory / docker_container_network
blobce77be6f841f06602c74c415421ee215a7548957
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2018 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
28 def _parse_docker_container_network(info):
29 import json
30 return json.loads(" ".join(info[0]))
33 def inv_docker_container_network_networks(info, inventory_tree):
34 parsed = _parse_docker_container_network(info)
36 networks = inventory_tree.get_list("software.applications.docker.container.networks:")
38 for network_name, network in parsed["Networks"].items():
39 networks.append({
40 "name" : network_name,
41 "network_id" : network["NetworkID"],
42 "ip_address" : network["IPAddress"],
43 "ip_prefixlen" : network["IPPrefixLen"],
44 "gateway" : network["Gateway"],
45 "mac_address" : network["MacAddress"],
49 inv_info["docker_container_network.networks"] = {
50 "inv_function": inv_docker_container_network_networks,
54 def inv_docker_container_network_ports(info, inventory_tree):
55 parsed = _parse_docker_container_network(info)
57 ports = inventory_tree.get_list("software.applications.docker.container.ports:")
59 for container_port_spec, host_ports in parsed["Ports"].items():
60 port, proto = container_port_spec.split("/", 1)
62 if host_ports:
63 host_addresses = ", ".join([ "%s:%s" % (hp["HostIp"], hp["HostPort"]) for hp in host_ports ])
64 else:
65 host_addresses = ""
67 ports.append({
68 "port" : int(port),
69 "protocol" : proto,
70 "host_addresses" : host_addresses,
74 inv_info["docker_container_network.ports"] = {
75 "inv_function": inv_docker_container_network_ports,