Skip to content

Commit

Permalink
Before sending notification verifying no changes in alert for sometime
Browse files Browse the repository at this point in the history
tendrl-bug-id: #177
bugzilla: 1564175

Signed-off-by: GowthamShanmugasundaram <gshanmug@redhat.com>
  • Loading branch information
GowthamShanmugam committed Jun 7, 2018
1 parent 58e3b80 commit 401bb45
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions tendrl/notifier/notification/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from abc import abstractmethod
from datetime import datetime
from dateutil import parser
import importlib
import json
import os
Expand Down Expand Up @@ -124,28 +126,34 @@ def run(self):
lock = None
alerts = get_alerts()
for alert in alerts:
alert.tags = json.loads(alert.tags)
if str(alert.delivered).lower() == "false":
lock = etcd.Lock(
NS._int.wclient,
'alerting/alerts/%s' % alert.alert_id
)
lock.acquire(
blocking=True,
lock_ttl=60
)
if lock.is_acquired:
# renew a lock
lock.acquire(lock_ttl=60)
for plugin in NotificationPlugin.plugins:
plugin.dispatch_notification(alert)
update_alert_delivery(alert)
lock.release()
# Check any changes in alert for last 60 sec
if (datetime.now() - parser.parse(
alert.time_stamp
).replace(tzinfo=None)).seconds >= 60:
# no changes in alert for last 60 sec
alert.tags = json.loads(alert.tags)
if str(alert.delivered).lower() == "false":
lock = etcd.Lock(
NS._int.wclient,
'alerting/alerts/%s' % alert.alert_id
)
lock.acquire(
blocking=True,
lock_ttl=60
)
if lock.is_acquired:
# renew a lock
lock.acquire(lock_ttl=60)
for plugin in NotificationPlugin.plugins:
plugin.dispatch_notification(alert)
update_alert_delivery(alert)
lock.release()
except(
AttributeError,
SyntaxError,
ValueError,
KeyError,
TypeError,
etcd.EtcdException
)as ex:
Event(
Expand Down

0 comments on commit 401bb45

Please sign in to comment.