Module: check_mk
Branch: master
Commit: 4f9232eb571f24c1442e94954bb4b2af364766f9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4f9232eb571f24…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Oct 4 11:42:22 2018 +0200
docker_node_disk_usage: Handle old docker versions
CMK-1031
Change-Id: Ia2084323abeb832a0912b9d09bdbd78ac2ff2d27
---
agents/check_mk_agent.linux | 4 ++--
checks/docker_node_disk_usage | 39 +++++++++++++++++++++++++++------------
2 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 16c1ffb..abe3aee 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -1031,8 +1031,8 @@ if type docker > /dev/null 2>&1 && [ -z
"$MK_IS_PIGGYBACKED" ]; then
echo "<<<docker_node_info:sep(58)>>>"
docker info --format "{{json .}}" || docker info
- echo "<<<docker_node_disk_usage:sep(44)>>>"
- docker system df --format "{{json .}}"
+ echo "<<<docker_node_disk_usage>>>"
+ docker system df --format "{{json .}}" || docker system df
echo "<<<docker_node_images>>>"
echo "[[[images]]]"
diff --git a/checks/docker_node_disk_usage b/checks/docker_node_disk_usage
index 816ac69..eb41fb8 100644
--- a/checks/docker_node_disk_usage
+++ b/checks/docker_node_disk_usage
@@ -23,26 +23,41 @@
# 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.
+import json
-def parse_docker_node_disk_usage(info):
- import json
+def _parse_docker_node_disk_usage_dict(data):
+ key = data.pop('Type').lower()
- parsed = {}
- for line in info:
- data = json.loads(",".join(line))
+ act = data.get('Active')
+ if act is not None:
+ data['Active'] = int(act) if act else 0
- type_ = data.pop('Type').lower()
- parsed[type_] = data
+ tc = data.get('TotalCount') or data.get('Total')
+ if tc is not None:
+ data['TotalCount'] = int(tc) if tc else 0
- data['Active'] = int(data['Active']) if data['Active']
else 0
- data['TotalCount'] = int(data['TotalCount']) if
data['TotalCount'] else 0
- data['Size'] = docker_size_to_bytes(data['Size'])
+ sz = data.get('Size')
+ if sz is not None:
+ data['Size'] = docker_size_to_bytes(sz)
- reclaimable = data['Reclaimable'].split(' ')[0] # discard
percentage
+ rc = data.get('Reclaimable')
+ if rc is not None:
+ reclaimable = rc.split(' ')[0] # discard percentage
data['Reclaimable'] = docker_size_to_bytes(reclaimable)
- return parsed
+ return key, data
+
+
+def parse_docker_node_disk_usage(info):
+ try:
+ data_dicts = [json.loads(" ".join(line)) for line in info]
+ except ValueError:
+ header = [field.title() for field in info[0]]
+ data_dicts = [{k: v for k, v in zip(header, row)}
+ for row in info[1:]]
+
+ return dict(map(_parse_docker_node_disk_usage_dict, data_dicts))
def inventory_docker_node_disk_usage(parsed):