Module: check_mk
Branch: master
Commit: 57b82eb1e03fb3d464575d29a680cac42e4f5022
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=57b82eb1e03fb3…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Mon Jan 21 12:55:40 2019 +0100
lnx_thermal: use get_parsed_item_data decorator
Add a regression test and reformat the existing regression tests, as
well.
Change-Id: I4e889660bfb3ce13e832716731de5ce45fb72994
---
checks/lnx_thermal | 11 +--
.../checks/generictests/datasets/lnx_thermal.py | 83 +++++++++++++++-------
2 files changed, 65 insertions(+), 29 deletions(-)
diff --git a/checks/lnx_thermal b/checks/lnx_thermal
index 8386532..f01808d 100644
--- a/checks/lnx_thermal
+++ b/checks/lnx_thermal
@@ -86,7 +86,8 @@ def inventory_lnx_thermal(parsed):
yield item, {}
-def check_lnx_thermal(item, params, parsed):
+@get_parsed_item_data
+def check_lnx_thermal(item, params, data):
"""
- Trip points hot and critical are considered for the device crit level. In case both
trip
points are given the lower value is considered for the device crit level.
@@ -95,10 +96,10 @@ def check_lnx_thermal(item, params, parsed):
is considered for the device crit level.
- Trip point temperatures are provided via performance data.
"""
- temperature = parsed.get(item).get('temperature')
- warn_level = parsed.get(item).get('passive')
- hot_value = parsed.get(item).get('hot')
- critical_value = parsed.get(item).get('critical')
+ temperature = data.get('temperature')
+ warn_level = data.get('passive')
+ hot_value = data.get('hot')
+ critical_value = data.get('critical')
if temperature is None:
return
diff --git a/tests/unit/checks/generictests/datasets/lnx_thermal.py
b/tests/unit/checks/generictests/datasets/lnx_thermal.py
index 3def5af..fbb2173 100644
--- a/tests/unit/checks/generictests/datasets/lnx_thermal.py
+++ b/tests/unit/checks/generictests/datasets/lnx_thermal.py
@@ -19,28 +19,63 @@ discovery = {
}
checks = {
- '': [('Zone 0', {
- 'device_levels_handling': 'devdefault',
- 'levels': (70.0, 80.0)
- }, [(0, u'57.0 \xb0C', [('temp', 57.0, 127.0, 127.0, None,
None)])]),
- ('Zone 1', {
- 'device_levels_handling': 'devdefault',
- 'levels': (70.0, 80.0)
- }, [(0, u'65.0 \xb0C', [('temp', 65.0, 95.5, 100.0, None,
None)])]),
- ('Zone 2', {
- 'device_levels_handling': 'devdefault',
- 'levels': (70.0, 80.0)
- }, [(0, u'44.0 \xb0C', [('temp', 44.0, 70.0, 80.0, None,
None)])]),
- ('Zone 3', {
- 'device_levels_handling': 'devdefault',
- 'levels': (70.0, 80.0)
- }, [(0, u'48.0 \xb0C', [('temp', 48.0, 77.0, 87.0, None,
None)])]),
- ('Zone 4', {
- 'device_levels_handling': 'devdefault',
- 'levels': (70.0, 80.0)
- }, [(0, u'20.0 \xb0C', [('temp', 20.0, 70.0, 80.0, None,
None)])]),
- ('Zone 5', {
- 'device_levels_handling': 'devdefault',
- 'levels': (70.0, 80.0)
- }, [(0, u'27.0 \xb0C', [('temp', 27.0, 70.0, 80.0, None,
None)])])]
+ '': [
+ (
+ 'Zone 0',
+ {
+ 'device_levels_handling': 'devdefault',
+ 'levels': (70.0, 80.0)
+ },
+ [(0, u'57.0 \xb0C', [('temp', 57.0, 127.0, 127.0, None,
None)])],
+ ),
+ (
+ 'Zone 1',
+ {
+ 'device_levels_handling': 'devdefault',
+ 'levels': (70.0, 80.0)
+ },
+ [(0, u'65.0 \xb0C', [('temp', 65.0, 95.5, 100.0, None,
None)])],
+ ),
+ (
+ 'Zone 2',
+ {
+ 'device_levels_handling': 'devdefault',
+ 'levels': (70.0, 80.0)
+ },
+ [(0, u'44.0 \xb0C', [('temp', 44.0, 70.0, 80.0, None,
None)])],
+ ),
+ (
+ 'Zone 3',
+ {
+ 'device_levels_handling': 'devdefault',
+ 'levels': (70.0, 80.0)
+ },
+ [(0, u'48.0 \xb0C', [('temp', 48.0, 77.0, 87.0, None,
None)])],
+ ),
+ (
+ 'Zone 4',
+ {
+ 'device_levels_handling': 'devdefault',
+ 'levels': (70.0, 80.0)
+ },
+ [(0, u'20.0 \xb0C', [('temp', 20.0, 70.0, 80.0, None,
None)])],
+ ),
+ (
+ 'Zone 5',
+ {
+ 'device_levels_handling': 'devdefault',
+ 'levels': (70.0, 80.0)
+ },
+ [(0, u'27.0 \xb0C', [('temp', 27.0, 70.0, 80.0, None,
None)])],
+ ),
+ # test for an unknown item
+ (
+ 'Zone 6',
+ {
+ 'device_levels_handling': 'devdefault',
+ 'levels': (70.0, 80.0)
+ },
+ None
+ ),
+ ]
}