summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2014-07-16 23:04:26 +0200
committerFlorian Pritz <bluewind@xinu.at>2014-07-16 23:04:26 +0200
commit465769cd00069d8c0b0af73bc8072012f242d5a9 (patch)
tree5ed3277c916e4edc36b9a2847fecf59d69a80489
parent8c399f7c9e5c798f9c8797a0db92c5299726b058 (diff)
downloadbin-465769cd00069d8c0b0af73bc8072012f242d5a9.tar.gz
bin-465769cd00069d8c0b0af73bc8072012f242d5a9.tar.xz
smokemtr.py: make sendmail/SMTP configurable
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-xsmokemtr.py23
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())