Module: check_mk
Branch: master
Commit: d85272d77c31d77363d088356adfd8c8223462be
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d85272d77c31d7…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Feb 28 12:18:03 2019 +0100
mssql_databases: prepare error handling.
CMK-1570
Change-Id: Ic59dc85e753aae54154294e00550761eb8c59715
---
checks/mssql_databases | 30 ++++++++++------------
.../datasets/mssql_databases_regression.py | 14 +++++++---
2 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/checks/mssql_databases b/checks/mssql_databases
index 3117c0f..a6d707b 100644
--- a/checks/mssql_databases
+++ b/checks/mssql_databases
@@ -57,32 +57,30 @@ def parse_mssql_databases(info):
return parsed
-def inventory_mssql_databases(parsed):
- return [(db_name, {}) for db_name in parsed]
-
-
-def check_mssql_databases(item, params, parsed):
+@get_parsed_item_data
+def check_mssql_databases(_no_item, params, data):
map_states = {
"1": (1, "on"),
"0": (0, "off"),
}
- if item in parsed:
- data = parsed[item]
- db_state = data["Status"]
- state = params.get("map_db_states", {}).get(db_state.replace("
", "_").upper(), 0)
- yield state, 'Status: %s' % db_state
- yield 0, 'Recovery: %s' % data["Recovery"]
+ db_state = data["Status"]
+ if db_state.startswith("ERROR: "):
+ yield 2, db_state[7:]
+ return
+ state = params.get("map_db_states", {}).get(db_state.replace(" ",
"_").upper(), 0)
+ yield state, 'Status: %s' % db_state
+ yield 0, 'Recovery: %s' % data["Recovery"]
- for what in ["close", "shrink"]:
- state, state_readable = map_states[data["auto_%s" % what]]
- state = params.get("map_auto_%s_state" % what,
{}).get(state_readable, state)
- yield state, 'Auto %s: %s' % (what, state_readable)
+ for what in ["close", "shrink"]:
+ state, state_readable = map_states[data["auto_%s" % what]]
+ state = params.get("map_auto_%s_state" % what, {}).get(state_readable,
state)
+ yield state, 'Auto %s: %s' % (what, state_readable)
check_info['mssql_databases'] = {
'parse_function': parse_mssql_databases,
- 'inventory_function': inventory_mssql_databases,
+ 'inventory_function': discover(),
'check_function': check_mssql_databases,
'service_description': 'MSSQL %s Database',
'group': 'mssql_databases',
diff --git a/tests/unit/checks/generictests/datasets/mssql_databases_regression.py
b/tests/unit/checks/generictests/datasets/mssql_databases_regression.py
index 91ed286..0cc370a 100644
--- a/tests/unit/checks/generictests/datasets/mssql_databases_regression.py
+++ b/tests/unit/checks/generictests/datasets/mssql_databases_regression.py
@@ -8,14 +8,18 @@ info = [['MSSQL_MSSQL46', 'CorreLog_Report_T',
'ONLINE', 'FULL', '0', '0'],
['MSSQL_MSSQL46', 'msdb', 'ONLINE', 'SIMPLE',
'0', '0'],
['MSSQL_MSSQL46', 'NOC_ALARM_T', 'ONLINE',
'FULL', '0', '1'],
['MSSQL_MSSQL46', 'test_autoclose', 'ONLINE',
'FULL', '1', '0'],
- ['MSSQL_MSSQL46', 'test_autoclose', 'RECOVERY',
'PENDING', 'FULL', '1', '0']]
+ ['MSSQL_MSSQL46', 'test_autoclose', 'RECOVERY',
'PENDING', 'FULL', '1', '0'],
+ ['MSSQL_Mouse', '-', 'ERROR: We are out of cheese!',
'-', '-', '-']
+ ]
discovery = {'': [('MSSQL_MSSQL46 CorreLog_Report_T', {}),
('MSSQL_MSSQL46 NOC_ALARM_T', {}),
('MSSQL_MSSQL46 master', {}),
('MSSQL_MSSQL46 msdb', {}),
- ('MSSQL_MSSQL46 test_autoclose', {})]}
+ ('MSSQL_MSSQL46 test_autoclose', {}),
+ ('MSSQL_Mouse -', {}),
+ ]}
checks = {'': [('MSSQL_MSSQL46 CorreLog_Report_T',
@@ -47,4 +51,8 @@ checks = {'': [('MSSQL_MSSQL46 CorreLog_Report_T',
[(0, 'Status: ONLINE', []),
(0, 'Recovery: FULL', []),
(1, 'Auto close: on', []),
- (0, 'Auto shrink: off', [])])]}
+ (0, 'Auto shrink: off', [])]),
+ ('MSSQL_Mouse -',
+ {},
+ [(2, 'We are out of cheese!')])
+ ]}