Module: check_mk
Branch: master
Commit: 82a0551479e095949bf80f512e409603e788e2ea
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=82a0551479e095…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Feb 22 11:03:56 2019 +0100
mssql_blocked_sessions: prepare parse function to ignore err msg
Also make pylint happy and use new CheckAPI
CMK-1570
Change-Id: Ief0fbd6f4ff1866fd8be45fdc90c02aacde42dc2
---
checks/mssql_blocked_sessions | 35 ++++++++++++++---------------------
1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/checks/mssql_blocked_sessions b/checks/mssql_blocked_sessions
index 5263d05..077ef55 100644
--- a/checks/mssql_blocked_sessions
+++ b/checks/mssql_blocked_sessions
@@ -44,13 +44,10 @@ def parse_mssql_blocked_sessions(info):
"DBInstance", ["session_id", "wait_type",
"blocking_session_id", "wait_duration"])
parsed = {}
for line in info:
- if len(line) == 5:
- inst, session_id, wait_duration_ms, wait_type, blocking_session_id = line
- elif len(line) == 4:
- session_id, wait_duration_ms, wait_type, blocking_session_id = line
- inst = ""
- else:
+ if len(line) not in (4, 5) or line[-1].startswith("ERROR: "):
continue
+ inst = line[0] if len(line) == 5 else ""
+ session_id, wait_duration_ms, wait_type, blocking_session_id = line[-4:]
parsed.setdefault(inst, []).append(
db_instance(
@@ -59,12 +56,8 @@ def parse_mssql_blocked_sessions(info):
blocking_session_id,
float(wait_duration_ms) / 1000,
))
- return parsed
-
-def inventory_mssql_blocked_sessions(parsed):
- for instance in parsed:
- yield instance, {}
+ return parsed
def check_mssql_blocked_sessions(item, params, parsed):
@@ -82,26 +75,26 @@ def check_mssql_blocked_sessions(item, params, parsed):
ignored_waittypes = set()
waittypes_to_be_ignored = params.get("ignore_waittypes", [])
- for e in parsed[item]:
- if e.wait_type in waittypes_to_be_ignored:
- ignored_waittypes.add(e.wait_type)
+ for db_inst in parsed[item]:
+ if db_inst.wait_type in waittypes_to_be_ignored:
+ ignored_waittypes.add(db_inst.wait_type)
continue
level_info = ""
state = 0
- if crit is not None and e.wait_duration >= crit:
+ if crit is not None and db_inst.wait_duration >= crit:
state = 2
- elif warn is not None and e.wait_duration >= warn:
+ elif warn is not None and db_inst.wait_duration >= warn:
state = 1
if state:
level_info = " (warn/crit at %s/%s)" %
(get_age_human_readable(warn),
get_age_human_readable(crit))
- summary.setdefault(e.session_id, 0)
- summary[e.session_id] += 1
+ summary.setdefault(db_inst.session_id, 0)
+ summary[db_inst.session_id] += 1
details.append((state, "Session %s blocked by %s (Type: %s, Wait:
%s)%s" % \
- (e.session_id, e.blocking_session_id, e.wait_type,
- get_age_human_readable(e.wait_duration), level_info)))
+ (db_inst.session_id, db_inst.blocking_session_id,
db_inst.wait_type,
+ get_age_human_readable(db_inst.wait_duration), level_info)))
if summary:
yield params['state'], "Summary: %s" % (", ".join(
@@ -118,7 +111,7 @@ def check_mssql_blocked_sessions(item, params, parsed):
check_info['mssql_blocked_sessions'] = {
'parse_function': parse_mssql_blocked_sessions,
- 'inventory_function': inventory_mssql_blocked_sessions,
+ 'inventory_function': discover(),
'check_function': check_mssql_blocked_sessions,
'service_description': 'MSSQL %s Blocked Sessions',
'group': 'mssql_instance_blocked_sessions',