added data checks

This commit is contained in:
George Pochiscan 2023-05-31 12:47:38 +03:00
parent c26de603bb
commit d7ba6d93f4

View File

@ -21,13 +21,12 @@ def parse_informix_transactions(info):
for line in info: for line in info:
if line[0].startswith("[[[") and line[0].endswith("]]]"): if line[0].startswith("[[[") and line[0].endswith("]]]"):
instance = line[0][3:-3] instance = line[0][3:-3]
elif instance is not None: elif instance is not None:
entry = {} entry = {}
parsed.setdefault(instance, []) parsed.setdefault(instance, [])
parsed[instance].append(entry) parsed[instance].append(entry)
###in some cases, for some transaction lines there is no info, only a timestamp that should be ignored
if len(line) > 2: if len(line) > 2:
if "C" in line[2]: if "C" in line[2]:
entry.setdefault("current_log_id", line[3]) entry.setdefault("current_log_id", line[3])
elif entry is not None: elif entry is not None:
@ -35,7 +34,7 @@ def parse_informix_transactions(info):
line[4] = line[4].split(":",1)[0] line[4] = line[4].split(":",1)[0]
if ":" in str(line[5]): if ":" in str(line[5]):
line[5] = line[5].split(":",1)[0] line[5] = line[5].split(":",1)[0]
entry.setdefault("session", [line[2], line[3], line[4], line[5]]) entry.setdefault("session", [line[2], line[3], line[4], line[5]])
return parsed return parsed
@ -51,13 +50,14 @@ def check_informix_transactions_locks(item, params, parsed):
infotext = "" infotext = ""
state = 0 state = 0
for session in data[1:]: for session in data[1:]:
if "-" not in session["session"][1]: if session and session["session"][2]:
if int(session["session"][1]) >= crit: if "-" not in session["session"][1]:
state = 2 if int(session["session"][1]) >= crit:
infotext += 'Session with ID %s has %s locks; ' % (session["session"][0], session["session"][1]) state = 2
elif int(session["session"][1]) >= warn: infotext += 'Session with ID %s has %s locks; ' % (session["session"][0], session["session"][1])
state = 1 elif int(session["session"][1]) >= warn:
infotext += 'Session with ID %s has %s locks; ' % (session["session"][0], session["session"][1]) state = 1
infotext += 'Session with ID %s has %s locks; ' % (session["session"][0], session["session"][1])
if state: if state:
infotext += " (warn/crit at %s/%s)" % (warn, crit) infotext += " (warn/crit at %s/%s)" % (warn, crit)
@ -86,12 +86,13 @@ def check_informix_transactions_activity(item, no_params, parsed):
if item in parsed: if item in parsed:
data = parsed[item] data = parsed[item]
state = 0 state = 0
infotext = '' infotext = ''
for session in data[1:]: for session in data[1:]:
if "-" not in session["session"][2]: if session and session["session"][2]:
if int(session["session"][2]) < int(data[0]['current_log_id']): if "-" not in session["session"][2]:
state = 2 if int(session["session"][2]) < int(data[0]['current_log_id']):
infotext += "Session %s doesn't have activity in current log; " % (session["session"][0]) state = 2
infotext += "Session %s doesn't have activity in current log; " % (session["session"][0])
if not state: if not state:
@ -119,10 +120,11 @@ def check_informix_long_transactions(item, no_params, parsed):
state = 0 state = 0
infotext = '' infotext = ''
for session in data[1:]: for session in data[1:]:
if "-" not in session["session"][2]: if session and session["session"][2]:
if (int(session["session"][2]) - int(session["session"][3])) < 2: if "-" not in session["session"][2]:
state = 2 if (int(session["session"][2]) - int(session["session"][3])) < 2:
infotext += "Session %s is using more than 3 logical logs; " % (session["session"][0]) state = 2
infotext += "Session %s is using more than 3 logical logs; " % (session["session"][0])
if not state: if not state:
@ -138,3 +140,4 @@ check_info['informix_transactions.long_transactions'] = {
'has_perfdata': False, 'has_perfdata': False,
'service_description': 'Informix sessions Long transactions %s', 'service_description': 'Informix sessions Long transactions %s',
} }