Add notifications for alarm changes
Changes in alarm state (including definition and deletion) now emit notifications. Change-Id: I55799d6f00e6832c1d7ffb736f97d3dfcbe801aa
This commit is contained in:
@@ -50,6 +50,7 @@ from wsme import types as wtypes
|
||||
from ceilometer.openstack.common import context
|
||||
from ceilometer.openstack.common.gettextutils import _
|
||||
from ceilometer.openstack.common import log
|
||||
from ceilometer.openstack.common.notifier import api as notify
|
||||
from ceilometer.openstack.common import strutils
|
||||
from ceilometer.openstack.common import timeutils
|
||||
from ceilometer import sample
|
||||
@@ -448,6 +449,13 @@ def _make_link(rel_name, url, type, type_arg, query=None):
|
||||
rel=rel_name)
|
||||
|
||||
|
||||
def _send_notification(event, payload):
|
||||
notification = event.replace(" ", "_")
|
||||
notification = "alarm.%s" % notification
|
||||
notify.notify(None, notify.publisher_id("ceilometer.api"),
|
||||
notification, notify.INFO, payload)
|
||||
|
||||
|
||||
class Sample(_Base):
|
||||
"""A single measurement for a given meter and resource.
|
||||
"""
|
||||
@@ -1240,22 +1248,29 @@ class AlarmController(rest.RestController):
|
||||
if not cfg.CONF.alarm.record_history:
|
||||
return
|
||||
type = type or storage.models.AlarmChange.RULE_CHANGE
|
||||
detail = json.dumps(utils.stringify_timestamps(data))
|
||||
scrubbed_data = utils.stringify_timestamps(data)
|
||||
detail = json.dumps(scrubbed_data)
|
||||
user_id = pecan.request.headers.get('X-User-Id')
|
||||
project_id = pecan.request.headers.get('X-Project-Id')
|
||||
on_behalf_of = on_behalf_of or project_id
|
||||
payload = dict(event_id=str(uuid.uuid4()),
|
||||
alarm_id=self._id,
|
||||
type=type,
|
||||
detail=detail,
|
||||
user_id=user_id,
|
||||
project_id=project_id,
|
||||
on_behalf_of=on_behalf_of,
|
||||
timestamp=now)
|
||||
|
||||
try:
|
||||
self.conn.record_alarm_change(dict(event_id=str(uuid.uuid4()),
|
||||
alarm_id=self._id,
|
||||
type=type,
|
||||
detail=detail,
|
||||
user_id=user_id,
|
||||
project_id=project_id,
|
||||
on_behalf_of=on_behalf_of,
|
||||
timestamp=now))
|
||||
self.conn.record_alarm_change(payload)
|
||||
except NotImplementedError:
|
||||
pass
|
||||
|
||||
# Revert to the pre-json'ed details ...
|
||||
payload['detail'] = scrubbed_data
|
||||
_send_notification(type, payload)
|
||||
|
||||
@wsme_pecan.wsexpose(Alarm, wtypes.text)
|
||||
def get(self):
|
||||
"""Return this alarm."""
|
||||
@@ -1367,21 +1382,28 @@ class AlarmsController(rest.RestController):
|
||||
if not cfg.CONF.alarm.record_history:
|
||||
return
|
||||
type = storage.models.AlarmChange.CREATION
|
||||
detail = json.dumps(utils.stringify_timestamps(data))
|
||||
scrubbed_data = utils.stringify_timestamps(data)
|
||||
detail = json.dumps(scrubbed_data)
|
||||
user_id = pecan.request.headers.get('X-User-Id')
|
||||
project_id = pecan.request.headers.get('X-Project-Id')
|
||||
payload = dict(event_id=str(uuid.uuid4()),
|
||||
alarm_id=alarm_id,
|
||||
type=type,
|
||||
detail=detail,
|
||||
user_id=user_id,
|
||||
project_id=project_id,
|
||||
on_behalf_of=project_id,
|
||||
timestamp=now)
|
||||
|
||||
try:
|
||||
conn.record_alarm_change(dict(event_id=str(uuid.uuid4()),
|
||||
alarm_id=alarm_id,
|
||||
type=type,
|
||||
detail=detail,
|
||||
user_id=user_id,
|
||||
project_id=project_id,
|
||||
on_behalf_of=project_id,
|
||||
timestamp=now))
|
||||
conn.record_alarm_change(payload)
|
||||
except NotImplementedError:
|
||||
pass
|
||||
|
||||
# Revert to the pre-json'ed details ...
|
||||
payload['detail'] = scrubbed_data
|
||||
_send_notification(type, payload)
|
||||
|
||||
@wsme.validate(Alarm)
|
||||
@wsme_pecan.wsexpose(Alarm, body=Alarm, status_code=201)
|
||||
def post(self, data):
|
||||
|
||||
Reference in New Issue
Block a user