summaryrefslogtreecommitdiffstats
path: root/events/src/utils.py
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2016-10-26 15:51:17 +0530
committerAravinda VK <avishwan@redhat.com>2016-11-17 03:10:25 -0800
commitb7ebffbda9ba784ccfae6d1a90766d5310cdaa15 (patch)
treea7557066d5676d7e4f3df54ad3e33a4512a29cd8 /events/src/utils.py
parent46e5466850311ee69e6ae9a11c2bba2aabadd5de (diff)
eventsapi: Auto reload Webhooks data when modified
glustereventsd depends on reload signal to reload the Webhooks configurations. But if reload signal missed, no events will be sent to newly added Webhook. Added auto reload based on webhooks file mtime. Before pushing events to Webhooks, reloads webhooks configurations if previously recorded mtime is different than current mtime. BUG: 1388862 Change-Id: I83a41d6a52d8fa1d70e88294298f4a5c396d4158 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15731 Reviewed-by: Prashanth Pai <ppai@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'events/src/utils.py')
-rw-r--r--events/src/utils.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/events/src/utils.py b/events/src/utils.py
index 6f695c37eba..e69d6577ff0 100644
--- a/events/src/utils.py
+++ b/events/src/utils.py
@@ -25,6 +25,7 @@ import eventtypes
# Webhooks list
_webhooks = {}
+_webhooks_file_mtime = 0
# Default Log Level
_log_level = "INFO"
# Config Object
@@ -117,10 +118,12 @@ def load_webhooks():
Load/Reload the webhooks list. This function will
be triggered during init and when SIGUSR2.
"""
- global _webhooks
+ global _webhooks, _webhooks_file_mtime
_webhooks = {}
if os.path.exists(WEBHOOKS_FILE):
_webhooks = json.load(open(WEBHOOKS_FILE))
+ st = os.lstat(WEBHOOKS_FILE)
+ _webhooks_file_mtime = st.st_mtime
def load_all():
@@ -138,6 +141,8 @@ def publish(ts, event_key, data):
if NodeID is None:
NodeID = get_node_uuid()
+ autoload_webhooks()
+
message = {
"nodeid": NodeID,
"ts": int(ts),
@@ -151,6 +156,20 @@ def publish(ts, event_key, data):
pass
+def autoload_webhooks():
+ global _webhooks_file_mtime
+ try:
+ st = os.lstat(WEBHOOKS_FILE)
+ except OSError:
+ st = None
+
+ if st is not None:
+ # If Stat is available and mtime is not matching with
+ # previously recorded mtime, reload the webhooks file
+ if st.st_mtime != _webhooks_file_mtime:
+ load_webhooks()
+
+
def plugin_webhook(message):
# Import requests here since not used in any other place
import requests