Module: check_mk
Branch: master
Commit: eb3b46028dd8cfe365fc7eb206f43f51b1ef4f8b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eb3b46028dd8cf…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Fri Oct 12 14:42:00 2018 +0200
Check function decorator: Adjusted for item in parsed but parsed[item] empty
Change-Id: I18d97315821b349fb8bd398ef8e49eb0015b7db9
---
cmk_base/check_api.py | 9 +++++----
tests/unit/cmk_base/test_check_api.py | 5 ++++-
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/cmk_base/check_api.py b/cmk_base/check_api.py
index 888edfa..721ffe5 100644
--- a/cmk_base/check_api.py
+++ b/cmk_base/check_api.py
@@ -492,15 +492,16 @@ def get_parsed_item_data(check_function):
In case of parsed not being a dict the decorator returns 3
(UNKN state) with a wrong usage message.
- In case of item not existing in parsed the decorator gives an
- empty return leading to cmk_base returning 3 (UNKN state) with
- an item not found message (see cmk_base/checking.py).
+ In case of item not existing as a key in parsed or parsed[item]
+ not existing the decorator gives an empty return leading to
+ cmk_base returning 3 (UNKN state) with an item not found message
+ (see cmk_base/checking.py).
"""
@_functools.wraps(check_function)
def wrapped_check_function(item, params, parsed):
if not isinstance(parsed, dict):
return 3, "Wrong usage of decorator function
'get_parsed_item_data': parsed is not a dict"
- if item not in parsed:
+ if item not in parsed or not parsed[item]:
return
return check_function(item, params, parsed[item])
return wrapped_check_function
diff --git a/tests/unit/cmk_base/test_check_api.py
b/tests/unit/cmk_base/test_check_api.py
index 2222e31..a300832 100644
--- a/tests/unit/cmk_base/test_check_api.py
+++ b/tests/unit/cmk_base/test_check_api.py
@@ -12,10 +12,13 @@ def check_foo(item, params, parsed_item_data):
def test_get_parsed_item_data():
params = {}
- parsed = {1: "one"}
+ parsed = {1: "one", 3: {}, 4: [], 5: ""}
info = [[1, "one"], [2, "two"]]
assert check_foo(1, params, parsed) == (2, "bar")
assert check_foo(2, params, parsed) == None
+ assert check_foo(3, params, parsed) == None
+ assert check_foo(4, params, parsed) == None
+ assert check_foo(5, params, parsed) == None
assert check_foo(1, params, info) == (3, "Wrong usage of decorator function
'get_parsed_item_data': parsed is not a dict")
assert check_foo.__name__ == "check_foo"