Module: check_mk
Branch: master
Commit: ac5d1624756bf814bb88b3e1001c961ba9245ab4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ac5d1624756bf8…
Author: Ronny Bruska <rb(a)mathias-kettner.de>
Date: Thu Mar 21 09:09:33 2019 +0100
7203 FIX agent_prism: Fixed handling of informational messages
We have seen informational messages in format:
{dev_type} drive {dev_name} on host {ip_address} has the following problems: {err_msg}
In order to handle such cases, we now deal with this message format differently.
Change-Id: I52ef1fcae1cae5d9ee558b0fd5fd51bf16524828
---
.werks/7203 | 15 +++++++++++
agents/special/agent_prism | 9 ++++++-
checks/prism_alerts | 13 +++++++---
.../checks/generictests/datasets/prism_alerts.py | 30 ++++++++++++----------
4 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/.werks/7203 b/.werks/7203
new file mode 100644
index 0000000..3a83238
--- /dev/null
+++ b/.werks/7203
@@ -0,0 +1,15 @@
+Title: agent_prism: Fixed handling of informational messages
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1553155607
+Class: fix
+
+We have seen informational messages in format:
+{dev_type} drive {dev_name} on host {ip_address} has the following problems: {err_msg}
+
+In order to handle such cases, we now deal with this message format differently.
+
+
diff --git a/agents/special/agent_prism b/agents/special/agent_prism
index 65ac76c..ea51c52 100755
--- a/agents/special/agent_prism
+++ b/agents/special/agent_prism
@@ -164,7 +164,14 @@ def output_alerts(opener, headers):
# actual values are stored in context_values, the keys in
# context_types
context = zip(entity['contextTypes'], entity['contextValues'])
- message = entity['message'].format(**dict(context))
+ # We have seen informational messages in format:
+ # {dev_type} drive {dev_name} on host {ip_address} has the following problems:
{err_msg}
+ # In this case the keys have no values so we can not assign it to the message
+ # To handle this, we output a message without assigning the keys
+ try:
+ message = entity['message'].format(**dict(context))
+ except KeyError:
+ message = entity['message']
writer.writerow([entity['createdTimeStampInUsecs'], message,
entity['severity']])
diff --git a/checks/prism_alerts b/checks/prism_alerts
index e7b3baf..be79ce2 100644
--- a/checks/prism_alerts
+++ b/checks/prism_alerts
@@ -40,7 +40,8 @@ def check_prism_alerts(__no_item, __no_params, parsed):
return {'kInfo': (0, 0), 'kWarning': (1, 1), 'kCritical':
(3, 2)}.get(name, (2, 3))
if len(parsed) == 0:
- return 0, "No alerts"
+ yield 0, "No alerts"
+ return
# sort messages by severity, then timestamp, both reversed
# this way the first element should be the newest among those
@@ -49,8 +50,14 @@ def check_prism_alerts(__no_item, __no_params, parsed):
parsed, key=lambda x: (severity(x['severity'][0]),
x['timestamp']), reverse=True)
sever = row_sorted[0]
time_str = time.strftime("%c",
time.localtime(int(sever['timestamp']) / 1000000))
- return severity(sever['severity'])[1], "%d alerts, Last worst on %s:
\"%s\"" %\
- (len(row_sorted), time_str, sever['message'])
+ yield severity(sever['severity'])[1], "%d alerts" %
len(row_sorted)
+
+ message = sever['message']
+ if "has the following problems" in message:
+ state = 1
+ else:
+ state = 0
+ yield state, "Last worst on %s: \"%s\"" % (time_str, message)
check_info['prism_alerts'] = {
diff --git a/tests/unit/checks/generictests/datasets/prism_alerts.py
b/tests/unit/checks/generictests/datasets/prism_alerts.py
index 7b46263..41fe6d1 100644
--- a/tests/unit/checks/generictests/datasets/prism_alerts.py
+++ b/tests/unit/checks/generictests/datasets/prism_alerts.py
@@ -1,19 +1,23 @@
# yapf: disable
+
+
checkname = 'prism_alerts'
-info = [
- ['timestamp', 'message', 'severity'],
- [
- '1456749413140000',
- 'DIMM fault detected on host 172.25.209.110. The node is running with 384 GB
whereas 512 GB was installed.',
- 'kCritical'
- ], ['1456749413150000', 'Some warning message.',
'kWarning'],
- ['1456749413160000', 'Some info message.', 'kInfo']
-]
+
+info = [['timestamp', 'message', 'severity'],
+ ['1456749413140000',
+ 'DIMM fault detected on host 172.25.209.110. The node is running with 384 GB
whereas 512 GB was installed.',
+ 'kCritical'],
+ ['1456749413150000', 'Some warning message.',
'kWarning'],
+ ['1456749413160000', 'Some info message.', 'kInfo']]
+
discovery = {'': [(None, None)]}
-checks = {
- '': [(None, {}, [(0, '3 alerts, Last worst on Mon Feb 29 13:36:53 2016:
"Some info message."',
- [])])]
-}
+
+checks = {'': [(None,
+ {},
+ [(0, '3 alerts', []),
+ (0,
+ 'Last worst on Mon Feb 29 13:36:53 2016: "Some info
message."',
+ [])])]}
\ No newline at end of file