Cleanup config.nodes_of
[check_mk.git] / inventory / docker_node_info
blobd38bb0f94de28969c68edb9c0672a1e2f4524adb
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 _try_set(node, nkey, data, dkey):
29 if dkey in data:
30 node[nkey] = data[dkey]
33 def inv_docker_node_info(parsed, inventory_tree, status_data_tree):
34 if not parsed:
35 return
37 node = inventory_tree.get_dict("software.applications.docker.")
38 _try_set(node, "version", parsed, u"ServerVersion")
39 _try_set(node, "registry", parsed, "IndexServerAddress")
40 # {"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null}
41 swarm_data = parsed.get("Swarm", {})
42 _try_set(node, "swarm_state", swarm_data, "LocalNodeState")
43 _try_set(node, "swarm_manager", swarm_data, "RemoteManagers")
44 _try_set(node, "swarm_node_id", swarm_data, "NodeID")
46 labels = parsed.get(u"Labels")
47 if labels:
48 node_labels = inventory_tree.get_list("software.applications.docker.node_labels:")
49 node_labels += [{"label": label} for label in labels]
51 status_node = status_data_tree.get_dict("software.applications.docker.")
52 _try_set(status_node, "num_containers_total", parsed, "Containers")
53 _try_set(status_node, "num_containers_running", parsed, "ContainersRunning")
54 _try_set(status_node, "num_containers_paused", parsed, "ContainersPaused")
55 _try_set(status_node, "num_containers_stopped", parsed, "ContainersStopped")
56 _try_set(status_node, "num_images", parsed, "Images")
59 inv_info['docker_node_info'] = {
60 'inv_function': inv_docker_node_info,
61 'has_status_data': True,