Commit 4442db6f authored by Aurel's avatar Aurel

when notifying, attached alarm's result to mail it there is one


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21469 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 604a567c
...@@ -443,6 +443,23 @@ class Alarm(XMLObject, PeriodicityMixin): ...@@ -443,6 +443,23 @@ class Alarm(XMLObject, PeriodicityMixin):
candidate_list = self.getDestinationValueList() candidate_list = self.getDestinationValueList()
if not candidate_list: if not candidate_list:
candidate_list = None candidate_list = None
result_list = [x for x in self.getLastActiveProcess().getResultList() if x is not None]
attachment_list = []
if len(result_list):
def sort_result_list(a, b):
result = - cmp(a.severity, b.severity)
if result == 0:
result = cmp(a.summary, b.summary)
return result
result_list.sort(sort_result_list)
rendered_alarm_result_list = ['%02i summary: %s\n%s\n----' %
(int(getattr(x, 'severity', 0)), getattr(x, 'summary', ''), getattr(x, 'detail', ''))
for x in result_list]
rendered_alarm_result = '\n'.join(rendered_alarm_result_list)
attachment_list.append({'name': 'alarm_result.txt',
'content': rendered_alarm_result,
'mime_type': 'text/plain'})
notification_tool.sendMessage(recipient=candidate_list, notification_tool.sendMessage(recipient=candidate_list,
subject='[%s] ERP5 Alarm Notification: %s' % subject='[%s] ERP5 Alarm Notification: %s' %
(prefix, self.getTitle()), (prefix, self.getTitle()),
...@@ -453,7 +470,8 @@ Alarm Description: ...@@ -453,7 +470,8 @@ Alarm Description:
%s %s
Alarm URL: %s Alarm URL: %s
""" % (self.getTitle(), self.getDescription(), self.absolute_url())) """ % (self.getTitle(), self.getDescription(), self.absolute_url()),
attachment_list=attachment_list)
security.declareProtected(Permissions.View, 'getLastActiveProcess') security.declareProtected(Permissions.View, 'getLastActiveProcess')
def getLastActiveProcess(self): def getLastActiveProcess(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment