Module: check_mk
Branch: master
Commit: 09f72c5e4af24314b6177930828ede03fe64f51d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=09f72c5e4af243…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Jul 5 12:44:56 2018 +0200
Be strict about infotext being a string.
Remove all falsey infotexts from the aggregation
of check results (to avoid multiple commas).
Make sure we consider the check status, even if
the infotext is falsey.
The test classes in checktestlib.py expect infotext
to be of type str *allways*.
Change-Id: Ib99ce305711105726cc4512aeae6046c0cbea760
---
checks/diskstat.include | 2 +-
checks/hivemanager_devices | 6 +++---
checks/lnx_quota | 6 +++---
checks/mkeventd_status | 4 ++--
checks/omd_apache | 2 +-
cmk_base/checking.py | 9 ++++-----
6 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/checks/diskstat.include b/checks/diskstat.include
index c6617dd..9055738 100644
--- a/checks/diskstat.include
+++ b/checks/diskstat.include
@@ -457,4 +457,4 @@ def check_diskstat_dict(item, params, disks):
# Currently the levels are not shown in the perfdata
perfdata.append(("disk_" + key, value))
- yield 0, None, perfdata
+ yield 0, '', perfdata
diff --git a/checks/hivemanager_devices b/checks/hivemanager_devices
index a440041..b0e0cb2 100644
--- a/checks/hivemanager_devices
+++ b/checks/hivemanager_devices
@@ -68,16 +68,16 @@ def check_hivemanager_devices(item, params, info):
levels = ' Warn/Crit at %s/%s' % ( warn, crit )
if number_of_clients >= crit:
- yield 2, infotext+levels, perfdata
+ yield 2, infotext + levels, perfdata
elif number_of_clients >= warn:
- yield 1, infotext+levels, perfdata
+ yield 1, infotext + levels, perfdata
else:
yield 0, infotext, perfdata
# Uptime
state = 0
warn, crit = 0, 0
- infotext = None
+ infotext = ''
uptime_secs = 0
if infos['upTime'] != 'down':
uptime_tokens = map(int, infos['upTime'].split()[-2::-2])
diff --git a/checks/lnx_quota b/checks/lnx_quota
index 0560b0e..bf00db6 100644
--- a/checks/lnx_quota
+++ b/checks/lnx_quota
@@ -110,7 +110,7 @@ def lnx_quota_limit_check(mode, what, user, used, soft, hard, grace):
txt += ', within grace time'
else:
state = 0
- txt = None
+ txt = ''
return state, txt
@@ -161,10 +161,10 @@ def check_lnx_quota(item, params, parsed):
if txt:
at_least_one_problematic = True
- yield state, (txt + ', ')
+ yield state, txt
#yield state, (txt + ', '), perfdata
else:
- yield state, None
+ yield state, ''
#yield state, None, perfdata
if not at_least_one_problematic:
diff --git a/checks/mkeventd_status b/checks/mkeventd_status
index 373bd93..b0ca294 100644
--- a/checks/mkeventd_status
+++ b/checks/mkeventd_status
@@ -119,7 +119,7 @@ def check_mkeventd_status(item, params, parsed):
else:
value = rates["rule_hit"] / rates["rule_trie"] * 100
hit_rate_txt = "%.2f%%" % value
- yield 0, None, [("average_rule_hit_ratio", value)]
+ yield 0, '', [("average_rule_hit_ratio", value)]
yield 0, "%s: %s" % ("Rule hit ratio", hit_rate_txt)
# Time columns
@@ -132,7 +132,7 @@ def check_mkeventd_status(item, params, parsed):
value = status.get("average_%s_time" % name)
if value:
txt = "%.2f ms" % (value * 1000)
- yield 0, None, [("average_%s_time" % name, value)]
+ yield 0, '', [("average_%s_time" % name, value)]
else:
if name == "sync":
continue # skip if not available
diff --git a/checks/omd_apache b/checks/omd_apache
index 073ee03..ac67f5f 100644
--- a/checks/omd_apache
+++ b/checks/omd_apache
@@ -119,7 +119,7 @@ def check_omd_apache(item, _no_params, parsed):
rate = get_rate("omd_apache.%s.%s.%s" % (item, ty, key), this_time,
value,
onwrap=SKIP, is_rate=True)
total += rate
- yield 0, None, [(ty+'_'+key, rate)]
+ yield 0, '', [(ty + '_' + key, rate)]
total = ty == 'bytes' and get_bytes_human_readable(total) or
'%.2f' % total
yield 0, '%s %s' % (total, title)
diff --git a/cmk_base/checking.py b/cmk_base/checking.py
index 9794706..a7362ba 100644
--- a/cmk_base/checking.py
+++ b/cmk_base/checking.py
@@ -365,6 +365,7 @@ def _sanitize_yield_check_result(result, is_snmp):
# Simple check with no separate subchecks (yield wouldn't have been neccessary
here!)
if len(subresults) == 1:
state, infotext, perfdata = _sanitize_tuple_check_result(subresults[0],
allow_missing_infotext=True)
+ # just to be safe - infotext should allways be a string
if infotext == None:
return state, u"", perfdata
else:
@@ -381,15 +382,13 @@ def _sanitize_yield_check_result(result, is_snmp):
for subresult in subresults:
st, text, perf = _sanitize_tuple_check_result(subresult,
allow_missing_infotext=True)
- # FIXME/TODO: Why is the state only aggregated when having text != None?
- if text != None:
- infotexts.append(text + ["", "(!)", "(!!)",
"(?)"][st])
- status = cmk_base.utils.worst_service_state(st, status)
+ infotexts.append(text + ["", "(!)", "(!!)",
"(?)"][st])
+ status = cmk_base.utils.worst_service_state(st, status)
if perf != None:
perfdata += subresult[2]
- return status, ", ".join(infotexts), perfdata
+ return status, ", ".join(i for i in infotexts if i), perfdata
def _item_not_found(is_snmp):