-
Notifications
You must be signed in to change notification settings - Fork 4
/
alert.py
54 lines (39 loc) · 1.18 KB
/
alert.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
from configuration import botAlert, mailConfig
import smtplib
from email.message import EmailMessage
class Mail:
def send(self, subject, message):
msg = EmailMessage()
msg.set_content(message)
msg['Subject'] = subject
msg['From'] = mailConfig['from']
msg['To'] = mailConfig['to']
s = smtplib.SMTP(mailConfig['smtp'], mailConfig['port'], None, 3)
s.login(mailConfig['username'], mailConfig['password'])
try:
s.send_message(msg)
print('Sent alert "' + message + '" via email')
finally:
s.quit()
def alert(asset, message, isError=False):
if botAlert == 'email':
msg = EmailMessage()
msg.set_content(message)
if isError:
subj = 'OPI Error'
else:
subj = 'OPI Alert'
if asset:
subj = subj + ', Asset: ' + asset
mail = Mail()
mail.send(subj, message)
if isError:
exit(1)
else:
if asset:
print('Asset: ' + asset)
print(message)
if isError:
exit(1)
def botFailed(asset, message):
return alert(asset, message, True)