Module: check_mk
Branch: master
Commit: 9bcf85397bcf8c038a7b3661675d9d2ff59e6985
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9bcf85397bcf8c…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Nov 7 08:45:32 2018 +0100
6837 FIX docker_node_info: Handle unescaped newlines
Previously the check did not handle unescaped newlines,
ultimately resulting in the unhelpful exception "KeyError: 'Swarm'".
Change-Id: I84ffb9afc2444cb979e6f478362af68f1fce37be
---
.werks/6837 | 11 ++++
checks/docker.include | 3 +-
.../generictests/datasets/docker_node_info_2.py | 61 ++++++++++++++++++++++
3 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/.werks/6837 b/.werks/6837
new file mode 100644
index 0000000..608e972
--- /dev/null
+++ b/.werks/6837
@@ -0,0 +1,11 @@
+Title: docker_node_info: Handle unescaped newlines
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1541576572
+Class: fix
+
+Previously the check did not handle unescaped newlines,
+ultimately resulting in the unhelpful exception "KeyError: 'Swarm'".
diff --git a/checks/docker.include b/checks/docker.include
index 78603a8..4670c1f 100644
--- a/checks/docker.include
+++ b/checks/docker.include
@@ -85,7 +85,8 @@ def parse_docker_node_info(info):
if joined.endswith("permission denied"):
return {}
try:
- return json.loads(joined)
+ # this may contain a certificate containing newlines.
+ return json.loads(joined.replace("\n", "\\n"))
except ValueError:
pass
diff --git a/tests/unit/checks/generictests/datasets/docker_node_info_2.py
b/tests/unit/checks/generictests/datasets/docker_node_info_2.py
new file mode 100644
index 0000000..3bd66f8
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/docker_node_info_2.py
@@ -0,0 +1,61 @@
+
+
+checkname = "docker_node_info"
+
+info = [
+ ['{"ID": "XXXX:YYYY:6666","Containers":15,'
+
'"ContainersRunning":6,"ContainersPaused":0,"ContainersStopped":9,"Images":7,'
+
'"Driver":"overlay","DriverStatus":[["Backing',
'Filesystem","xfs"],["Supports',
+
'd_type","true"]],"SystemStatus":null,"Plugins":{"Volume":["local"],'
+
'"Network":["bridge","host"],"Authorization":null,'
+
'"Log":["journald","json-file","splunk","syslog"]},"MemoryLimit":true,'
+ '"SwapLimit":true,"KernelMemory":true,'
+
'"SystemTime":"2000-01-01T01:00:00.000000000+01:00","LoggingDriver":"json-file",'
+
'"CgroupDriver":"cgroupfs","NEventsListener":6,'
+
'"KernelVersion":"3.10.0-666.6.6.el6.x86_64","OperatingSystem":"An',
'awesome',
+
'one","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":4,"MemTotal":16666666666,'
+
'"GenericResources":null,"DockerRootDir":"/data/docker",'
+ '"HttpProxy":"http://proxy.foo:8080",'
+ '"HttpsProxy":"http://proxy.foo:8080",'
+ '"NoProxy":"localhost,', '127.0.0.0/8,',
'66.666.66.666,', '.foo.bar,', '.gee.boo.it",',
+
'"Name":"my_name","Labels":[],"ExperimentalBuild":false,"ServerVersion":"16.06.6-ce",'
+
'"ClusterStore":"","ClusterAdvertise":"","Runtimes":{"runc":{"path":"docker-runc"}},'
+
'"DefaultRuntime":"runc","Swarm":{"NodeID":"66666666666666",'
+
'"NodeAddr":"66.666.66.666","LocalNodeState":"active","ControlAvailable":true,'
+
'"Error":"","RemoteManagers":[{"NodeID":"6666666",'
+
'"Addr":"66.666.66.666:6666"}],"Nodes":2,"Managers":1,'
+
'"Cluster":{"ID":"cluster_id_66666666","Version":{"Index":66666666},'
+ '"CreatedAt":"2016-06-06T06:56:56.66666666Z",'
+
'"UpdatedAt":"2016-12-06T06:56:56.66666666Z","Spec":{"Name":"default","Labels":{},'
+
'"Orchestration":{"TaskHistoryRetentionLimit":5},"Raft":{"SnapshotInterval":10000,'
+
'"KeepOldSnapshots":0,"LogEntriesForSlowFollowers":500,"ElectionTick":10,'
+
'"HeartbeatTick":1},"Dispatcher":{"HeartbeatPeriod":6000000000},'
+
'"CAConfig":{"NodeCertExpiry":6666666666666666},"TaskDefaults":{},'
+
'"EncryptionConfig":{"AutoLockManagers":false}},"TLSInfo":{"TrustRoot":'
+ '"-----BEGIN', 'CERTIFICATE-----\n'
+ 'FoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\n'
+ 'FoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\n'
+ 'FoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\n'
+ 'FoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\n'
+ 'FoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\n'
+ 'FoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\n'
+ 'FoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\n'
+ 'FoobarFoobarFoobarFoobarFoobarFoobarFoobar==\n'
+ '-----END', 'CERTIFICATE-----\n",'
+ '"CertIssuerSubject":"Jim",'
+
'"CertIssuerPublicKey":"odoriuhaoerhaergjhargjkhaejfgasdg=="},'
+
'"RootRotationInProgress":false}},"LiveRestoreEnabled":false,"Isolation":"",'
+
'"InitBinary":"docker-init","ContainerdCommit":'
+ '{"ID":"666666666666666666666666666666666666",'
+
'"Expected":"77777777777777777777777777777777777777777"},'
+
'"RuncCommit":{"ID":"444444444444444444444444444444444444444",'
+
'"Expected":"ffffffffffffffffffffffffffffffffffffffffffffff"},'
+
'"InitCommit":{"ID":"9999999","Expected":"6666666"},'
+ '"SecurityOptions":["name=seccomp,profile=default"]}']
+]
+