2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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 inventory_docker_node_info(parsed
):
29 if parsed
and isinstance(parsed
, dict):
33 def check_docker_node_info(item
, params
, parsed
):
34 if isinstance(parsed
, dict):
35 # TODO use other infos from this section?
36 return 0, 'Daemon running on host %s' % parsed
["Name"]
41 check_info
['docker_node_info'] = {
42 'includes': ['docker.include'],
43 'parse_function': parse_docker_node_info
,
44 'inventory_function': inventory_docker_node_info
,
45 'check_function': check_docker_node_info
,
46 'service_description': 'Docker node info',
50 def inventory_docker_node_containers(parsed
):
51 if parsed
and isinstance(parsed
, dict):
55 def check_docker_node_containers(item
, params
, parsed
):
56 if not isinstance(parsed
, dict):
57 # String with error message in case the daemon is not running
60 def check_node_levels(count
, warn
, crit
, warn_lower
, crit_lower
):
61 if crit
is not None and count
>= crit
:
62 return 2, " (warn/crit at %s/%s)" % (warn
, crit
)
63 if crit_lower
is not None and count
< crit_lower
:
64 return 2, " (warn/crit below %s/%s)" % (warn_lower
, crit_lower
)
65 if warn
is not None and count
>= warn
:
66 return 1, " (warn/crit at %s/%s)" % (warn
, crit
)
67 if warn_lower
is not None and count
< warn_lower
:
68 return 1, " (warn/crit below %s/%s)" % (warn_lower
, crit_lower
)
71 for title
, key
, upper_name
, lower_name
in (
72 ("containers", "Containers", 'upper_levels', 'lower_levels'),
73 ("running", "ContainersRunning", 'running_upper_levels', 'running_lower_levels'),
74 ("paused", "ContainersPaused", 'paused_upper_levels', 'paused_lower_levels'),
75 ("stopped", "ContainersStopped", 'stopped_upper_levels', 'stopped_lower_levels'),
77 raw_count
= parsed
.get(key
)
79 yield 3, "%s: count not present in agent output" % title
81 count
= int(raw_count
)
83 warn
, crit
= params
.get(upper_name
, (None, None))
84 lower_warn
, lower_crit
= params
.get(lower_name
, (None, None))
86 status
, level_text
= check_node_levels(count
, warn
, crit
, lower_warn
, lower_crit
)
87 infotext
= "%s: %d" % (title
, count
)
89 infotext
+= level_text
90 perfdata
= [(title
.lower(), count
, warn
, crit
, lower_warn
, lower_crit
)]
92 yield status
, infotext
, perfdata
95 check_info
["docker_node_info.containers"] = {
96 "inventory_function": inventory_docker_node_containers
,
97 "check_function": check_docker_node_containers
,
98 "service_description": "Docker containers",
100 "group": "docker_node_containers",