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'] = {
Module: check_mk
Branch: master
Commit: a3637595f70a21d91f6de785cadf5ffd3b7580d4
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a3637595f70a21…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Thu Feb 7 14:07:21 2019 +0100
Bug fix for sorter name of painter when painter spec has parameters
Some refactoring to isolate functions
Change-Id: I80bbe5e19bf5aa3c2b485d52c702577961d31950
---
cmk/gui/plugins/views/utils.py | 48 ++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/cmk/gui/plugins/views/utils.py b/cmk/gui/plugins/views/utils.py
index 9eb4070..9288a03 100644
--- a/cmk/gui/plugins/views/utils.py
+++ b/cmk/gui/plugins/views/utils.py
@@ -33,6 +33,7 @@ import time
import re
import hashlib
import traceback
+import six
import livestatus
@@ -1559,18 +1560,23 @@ def _transform_old_views(all_views):
# '----------------------------------------------------------------------'
+def extract_painter_name(painter_spec):
+ if isinstance(painter_spec[0], tuple):
+ return painter_spec[0][0]
+ if isinstance(painter_spec, tuple):
+ return painter_spec[0]
+ if isinstance(painter_spec, six.string_types):
+ return painter_spec
+
+
+def painter_exists(painter_spec):
+ painter_name = extract_painter_name(painter_spec)
+
+ return painter_name in painter_registry
+
+
# A cell is an instance of a painter in a view (-> a cell or a grouping cell)
class Cell(object):
- # Wanted to have the "parse painter spec logic" in one place (The Cell() class)
- # but this should be cleaned up more. TODO: Move this to another place
- @staticmethod
- def painter_exists(painter_spec):
- if isinstance(painter_spec[0], tuple):
- painter_name = painter_spec[0][0]
- else:
- painter_name = painter_spec[0]
-
- return painter_name in painter_registry
# Wanted to have the "parse painter spec logic" in one place (The Cell() class)
# but this should be cleaned up more. TODO: Move this to another place
@@ -1606,16 +1612,14 @@ class Cell(object):
# Same as above but instead of the "Painter name" a two element tuple with the painter name as
# first element and a dictionary of parameters as second element is set.
def _from_view(self, painter_spec):
+ self._painter_name = extract_painter_name(painter_spec)
if isinstance(painter_spec[0], tuple):
- self._painter_name, self._painter_params = painter_spec[0]
- else:
- self._painter_name = painter_spec[0]
+ self._painter_params = painter_spec[0][1]
if painter_spec[1] is not None:
self._link_view_name = painter_spec[1]
- # Clean this call to Cell.painter_exists() up!
- if len(painter_spec) >= 3 and Cell.painter_exists((painter_spec[2], None)):
+ if len(painter_spec) >= 3 and painter_spec[2] in painter_registry:
self._tooltip_painter_name = painter_spec[2]
# Get a list of columns we need to fetch in order to render this cell
@@ -1944,7 +1948,7 @@ class EmptyCell(Cell):
def get_cells(view):
cells = []
for e in view["painters"]:
- if not Cell.painter_exists(e):
+ if not painter_exists(e):
continue
if Cell.is_join_cell(e):
@@ -1957,7 +1961,7 @@ def get_cells(view):
def get_group_cells(view):
- return [Cell(view, e) for e in view["group_painters"] if Cell.painter_exists(e)]
+ return [Cell(view, e) for e in view["group_painters"] if painter_exists(e)]
def output_csv_headers(view):
@@ -1968,20 +1972,22 @@ def output_csv_headers(view):
html.response.headers["Content-Disposition"] = "Attachment; filename=\"%s\"" % filename
-def get_sorter_name_of_painter(painter_name):
+def get_sorter_name_of_painter(painter_name_or_spec):
+ painter_name = extract_painter_name(painter_name_or_spec)
painter = painter_registry[painter_name]()
if painter.sorter:
return painter.sorter
- elif painter_name in sorter_registry:
+ if painter_name in sorter_registry:
return painter_name
+
return None
def get_separated_sorters(view):
- group_sort = [(get_sorter_name_of_painter(p[0]), False)
+ group_sort = [(get_sorter_name_of_painter(p), False)
for p in view['group_painters']
- if p[0] in painter_registry and get_sorter_name_of_painter(p[0]) is not None]
+ if painter_exists(p) and get_sorter_name_of_painter(p) is not None]
view_sort = [s for s in view['sorters'] if not s[0] in group_sort]
# Get current url individual sorters. Parse the "sort" url parameter,