Merge "Fix periodic notifications for webhooks"
This commit is contained in:
commit
794c8c997a
@ -22,7 +22,7 @@ _DEFAULT_ALARM_TOPIC = 'alarm-state-transitions'
|
||||
_DEFAULT_NOTIFICATION_TOPIC = 'alarm-notifications'
|
||||
_DEFAULT_RETRY_TOPIC = 'retry-notifications'
|
||||
_DEFAULT_PERIODIC_TOPICS = {
|
||||
60: '60-seconds-notifications'
|
||||
'60': '60-seconds-notifications'
|
||||
}
|
||||
_DEFAULT_MAX_OFFSET_LAG = 600
|
||||
|
||||
|
@ -20,7 +20,7 @@ _DEFAULT_URL = '127.0.0.1:2181'
|
||||
_DEFAULT_NOTIFICATION_PATH = '/notification/alarms'
|
||||
_DEFAULT_RETRY_PATH = '/notification/retry'
|
||||
_DEFAULT_PERIODIC_PATH = {
|
||||
60: '/notification/60_seconds'
|
||||
'60': '/notification/60_seconds'
|
||||
}
|
||||
|
||||
zookeeper_group = cfg.OptGroup('zookeeper',
|
||||
|
@ -108,10 +108,10 @@ def main(argv=None):
|
||||
args=(retry_engine.RetryEngine,))
|
||||
)
|
||||
|
||||
if 60 in CONF.kafka.periodic:
|
||||
for notification_period in CONF.kafka.periodic.keys():
|
||||
processors.append(multiprocessing.Process(
|
||||
target=start_process,
|
||||
args=(periodic_engine.PeriodicEngine, 60))
|
||||
args=(periodic_engine.PeriodicEngine, int(notification_period)))
|
||||
)
|
||||
|
||||
try:
|
||||
|
@ -39,7 +39,6 @@ class Notification(object):
|
||||
'retry_count',
|
||||
'raw_alarm',
|
||||
'period',
|
||||
'periodic_topic'
|
||||
)
|
||||
|
||||
def __init__(self, id, type, name, address, period, retry_count, alarm):
|
||||
@ -77,8 +76,6 @@ class Notification(object):
|
||||
# to be updated on actual notification send time
|
||||
self.notification_timestamp = None
|
||||
|
||||
# set periodic topic
|
||||
self.periodic_topic = period
|
||||
self.period = period
|
||||
|
||||
def __eq__(self, other):
|
||||
@ -115,7 +112,6 @@ class Notification(object):
|
||||
'lifecycle_state',
|
||||
'tenant_id',
|
||||
'period',
|
||||
'periodic_topic'
|
||||
]
|
||||
notification_data = {name: getattr(self, name)
|
||||
for name in notification_fields}
|
||||
|
@ -46,10 +46,10 @@ class NotificationEngine(object):
|
||||
|
||||
def _add_periodic_notifications(self, notifications):
|
||||
for notification in notifications:
|
||||
topic = notification.periodic_topic
|
||||
if topic in CONF.kafka.periodic and notification.type == "webhook":
|
||||
period = str(notification.period)
|
||||
if period in CONF.kafka.periodic.keys() and notification.type == "webhook":
|
||||
notification.notification_timestamp = time.time()
|
||||
self._producer.publish(CONF.kafka.periodic[topic],
|
||||
self._producer.publish(CONF.kafka.periodic[period],
|
||||
[notification.to_json()])
|
||||
|
||||
def run(self):
|
||||
|
@ -33,7 +33,7 @@ CONF = cfg.CONF
|
||||
|
||||
class PeriodicEngine(object):
|
||||
def __init__(self, period):
|
||||
self._topic_name = CONF.kafka.periodic[period]
|
||||
self._topic_name = CONF.kafka.periodic[str(period)]
|
||||
|
||||
self._statsd = get_statsd_client()
|
||||
|
||||
@ -42,7 +42,7 @@ class PeriodicEngine(object):
|
||||
CONF.kafka.group,
|
||||
self._topic_name,
|
||||
CONF.zookeeper.url,
|
||||
CONF.zookeeper.periodic_path[period],
|
||||
CONF.zookeeper.periodic_path[str(period)],
|
||||
CONF.kafka.legacy_kafka_client_enabled)
|
||||
self._producer = client_factory.get_kafka_producer(
|
||||
CONF.kafka.url,
|
||||
|
@ -22,7 +22,6 @@ jira_format:
|
||||
# notification.retry_count
|
||||
# notification.raw_alarm
|
||||
# notification.period
|
||||
# notification.periodic_topic
|
||||
|
||||
# Please include alarm_id in summary as it is used for searching the issues
|
||||
summary: Alaram created for {{ notification.alarm_name }} with severity {{ notification.state }} for {{ notification.alarm_id }}
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- Supports setting arbitrary notification periods.
|
||||
fixes:
|
||||
- Issue with periodic notification processor failing to load when using Oslo
|
||||
config.
|
@ -51,7 +51,6 @@ def test_json():
|
||||
u'address': u'address',
|
||||
u'message': u'stateChangeReason',
|
||||
u'period': 0,
|
||||
u'periodic_topic': 0,
|
||||
u'retry_count': 0,
|
||||
u'raw_alarm': {
|
||||
u'alarmId': u'alarmId',
|
||||
@ -101,7 +100,6 @@ def test_json_non_zero_period():
|
||||
u'address': u'address',
|
||||
u'message': u'stateChangeReason',
|
||||
u'period': 60,
|
||||
u'periodic_topic': 60,
|
||||
u'retry_count': 0,
|
||||
u'raw_alarm': {
|
||||
u'alarmId': u'alarmId',
|
||||
|
Loading…
Reference in New Issue
Block a user