Commit 9be1a42f authored by Daniel Armbruster's avatar Daniel Armbruster Committed by thomas.forbriger
Browse files

corrections and adjustments

This is a legacy commit from before 2015-05-18.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.

SVN Path:
SVN Revision: 4695
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 6c51c49f
......@@ -127,7 +127,7 @@ class CsbackLog:
def getLogger(self):
return self.logger
formatter = '%(name)-8s[%(process)d]: %(levelname)-8s %(message)s'
formatter = ' %(name)-8s[%(process)d]: %(levelname)-8s %(message)s'
# ----------------------------------------------------------------------------
if __name__ == "__main__":
......@@ -109,6 +109,7 @@ def help():
-P|--port ARG SMTP port.
-H|--host ARG Hostname of the SMTP server.
-t|--tls Use TLS encryption.
-u|--username ARG Username for SMTP server login.
-p|--password ARG Password for SMTP server login.
-n|--nagios Use csbackntfy in it's nagios mode and print the current
......@@ -132,9 +133,9 @@ def main(argv=None):
argv = sys.argv
opts, args = getopt.getopt(argv[1:], "vhdlr:s:P:H:u:p:n", ["help", \
opts, args = getopt.getopt(argv[1:], "vhdlr:s:P:H:u:p:nt", ["help", \
"verbose", "debug", "logging", "receiver=", "sender=", "port=", \
"host=", "username=", "password=", '--nagios'])
"host=", "username=", "password=", '--nagios', '--tls'])
except getopt.GetoptError as err:
raise Usage(139,err.msg)
verbose = False
......@@ -146,6 +147,7 @@ def main(argv=None):
username = ''
password = ''
nagiosMode = False
useTLS = False
# collect commandline arguments
for opt, arg in opts:
if opt in ("-v", "--verbose"):
......@@ -173,6 +175,8 @@ def main(argv=None):
password = arg
elif opt in ("-n", "--nagios"):
nagiosMode = True
elif opt in ("-t", "--tls"):
useTLS = True
raise Usage(177,"Unhandled option chosen.")
......@@ -204,7 +208,7 @@ def main(argv=None):
logger.getLogger().info("Reading logfile(s) ...")
for path in logFilePathes:
for line in open(path, 'r+').readlines():
for line in open(path, 'r').readlines():
if line.find('INFO'):
elif line.find('WARNING'):
......@@ -308,7 +312,10 @@ def main(argv=None):
logger.getLogger().debug("Sending email.")
session = smtplib.SMTP(host=host, port=port)
if useTLS:
session.login(username, password)
session.sendmail(sender, receivers, mail.as_string())
except smtplib.SMTPRecipientsRefused:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment