mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-27 00:07:16 +00:00
chg: [Trackers] email notifications: add tracker description in email subject
This commit is contained in:
parent
0c23c24a06
commit
4ca02a7243
4 changed files with 37 additions and 7 deletions
|
@ -23,7 +23,7 @@ config_loader = ConfigLoader.ConfigLoader()
|
||||||
publisher.port = 6380
|
publisher.port = 6380
|
||||||
publisher.channel = "Script"
|
publisher.channel = "Script"
|
||||||
|
|
||||||
def sendEmailNotification(recipient, alert_name, content):
|
def sendEmailNotification(recipient, mail_subject, mail_body):
|
||||||
|
|
||||||
sender = config_loader.get_config_str("Notifications", "sender")
|
sender = config_loader.get_config_str("Notifications", "sender")
|
||||||
sender_user = config_loader.get_config_str("Notifications", "sender_user")
|
sender_user = config_loader.get_config_str("Notifications", "sender_user")
|
||||||
|
@ -60,14 +60,13 @@ def sendEmailNotification(recipient, alert_name, content):
|
||||||
mime_msg = MIMEMultipart()
|
mime_msg = MIMEMultipart()
|
||||||
mime_msg['From'] = sender
|
mime_msg['From'] = sender
|
||||||
mime_msg['To'] = recipient
|
mime_msg['To'] = recipient
|
||||||
mime_msg['Subject'] = "AIL Framework " + alert_name + " Alert"
|
mime_msg['Subject'] = mail_subject
|
||||||
|
|
||||||
body = content
|
mime_msg.attach(MIMEText(mail_body, 'plain'))
|
||||||
mime_msg.attach(MIMEText(body, 'plain'))
|
|
||||||
|
|
||||||
smtp_server.sendmail(sender, recipient, mime_msg.as_string())
|
smtp_server.sendmail(sender, recipient, mime_msg.as_string())
|
||||||
smtp_server.quit()
|
smtp_server.quit()
|
||||||
print('Send notification ' + alert_name + ' to '+recipient)
|
print('Send notification: ' + mail_subject + ' to '+recipient)
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
traceback.print_tb(err.__traceback__)
|
traceback.print_tb(err.__traceback__)
|
||||||
|
|
|
@ -20,6 +20,7 @@ from packages import Item
|
||||||
from packages import Term
|
from packages import Term
|
||||||
|
|
||||||
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib'))
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib'))
|
||||||
|
import Tracker
|
||||||
import regex_helper
|
import regex_helper
|
||||||
|
|
||||||
full_item_url = "/showsavedpaste/?paste="
|
full_item_url = "/showsavedpaste/?paste="
|
||||||
|
@ -42,9 +43,10 @@ def new_term_found(term, term_type, item_id, item_date):
|
||||||
|
|
||||||
mail_to_notify = Term.get_term_mails(term_uuid)
|
mail_to_notify = Term.get_term_mails(term_uuid)
|
||||||
if mail_to_notify:
|
if mail_to_notify:
|
||||||
|
mail_subject = Tracker.get_email_subject(tracker_uuid)
|
||||||
mail_body = mail_body_template.format(term, item_id, full_item_url, item_id)
|
mail_body = mail_body_template.format(term, item_id, full_item_url, item_id)
|
||||||
for mail in mail_to_notify:
|
for mail in mail_to_notify:
|
||||||
NotificationHelper.sendEmailNotification(mail, 'Term Tracker', mail_body)
|
NotificationHelper.sendEmailNotification(mail, mail_subject, mail_body)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
publisher.port = 6380
|
publisher.port = 6380
|
||||||
|
|
|
@ -18,6 +18,8 @@ import NotificationHelper
|
||||||
from packages import Item
|
from packages import Item
|
||||||
from packages import Term
|
from packages import Term
|
||||||
|
|
||||||
|
from lib import Tracker
|
||||||
|
|
||||||
full_item_url = "/showsavedpaste/?paste="
|
full_item_url = "/showsavedpaste/?paste="
|
||||||
|
|
||||||
mail_body_template = "AIL Framework,\nNew occurrence for term tracked term: {}\nitem id: {}\nurl: {}{}"
|
mail_body_template = "AIL Framework,\nNew occurrence for term tracked term: {}\nitem id: {}\nurl: {}{}"
|
||||||
|
@ -48,9 +50,10 @@ def new_term_found(term, term_type, item_id, item_date):
|
||||||
|
|
||||||
mail_to_notify = Term.get_term_mails(term_uuid)
|
mail_to_notify = Term.get_term_mails(term_uuid)
|
||||||
if mail_to_notify:
|
if mail_to_notify:
|
||||||
|
mail_subject = Tracker.get_email_subject(tracker_uuid)
|
||||||
mail_body = mail_body_template.format(term, item_id, full_item_url, item_id)
|
mail_body = mail_body_template.format(term, item_id, full_item_url, item_id)
|
||||||
for mail in mail_to_notify:
|
for mail in mail_to_notify:
|
||||||
NotificationHelper.sendEmailNotification(mail, 'Term Tracker', mail_body)
|
NotificationHelper.sendEmailNotification(mail, mail_subject, mail_body)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
26
bin/lib/Tracker.py
Executable file
26
bin/lib/Tracker.py
Executable file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*-coding:UTF-8 -*
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import redis
|
||||||
|
|
||||||
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/'))
|
||||||
|
import ConfigLoader
|
||||||
|
|
||||||
|
import item_basic
|
||||||
|
|
||||||
|
config_loader = ConfigLoader.ConfigLoader()
|
||||||
|
r_serv_tracker = config_loader.get_redis_conn("ARDB_Tracker")
|
||||||
|
config_loader = None
|
||||||
|
|
||||||
|
get_tracker_description(tracker_uuid):
|
||||||
|
return r_serv_tracker.hget('tracker:{}'.format(term_uuid), 'description')
|
||||||
|
|
||||||
|
def get_email_subject(tracker_uuid):
|
||||||
|
tracker_description = get_tracker_description(tracker_uuid)
|
||||||
|
if not tracker_description:
|
||||||
|
return "AIL framework: Tracker Alert"
|
||||||
|
else:
|
||||||
|
return 'AIL framework: {}'.format(tracker_description)
|
Loading…
Reference in a new issue