Module: check_mk
Branch: master
Commit: 2d661f63928ad2c3d8c68c3dc72ff005ea9c7ab8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2d661f63928ad2…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Oct 17 15:40:59 2018 +0200
docker: refactoring to minimize differences to 1.5.0
Change-Id: I92dd566a291dc0771579fb95789f9514d0ce51ff
---
checks/docker.include | 77 ++++++++++++++++++++++----------------------
inventory/docker_node_images | 4 +--
2 files changed, 41 insertions(+), 40 deletions(-)
diff --git a/checks/docker.include b/checks/docker.include
index 70e2386..87eb4cd 100644
--- a/checks/docker.include
+++ b/checks/docker.include
@@ -26,6 +26,7 @@
import json
import re
+
def _docker_get_bytes(string):
'''get number of bytes from string
@@ -74,44 +75,6 @@ def _get_repo_tag(string):
return string, "latest"
-def _docker_parse_table(rows, fields, keys):
- '''docker provides us with space separated tables with field containing
spaces
-
- e.g.:
-
- TYPE TOTAL ACTIVE SIZE RECLAIMABLE
- Images 7 6 2.076 GB 936.9 MB (45%)
- Containers 22 0 2.298 GB 2.298 GB (100%)
- Local Volumes 5 5 304 B 0 B (0%)
- '''
- if not rows or not rows[0]:
- return []
-
- indices = []
- for field in fields:
- rex = regex(field + r'\ *')
- m = rex.search(rows[0][0])
- if m is not None:
- start, end = m.start(), m.end()
- if end - start == len(field):
- end = None
- indices.append((start, end))
- else:
- indices.append((0, 0))
-
- table = []
- for row in rows[1:]:
- if not row:
- continue
- try:
- line = {k: row[0][i:j].strip() for k, (i, j) in zip(keys, indices)}
- except IndexError:
- continue
- table.append(line)
-
- return table
-
-
def parse_docker_node_info(info):
'''parse output of "docker info"'''
try:
@@ -166,6 +129,44 @@ def parse_docker_node_info(info):
return parsed
+def _docker_parse_table(rows, fields, keys):
+ '''docker provides us with space separated tables with field containing
spaces
+
+ e.g.:
+
+ TYPE TOTAL ACTIVE SIZE RECLAIMABLE
+ Images 7 6 2.076 GB 936.9 MB (45%)
+ Containers 22 0 2.298 GB 2.298 GB (100%)
+ Local Volumes 5 5 304 B 0 B (0%)
+ '''
+ if not rows or not rows[0]:
+ return []
+
+ indices = []
+ for field in fields:
+ rex = regex(field + r'\ *')
+ m = rex.search(rows[0][0])
+ if m is not None:
+ start, end = m.start(), m.end()
+ if end - start == len(field):
+ end = None
+ indices.append((start, end))
+ else:
+ indices.append((0, 0))
+
+ table = []
+ for row in rows[1:]:
+ if not row:
+ continue
+ try:
+ line = {k: row[0][i:j].strip() for k, (i, j) in zip(keys, indices)}
+ except IndexError:
+ continue
+ table.append(line)
+
+ return table
+
+
def parse_docker_system_df(info):
field_map = (
diff --git a/inventory/docker_node_images b/inventory/docker_node_images
index 8c161c6..8bc367c 100644
--- a/inventory/docker_node_images
+++ b/inventory/docker_node_images
@@ -45,7 +45,7 @@ def inv_docker_node_images(info, inventory_tree, status_data_tree):
"repository" : image["Repository"],
"tag" : image["Tag"],
"id" : image["ID"],
- "amount_containers" : image["amount_containers"], #
len(image.get("__containers__", [])),
+ "amount_containers" : image["amount_containers"],
})
@@ -60,7 +60,7 @@ def inv_docker_node_images_containers(info, inventory_tree,
status_data_tree):
containers = parse_docker_node_images(info).get("containers", {})
status_node =
status_data_tree.get_list("software.applications.docker.containers:")
- for container in sorted(containers.itervalues(), lambda c: c["ID"]):
+ for container in sorted(containers.itervalues(), key=lambda c: c["ID"]):
status_node.append({
"id" : container["ID"],
"repository" : container["Repository"],