Include previous state in alarm notification

We now provide both the current and previous alarm states
in the notification.

This allows differential logic to be applied by the webhook
implementation, for example depending on whether the previous
state was known or insufficient data.

It also allows the initial and subsequent notifications to be
distinguished for repeat_actions alarms, without resorting to
fragile string comparisons between 'Transition to ...' and
'Remaining as ...'.

Change-Id: I61294e98ddf504b3ab22e9b16ab718d64c27486f
This commit is contained in:
Eoghan Glynn
2013-08-08 20:29:01 +00:00
parent 1e8b2b9b3a
commit 78def056db
10 changed files with 69 additions and 84 deletions

View File

@@ -128,7 +128,7 @@ class AlarmNotifierService(rpc_service.Service):
'ceilometer.alarm.' + cfg.CONF.alarm.notifier_rpc_topic,
)
def _handle_action(self, action, alarm, state, reason):
def _handle_action(self, action, alarm, previous, current, reason):
try:
action = network_utils.urlsplit(action)
except Exception:
@@ -150,7 +150,7 @@ class AlarmNotifierService(rpc_service.Service):
try:
LOG.debug("Notifying alarm %s with action %s",
alarm, action)
notifier.notify(action, alarm, state, reason)
notifier.notify(action, alarm, previous, current, reason)
except Exception:
LOG.exception(_("Unable to notify alarm %s"), alarm)
return
@@ -162,7 +162,8 @@ class AlarmNotifierService(rpc_service.Service):
- actions, the URL of the action to run;
this is a mapped to extensions automatically
- alarm, the alarm that has been triggered
- state, the new state the alarm transitionned to
- previous, the previous state of the alarm
- current, the new state the alarm has transitioned to
- reason, the reason the alarm changed its state
:param context: Request context.
@@ -176,7 +177,8 @@ class AlarmNotifierService(rpc_service.Service):
for action in actions:
self._handle_action(action,
data.get('alarm'),
data.get('state'),
data.get('previous'),
data.get('current'),
data.get('reason'))