-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (29 loc) · 1004 Bytes
/
main.py
File metadata and controls
37 lines (29 loc) · 1004 Bytes
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
import os
import smtplib
import sys
from email.mime.text import MIMEText
import settings
def check():
command_line_result = os.popen(settings.EXIM_PATH + " " + settings.EXIM_MAILQUEUE_SIZE_PARAM)
check_mail_queue_size(command_line_result)
def check_mail_queue_size(command_line_result):
for line in command_line_result:
count = int(line)
if count >= settings.EXIM_WARN_QUEUE_SIZE:
raise Exception("mail queue size is " + str(count) + " and exceeds maximum value of " + str(
settings.EXIM_WARN_QUEUE_SIZE))
break
def main():
try:
check()
except Exception, e:
msg = MIMEText(e.__str__())
msg['Subject'] = "Exim error " + settings.HOSTNAME
msg['From'] = settings.FROM_MAIL
msg['To'] = settings.TO_MAIL
s = smtplib.SMTP(settings.SMTP_ADDRESS)
s.sendmail(msg['From'], [msg['To']], msg.as_string())
s.quit()
sys.exit(1)
if __name__ == "__main__":
main()