Don't send unuseful rpc alarm notification

If the alarm have no actions for the new state we don't need to send a
message through the rpc for notification, just log a debug message
when it occur.

Fixes bug 1224416

Change-Id: I9aeb01e936dbacfbabb06e8b408d5ee04a93cb34
This commit is contained in:
Mehdi Abaakouk 2013-09-24 10:22:07 +02:00
parent 09e0f3fabf
commit 1feca03125
2 changed files with 32 additions and 0 deletions

View File

@ -20,6 +20,8 @@ from oslo.config import cfg
from ceilometer.openstack.common import context
from ceilometer.openstack.common.rpc import proxy as rpc_proxy
from ceilometer.openstack.common import log
from ceilometer.openstack.common.gettextutils import _
from ceilometer.storage.models import Alarm
OPTS = [
@ -34,6 +36,8 @@ OPTS = [
cfg.CONF.register_opts(OPTS, group='alarm')
LOG = log.getLogger(__name__)
class RPCAlarmNotifier(rpc_proxy.RpcProxy):
def __init__(self):
@ -43,6 +47,14 @@ class RPCAlarmNotifier(rpc_proxy.RpcProxy):
def notify(self, alarm, previous, reason):
actions = getattr(alarm, Alarm.ALARM_ACTIONS_MAP[alarm.state])
if not actions:
LOG.debug(_('alarm %(alarm_id)s has no action configured '
'for state transition from %(previous)s to '
'state %(state)s, skipping the notification.') %
{'alarm_id': alarm.alarm_id,
'previous': previous,
'state': alarm.state})
return
msg = self.make_msg('notify_alarm', data={
'actions': actions,
'alarm_id': alarm.alarm_id,

View File

@ -96,3 +96,23 @@ class TestRPCAlarmNotifier(base.TestCase):
self.notifier.notify(self.alarms[0], 'ok', 42)
reason = self.notified[0][1]['args']['data']['reason']
self.assertTrue(isinstance(reason, basestring))
def test_notify_no_actions(self):
alarm = AlarmClient(None, info={
'name': 'instance_running_hot',
'meter_name': 'cpu_util',
'comparison_operator': 'gt',
'threshold': 80.0,
'evaluation_periods': 5,
'statistic': 'avg',
'state': 'ok',
'user_id': 'foobar',
'project_id': 'snafu',
'period': 60,
'ok_actions': [],
'alarm_id': str(uuid.uuid4()),
'matching_metadata': {'resource_id':
'my_instance'}
})
self.notifier.notify(alarm, 'alarm', "what?")
self.assertEqual(len(self.notified), 0)