Module: check_mk
Branch: master
Commit: 178a5b16d9253f808d4cfae2467e2fbf91b88630
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=178a5b16d9253f…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Feb 22 12:06:03 2019 +0100
tmssql_tablespaces: prepare to handle error message
The plugin does not produce such an error message yet,
but we will be ready.
No animals were harmed during testing.
Change-Id: I3e92356617fd7b06fb041990830570bb94a04729
---
checks/mssql_tablespaces | 25 ++++++++++++++--------
.../datasets/mssql_tablespaces_regression.py | 5 +++++
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/checks/mssql_tablespaces b/checks/mssql_tablespaces
index d42c173..c638094 100644
--- a/checks/mssql_tablespaces
+++ b/checks/mssql_tablespaces
@@ -69,6 +69,9 @@ def parse_mssql_tablespaces(info):
values = (to_bytes(*p) for p in pairs[1:])
data = dict(zip(keys, values))
+ if len(line) > 14 and line[14].startswith("ERROR: "):
+ data["error"] = line[14][7:]
+
parsed.setdefault(item, data)
return parsed
@@ -82,17 +85,20 @@ def check_mssql_tablespaces(item, params, parsed):
raise MKCounterWrapped("Tablespace not found")
size = tablespace["size"]
+ if "error" in tablespace:
+ yield 2, tablespace["error"]
+
if size is not None:
levels = params.get("size", (None, None))
yield check_levels(
size, 'size', levels, human_readable_func=get_bytes_human_readable,
infoname="Size")
- for key, title, levels_info, upper_bounds in [
- ('unallocated', 'Unallocated space', 'below', False),
- ('reserved', 'Reserved space', 'at', True),
- ('data', 'Data', 'at', True),
- ('indexes', 'Indexes', 'at', True),
- ('unused', 'Unused', 'at', True),
+ for key, title, is_upper in [
+ ('unallocated', 'Unallocated space', False),
+ ('reserved', 'Reserved space', True),
+ ('data', 'Data', True),
+ ('indexes', 'Indexes', True),
+ ('unused', 'Unused', True),
]:
value_bytes = tablespace[key]
if value_bytes is None:
@@ -117,12 +123,13 @@ def check_mssql_tablespaces(item, params, parsed):
continue
state = 0
- if upper_bounds and value >= crit or not upper_bounds and value <= crit:
+ if is_upper and value >= crit or not is_upper and value <= crit:
state = 2
- elif upper_bounds and value >= warn or not upper_bounds and value <= warn:
+ elif is_upper and value >= warn or not is_upper and value <= warn:
state = 1
if state:
- infotext += " (warn/crit %s %s/%s)" % (levels_info,
readable_f(warn), readable_f(crit))
+ infotext += " (warn/crit %s %s/%s)" % (
+ ('below', 'at')[is_upper], readable_f(warn),
readable_f(crit))
yield state, infotext
diff --git a/tests/unit/checks/generictests/datasets/mssql_tablespaces_regression.py
b/tests/unit/checks/generictests/datasets/mssql_tablespaces_regression.py
index e7f43ad..b6ce600 100644
--- a/tests/unit/checks/generictests/datasets/mssql_tablespaces_regression.py
+++ b/tests/unit/checks/generictests/datasets/mssql_tablespaces_regression.py
@@ -6,12 +6,14 @@ checkname = 'mssql_tablespaces'
info = [
['MSSQL_SQLEXPRESS', 'master', '5.25', 'MB',
'1.59', 'MB', '2464',
'KB', '1096', 'KB', '1024', 'KB',
'344', 'KB'],
+ ['MSSQL_Katze', 'Kitty'] + ['-'] * 12 + ['ERROR: Kitty
ist auf die Nase gefallen!'],
]
discovery = {
'': [
('MSSQL_SQLEXPRESS master', {}),
+ ('MSSQL_Katze Kitty', {}),
],
}
@@ -34,5 +36,8 @@ checks = {
(0, 'Indexes: 1.00 MB, 19.0%', []),
(0, 'Unused: 344.00 kB, 6.4%', []),
]),
+ ('MSSQL_Katze Kitty', {}, [
+ (2, 'Kitty ist auf die Nase gefallen!'),
+ ]),
],
}