From 1c5bd9e8fd9e2bbd26161266b5bb6a1127009d65 Mon Sep 17 00:00:00 2001 From: ZhiQiang Fan Date: Thu, 28 Apr 2016 18:33:51 +0800 Subject: [PATCH] [Trivial] Improve alarm reason text In log, I find such message: alarm e513e3d2-bd2d-4f75-8eae-e5dd3a09faab transitioning to alarm because Event (message_id=6f5da2a9-300f-4e60-89db-e227db7cb9c6) hit the query of alarm (id=e513e3d2-bd2d-4f75-8eae-e5dd3a09faab) This doesn't have much information and has duplicate alarm id. And alarm notifier will send reason such as: Event (message_id=6f5da2a9-300f-4e60-89db-e227db7cb9c6) hit the query of alarm (id=e513e3d2-bd2d-4f75-8eae-e5dd3a09faab) Alarm notifier already includes the alarm id information, but has query information, so if there is many alarms, user needs to retieve that alarm to see why an event would trigger that alarm and which one the alarm is. This patch improves such text to be: alarm e513e3d2-bd2d-4f75-8eae-e5dd3a09faab transitioning to alarm because Event hits the query Change-Id: I64dd21ae8bee268164ec5d22e0146253c30e1a87 --- aodh/evaluator/event.py | 10 +++++++--- aodh/tests/unit/evaluator/test_event.py | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/aodh/evaluator/event.py b/aodh/evaluator/event.py index c38f201c1..2c800dba6 100644 --- a/aodh/evaluator/event.py +++ b/aodh/evaluator/event.py @@ -17,6 +17,7 @@ import operator from oslo_config import cfg from oslo_log import log +from oslo_serialization import jsonutils from oslo_utils import fnmatch from oslo_utils import timeutils import six @@ -248,9 +249,12 @@ class EventAlarmEvaluator(evaluator.Evaluator): """Update alarm state and fire alarm via alarm notifier.""" state = evaluator.ALARM - reason = (_('Event (message_id=%(message)s) hit the query of alarm ' - '(id=%(alarm)s)') % - {'message': event.id, 'alarm': alarm.id}) + reason = (_('Event hits the ' + 'query .') % + {'id': event.id, + 'event_type': event.get_value('event_type'), + 'alarm_query': jsonutils.dumps(alarm.obj.rule['query'], + sort_keys=True)}) reason_data = {'type': 'event', 'event': event.obj} always_record = alarm.obj.repeat_actions self._refresh(alarm.obj, state, reason, reason_data, always_record) diff --git a/aodh/tests/unit/evaluator/test_event.py b/aodh/tests/unit/evaluator/test_event.py index 5672804d2..106d39893 100644 --- a/aodh/tests/unit/evaluator/test_event.py +++ b/aodh/tests/unit/evaluator/test_event.py @@ -19,6 +19,7 @@ import six import uuid import mock +from oslo_serialization import jsonutils from oslo_utils import timeutils from aodh import evaluator @@ -122,9 +123,12 @@ class TestEventAlarmEvaluate(base.TestEvaluatorBase): alarm = n['alarm'] event = n['event'] previous = n.get('previous', evaluator.UNKNOWN) - reason = ('Event (message_id=%(e)s) hit the query of alarm ' - '(id=%(a)s)' % - {'e': event['message_id'], 'a': alarm.alarm_id}) + reason = ('Event hits the ' + 'query .') % { + 'e': event['message_id'], + 'type': event['event_type'], + 'query': jsonutils.dumps(alarm.rule['query'], + sort_keys=True)} data = {'type': 'event', 'event': event} expected = dict(alarm_id=alarm.alarm_id, state=evaluator.ALARM,