[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 <id=40a6c473-4a8a-40f4-be6b-bab4cb6a221c,event_type=image.update> hits the query <query=[{{"field": "traits.io_read_kbs", "op": "eq", "type": "float", "value": "123.456"}]> Change-Id: I64dd21ae8bee268164ec5d22e0146253c30e1a87
This commit is contained in:
parent
92c66522d5
commit
1c5bd9e8fd
@ -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 <id=%(id)s,event_type=%(event_type)s> hits the '
|
||||
'query <query=%(alarm_query)s>.') %
|
||||
{'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)
|
||||
|
@ -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 <id=%(e)s,event_type=%(type)s> hits the '
|
||||
'query <query=%(query)s>.') % {
|
||||
'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,
|
||||
|
Loading…
Reference in New Issue
Block a user