Module: check_mk
Branch: master
Commit: c2c32ef420a2c99b88c07a3a0ded61a9d11103a6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c2c32ef420a2c9…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Oct 4 10:56:44 2018 +0200
docker_node_info: Handle old docker versions
CMK-1031
Change-Id: I246b21cdbff61dea03404c38d55740b9c998ece4
---
agents/check_mk_agent.linux | 4 +-
checks/docker_node_info | 31 +++++-
.../datasets/docker_node_info_old_verison.py | 80 +++++++++++++
.../datasets/docker_node_info_regression.py | 124 +++++++++++++++++++++
4 files changed, 234 insertions(+), 5 deletions(-)
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 93407d0..16c1ffb 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -1028,8 +1028,8 @@ fi
# Iterate all running containers and report piggyback data for them
if type docker > /dev/null 2>&1 && [ -z "$MK_IS_PIGGYBACKED"
]; then
- echo "<<<docker_node_info>>>"
- docker info --format "{{json .}}" 2>&1
+ echo "<<<docker_node_info:sep(58)>>>"
+ docker info --format "{{json .}}" || docker info
echo "<<<docker_node_disk_usage:sep(44)>>>"
docker system df --format "{{json .}}"
diff --git a/checks/docker_node_info b/checks/docker_node_info
index 7a2cd36..8c368bc 100644
--- a/checks/docker_node_info
+++ b/checks/docker_node_info
@@ -25,12 +25,37 @@
# Boston, MA 02110-1301 USA.
+import json
+
+
+def parse_docker_node_info_nojson(info):
+ parsed = {}
+ prefix = ""
+ for row in info:
+ if not row:
+ continue
+ # ignore misssing keys / pad lines that are not of "key: value" type
+ if len(row) == 1:
+ row.append('')
+ key = row[0].strip()
+ value = ':'.join(row[1:]).strip()
+ # indented keys are prefixed by the last not indented key
+ # this does the right thing in the cases used below.
+ indent = len(row[0]) - len(key)
+ if indent == 0:
+ parsed[key] = value
+ prefix = key
+ else:
+ parsed[prefix + key] = value
+
+ return parsed
+
+
def parse_docker_node_info(info):
try:
- import json
- return json.loads("".join(info[0]))
+ return json.loads(":".join(info[0]))
except ValueError:
- return " ".join(info[0])
+ return parse_docker_node_info_nojson(info)
def inventory_docker_node_info(parsed):
diff --git a/tests/unit/checks/generictests/datasets/docker_node_info_old_verison.py
b/tests/unit/checks/generictests/datasets/docker_node_info_old_verison.py
new file mode 100644
index 0000000..edad095
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/docker_node_info_old_verison.py
@@ -0,0 +1,80 @@
+
+
+checkname = 'docker_node_info'
+
+
+info = [['Containers', ' 0'],
+ [' Running', ' 0'],
+ [' Paused', ' 0'],
+ [' Stopped', ' 0'],
+ ['Images', ' 0'],
+ ['Server Version', ' 18.06.1-ce'],
+ ['Storage Driver', ' overlay2'],
+ [' Backing Filesystem', ' extfs'],
+ [' Supports d_type', ' true'],
+ [' Native Overlay Diff', ' true'],
+ ['Logging Driver', ' json-file'],
+ ['Cgroup Driver', ' cgroupfs'],
+ ['Plugins', ''],
+ [' Volume', ' local'],
+ [' Network', ' bridge host macvlan null overlay'],
+ [' Log',
+ ' awslogs fluentd gcplogs gelf journald json-file logentries splunk
syslog'],
+ ['Swarm', ' inactive'],
+ ['Runtimes', ' runc'],
+ ['Default Runtime', ' runc'],
+ ['Init Binary', ' docker-init'],
+ ['containerd version', '
468a545b9edcd5932818eb9de8e72413e616e86e'],
+ ['runc version', ' 69663f0bd4b60df09991c08812a60108003fa340'],
+ ['init version', ' fec3683'],
+ ['Security Options', ''],
+ [' apparmor', ''],
+ [' seccomp', ''],
+ [' Profile', ' default'],
+ ['Kernel Version', ' 4.15.0-36-generic'],
+ ['Operating System', ' Ubuntu 18.04.1 LTS'],
+ ['OSType', ' linux'],
+ ['Architecture', ' x86_64'],
+ ['CPUs', ' 8'],
+ ['Total Memory', ' 15.54GiB'],
+ ['Name', ' klappson'],
+ ['ID',
+ ' VAW5',
+ 'RDCA',
+ 'ATG7',
+ '24TV',
+ 'Q7IJ',
+ 'L33R',
+ 'U5MX',
+ 'XKXN',
+ 'Z77K',
+ 'AR22',
+ 'QUE6',
+ '3JGL'],
+ ['Docker Root Dir', ' /var/lib/docker'],
+ ['Debug Mode (client)', ' false'],
+ ['Debug Mode (server)', ' false'],
+ ['Registry', ' https', '//index.docker.io/v1/'],
+ ['Labels', ''],
+ ['Experimental', ' false'],
+ ['Insecure Registries', ''],
+ [' 127.0.0.0/8', ''],
+ ['Live Restore Enabled', ' false']]
+
+
+discovery = {'': [(None, {})], 'containers': [(None, {})]}
+
+
+checks = {'': [(None, 'default', [(0, u'Daemon running on host
klappson', [])])],
+ 'containers': [(None,
+ 'default',
+ [(0,
+ 'containers: 0',
+ [('containers', 0, None, None, None, None)]),
+ (0,
+ 'running: 0',
+ [('running', 0, None, None, None, None)]),
+ (0, 'paused: 0', [('paused', 0, None, None,
None, None)]),
+ (0,
+ 'stopped: 0',
+ [('stopped', 0, None, None, None, None)])])]}
diff --git a/tests/unit/checks/generictests/datasets/docker_node_info_regression.py
b/tests/unit/checks/generictests/datasets/docker_node_info_regression.py
new file mode 100644
index 0000000..3ed9f7d
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/docker_node_info_regression.py
@@ -0,0 +1,124 @@
+
+
+checkname = 'docker_node_info'
+
+
+info = [['{"ID"',
+ '"VAW5',
+ 'RDCA',
+ 'ATG7',
+ '24TV',
+ 'Q7IJ',
+ 'L33R',
+ 'U5MX',
+ 'XKXN',
+ 'Z77K',
+ 'AR22',
+ 'QUE6',
+ '3JGL","Containers"',
+ '0,"ContainersRunning"',
+ '0,"ContainersPaused"',
+ '0,"ContainersStopped"',
+ '0,"Images"',
+ '0,"Driver"',
+ '"overlay2","DriverStatus"',
+ '[["Backing Filesystem","extfs"],["Supports
d_type","true"],["Native Overlay
Diff","true"]],"SystemStatus"',
+ 'null,"Plugins"',
+ '{"Volume"',
+ '["local"],"Network"',
+
'["bridge","host","macvlan","null","overlay"],"Authorization"',
+ 'null,"Log"',
+
'["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit"',
+ 'true,"SwapLimit"',
+ 'false,"KernelMemory"',
+ 'true,"CpuCfsPeriod"',
+ 'true,"CpuCfsQuota"',
+ 'true,"CPUShares"',
+ 'true,"CPUSet"',
+ 'true,"IPv4Forwarding"',
+ 'true,"BridgeNfIptables"',
+ 'true,"BridgeNfIp6tables"',
+ 'true,"Debug"',
+ 'false,"NFd"',
+ '22,"OomKillDisable"',
+ 'true,"NGoroutines"',
+ '43,"SystemTime"',
+ '"2018-10-04T08',
+ '47',
+ '40.954398342+02',
+ '00","LoggingDriver"',
+ '"json-file","CgroupDriver"',
+ '"cgroupfs","NEventsListener"',
+ '0,"KernelVersion"',
+ '"4.15.0-36-generic","OperatingSystem"',
+ '"Ubuntu 18.04.1 LTS","OSType"',
+ '"linux","Architecture"',
+ '"x86_64","IndexServerAddress"',
+ '"https',
+ '//index.docker.io/v1/","RegistryConfig"',
+ '{"AllowNondistributableArtifactsCIDRs"',
+ '[],"AllowNondistributableArtifactsHostnames"',
+ '[],"InsecureRegistryCIDRs"',
+ '["127.0.0.0/8"],"IndexConfigs"',
+ '{"docker.io"',
+ '{"Name"',
+ '"docker.io","Mirrors"',
+ '[],"Secure"',
+ 'true,"Official"',
+ 'true}},"Mirrors"',
+ '[]},"NCPU"',
+ '8,"MemTotal"',
+ '16690192384,"GenericResources"',
+ 'null,"DockerRootDir"',
+ '"/var/lib/docker","HttpProxy"',
+ '"","HttpsProxy"',
+ '"","NoProxy"',
+ '"","Name"',
+ '"klappson","Labels"',
+ '[],"ExperimentalBuild"',
+ 'false,"ServerVersion"',
+ '"18.06.1-ce","ClusterStore"',
+ '"","ClusterAdvertise"',
+ '"","Runtimes"',
+ '{"runc"',
+ '{"path"',
+ '"docker-runc"}},"DefaultRuntime"',
+ '"runc","Swarm"',
+ '{"NodeID"',
+ '"","NodeAddr"',
+ '"","LocalNodeState"',
+ '"inactive","ControlAvailable"',
+ 'false,"Error"',
+ '"","RemoteManagers"',
+ 'null},"LiveRestoreEnabled"',
+ 'false,"Isolation"',
+ '"","InitBinary"',
+ '"docker-init","ContainerdCommit"',
+ '{"ID"',
+
'"468a545b9edcd5932818eb9de8e72413e616e86e","Expected"',
+
'"468a545b9edcd5932818eb9de8e72413e616e86e"},"RuncCommit"',
+ '{"ID"',
+
'"69663f0bd4b60df09991c08812a60108003fa340","Expected"',
+
'"69663f0bd4b60df09991c08812a60108003fa340"},"InitCommit"',
+ '{"ID"',
+ '"fec3683","Expected"',
+ '"fec3683"},"SecurityOptions"',
+
'["name=apparmor","name=seccomp,profile=default"]}']]
+
+
+discovery = {'': [(None, {})], 'containers': [(None, {})]}
+
+
+checks = {'': [(None, 'default', [(0, u'Daemon running on host
klappson', [])])],
+ 'containers': [(None,
+ 'default',
+ [(0,
+ 'containers: 0',
+ [('containers', 0, None, None, None, None)]),
+ (0,
+ 'running: 0',
+ [('running', 0, None, None, None, None)]),
+ (0, 'paused: 0', [('paused', 0, None, None,
None, None)]),
+ (0,
+ 'stopped: 0',
+ [('stopped', 0, None, None, None, None)])])]}
\ No newline at end of file