-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncEmailNotification.py
75 lines (54 loc) · 1.76 KB
/
SyncEmailNotification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
__author__ = 'chuqiao'
import smtplib
import base64
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
def viewlog(file):
file = open("syncsolr.log")
file.seek(0,2)# Go to the end of the file
while True:
line = file.readline()
if "***Finished synchronizing***" in line:
mailUpdate()
elif "***Synchronize failed***" in line:
mailAlert()
def mailUpdate():
fromaddr = '[email protected]'
toaddr = '[email protected]'
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "[Sync-reports] Synchronise two Solrs"
body = '''The IAnn Solr is now synchronised with the Bioevents Solr.
'''
msg.attach(MIMEText(body, 'plain'))
username = 'bioeventsportal'
password = base64.b64decode('YmlvZXZlbnRzMzIx')
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(username, password)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
def mailAlert():
fromaddr = '[email protected]'
toaddr = '[email protected]'
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "[Sync-reports]Synchronise two Solrs failed"
body = '''The synchronisation of two Solrs failed.
'''
msg.attach(MIMEText(body, 'plain'))
username = 'bioeventsportal'
password = base64.b64decode('YmlvZXZlbnRzMzIx')
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(username, password)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
if __name__ == '__main__':
viewlog(file)