From 465769cd00069d8c0b0af73bc8072012f242d5a9 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 16 Jul 2014 23:04:26 +0200 Subject: smokemtr.py: make sendmail/SMTP configurable Signed-off-by: Florian Pritz --- smokemtr.py | 23 ++++++++++++++++++++--- 1 file 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 ' 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()) -- cgit v1.2.3-24-g4f1b