diff options
Diffstat (limited to 'smokemtr.py')
-rwxr-xr-x | smokemtr.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/smokemtr.py b/smokemtr.py index b52f35e..ba5a509 100755 --- a/smokemtr.py +++ b/smokemtr.py @@ -11,8 +11,15 @@ from email.mime.text import MIMEText MAIL_FROM = 'SmokeMTR <root@mistral.server-speed.net>' MAIL_TO = 'root@mistral.server-speed.net' LOG_FILE = '/tmp/smokealert.out' + +# leave empty if you don't want it to be used SENDMAIL = '/usr/bin/sendmail' -MTR = 'mtr' +# leave empty if you don't want it to be used +SMTP_HOST = '' + +# mtr binary path +MTR = '/usr/sbin/mtr' +# how many pings to send MTR_CYCLES = 20 def parse_args(): @@ -111,8 +118,18 @@ def mail_alert(subject="Smokeping alert", body=""): msg.attach(part2) #print(msg.as_string()) - sendmail = subprocess.Popen([SENDMAIL, MAIL_TO], stdin=subprocess.PIPE) - sendmail.communicate(msg.as_string()) + + if SENDMAIL != "": + sendmail = subprocess.Popen([SENDMAIL, MAIL_TO], stdin=subprocess.PIPE) + sendmail.communicate(msg.as_string()) + + if SMTP_HOST != "": + # Send the message via local SMTP server. + s = smtplib.SMTP(SMTP_HOST) + # sendmail function takes 3 arguments: sender's address, recipient's address + # and message to send - here it is sent as one string. + s.sendmail(MAIL_FROM, MAIL_TO, msg.as_string()) + s.quit() if __name__ == '__main__': mtr_host(parse_args()) |