Skip to content
Snippets Groups Projects
Commit c213cbab authored by Auke Klazema's avatar Auke Klazema
Browse files

Task #10707: First version of the actual emailing

parent 7802bba5
No related branches found
No related tags found
No related merge requests found
......@@ -17,9 +17,10 @@
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
import dateutil
import smtplib
import logging
from email.mime.text import MIMEText
from datetime import timedelta, datetime
from lofar.sas.otdb.OTDBBusListener import OTDBBusListener
from lofar.common.util import waitForInterrupt
......@@ -29,9 +30,9 @@ from lofar.sas.TriggerEmailService.common.config import DEFAULT_TRIGGER_NOTIFICA
from lofar.mom.momqueryservice.momqueryrpc import MoMQueryRPC
from lxml import etree
from StringIO import StringIO
from lofar.common.datetimeutils import parseDatetime
from re import findall
logger = logging.getLogger(__name__)
received_template_subject = """%(PROJECTNAME)s trigger %(TRIGGERID)s received"""
......@@ -101,8 +102,25 @@ kind regards,
LOFAR Science Operations & Support [ sos@astron.nl ]"""
def email(mom_id, subject, body, attachment):
pass
def email(recipients, subject, body, attachment):
recipients.append("sos@astron.nl")
recipients.append("operator@astron.nl")
sender = "Trigger Email Service <no-reply@astron.nl>"
COMMASPACE = ', '
msg = MIMEText(body)
msg["Subject"] = subject
msg["From"] = sender
msg["To"] = COMMASPACE.join(recipients)
if attachment:
txt = MIMEText(attachment)
msg.attach(txt)
s = smtplib.SMTP('localhost')
s.sendmail(sender, recipients, msg.as_string())
s.quit()
class OTDBTriggerListener(OTDBBusListener):
......@@ -137,8 +155,13 @@ class OTDBTriggerListener(OTDBBusListener):
trigger_id = self.mom_rpc_client.get_trigger_id(mom_id)
if trigger_id:
self._send_email(otdb_id, mom_id, trigger_id, template_subject, template_body)
def _send_email(self, otdb_id, mom_id, trigger_id, template_subject, template_body):
subject, body = self._fill_template(otdb_id, mom_id, trigger_id, template_subject, template_body)
email(mom_id, subject, body, None)
recipients = self._get_recipients(mom_id)
email(recipients, subject, body, None)
def _fill_template(self, otdb_id, mom_id, trigger_id, template_subject, template_body):
project = self.mom_rpc_client.getProject(mom_id)
......@@ -153,6 +176,16 @@ class OTDBTriggerListener(OTDBBusListener):
return subject, body
def _get_recipients(self, mom_id):
recipients = []
emails = self.mom_rpc_client.get_project_details(mom_id)
for k, v in emails.items:
recipients.append(v)
return recipients
class TriggerNotificationListener(AbstractBusListener):
def __init__(self, momquery_rpc = MoMQueryRPC(), busname=DEFAULT_TRIGGER_NOTIFICATION_BUSNAME, subject=DEFAULT_TRIGGER_NOTIFICATION_SUBJECT, broker=None, **kwargs):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment