Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
c213cbab
Commit
c213cbab
authored
8 years ago
by
Auke Klazema
Browse files
Options
Downloads
Patches
Plain Diff
Task #10707: First version of the actual emailing
parent
7802bba5
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TriggerEmailService/Server/lib/TriggerEmailService.py
+39
-6
39 additions, 6 deletions
SAS/TriggerEmailService/Server/lib/TriggerEmailService.py
with
39 additions
and
6 deletions
SAS/TriggerEmailService/Server/lib/TriggerEmailService.py
+
39
−
6
View file @
c213cbab
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment