Module: check_mk
Branch: master
Commit: 8c26f192be2e5ff047fafdc29edbf4c1e2239c66
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8c26f192be2e5f…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Feb 7 15:07:20 2019 +0100
docker_container_status: be a bit more robust
Change-Id: Ic2c48f1e6c282ac22860090ae6cf906bff394fac
---
checks/docker_container_status | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/checks/docker_container_status b/checks/docker_container_status
index f94205f..b1c207c 100644
--- a/checks/docker_container_status
+++ b/checks/docker_container_status
@@ -26,13 +26,16 @@
def parse_docker_container_status(info):
+ '''process the first line to a JSON object
+
+ In case there are multiple lines of output sent by the agent only process the first
+ line. We assume that this a full JSON object. The rest of the section is skipped.
+ When a container got piggyback data from multiple hosts (e.g. a cluster) this
results
+ in multiple JSON objects handed over to this check.
+ '''
if not info or not info[0]:
return
- # In case there are multiple lines of output sent by the agent only process the
first
- # line. We assume that this a full JSON object. The rest of the section is skipped.
- # When a container got piggyback data from multiple hosts (e.g. a cluster) this
results
- # in multiple JSON objects handed over to this check.
json_raw_data = " ".join(info[0])
import json
@@ -54,19 +57,19 @@ def parse_docker_container_status(info):
def inventory_docker_container_status_health(parsed):
- if u"Health" in parsed:
- return [(None, None)]
+ if "Health" in parsed:
+ yield None, None
def check_docker_container_status_health(_no_item, _no_params, parsed):
- health_status = parsed.get(u"Health", {}).get(u"Status")
+ health_status = parsed.get("Health", {}).get("Status")
if health_status == "healthy":
return 0, "Healthy"
elif health_status == "starting":
return 1, "Starting"
elif health_status == "unhealthy":
- failing_streak = parsed[u"Health"][u"FailingStreak"]
+ failing_streak = parsed.get("Health",
{}).get("FailingStreak", "not found")
return 2, "Unhealthy - Failing Streak: %d" % failing_streak
return 3, "Health Status '%s' unknown" % health_status
@@ -96,8 +99,8 @@ def check_docker_container_status(_no_item, _no_params, parsed):
yield state, "Status: %s" % status
- if parsed.get(u"Error"):
- yield 2, "Error: %s" % parsed[u"Error"]
+ if parsed.get("Error"):
+ yield 2, "Error: %s" % parsed["Error"]
check_info['docker_container_status'] = {