Commit 362a7b8a authored by Daniel Armbruster's avatar Daniel Armbruster Committed by thomas.forbriger
Browse files

take csback status file into consideration

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:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4942
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 7eacf294
......@@ -40,6 +40,7 @@
# 19/05/2012 V0.5 Bug fixed - str.find didn't work as expected.
# 10/12/2012 V0.6 provide '-D ARG' option to list only most recent error
# messages
# 23/01/2013 V0.7 consider additional csback status file
#
# =============================================================================
"""
......@@ -58,7 +59,7 @@ import datetime as dt
from email.mime.text import MIMEText
from collections import deque
__version__ = "V0.6"
__version__ = "V0.7"
__subversion__ = "$Id$"
__license__ = "GPLv2"
__author__ = "Daniel Armbruster"
......@@ -81,15 +82,15 @@ class Usage(Error):
def display(self):
usage_text = "Version: "+__version__+"\nLicense: "+__license__+ \
"\n"+__subversion__+"\nAuthor: "+__author__+ """
Usage: csbackntfy [-v|--verbose] [-d|--debug] [-l|--logging] [-D ARG]
-P|--port ARG -H|--host ARG -u|--username ARG
-p|--password ARG
Usage: csbackntfy [-v|--verbose] [-d|--debug] [-l|--logging] [-D|--days ARG]
[-S|--Status ARG] -P|--port ARG -H|--host ARG
-u|--username ARG -p|--password ARG
-r|--receiver ADDRESS [-r|--receiver ADDRESS [...]]
-s|--sender ADDRESS [PATH [PATH [...]]]
or: csbackntfy [-v|--verbose] [-d|--debug] [-l|--logging] [-D ARG]
-n|--nagios [PATH [PATH [...]]]
or: csbackntfy [-v|--verbose] [-d|--debug] [-l|--logging] [-D ARG] -o|--out
[PATH [PATH [...]]]
or: csbackntfy [-v|--verbose] [-d|--debug] [-l|--logging] [-D|--days ARG]
[-S|--Status ARG] -n|--nagios [PATH [PATH [...]]]
or: csbackntfy [-v|--verbose] [-d|--debug] [-l|--logging] [-D|--days ARG]
[-S|--Status ARG] -o|--out [PATH [PATH [...]]]
or: csbackntfy -h|--help\n"""
sys.stderr.write("csbackntfy [line "+self.line+"]: "+self.msg+"\n")
sys.stderr.write(usage_text)
......@@ -102,14 +103,14 @@ def help():
help_text = "Version: "+__version__+"\nLicense: "+__license__+"\n"+ \
__subversion__+"\nAuthor: "+__author__+"""
Usage: csbackntfy [-v|--verbose] [-d|--debug] [-l|--logging] [-D|--days ARG]
-P|--port ARG -H|--host ARG -u|--username ARG
-p|--password ARG
[-S|--Status ARG] -P|--port ARG -H|--host ARG
-u|--username ARG -p|--password ARG
-r|--receiver ADDRESS [-r|--receiver ADDRESS [...]]
-s|--sender ADDRESS [PATH [PATH [...]]]
or: csbackntfy [-v|--verbose] [-d|--debug] [-l|--logging] [-D|--days ARG]
-n|--nagios [PATH [PATH [...]]]
[-S|--Status ARG] -n|--nagios [PATH [PATH [...]]]
or: csbackntfy [-v|--verbose] [-d|--debug] [-l|--logging] [-D|--days ARG]
-o|--out [PATH [PATH [...]]]
[-S|--Status ARG] -o|--out [PATH [PATH [...]]]
or: csbackntfy -h|--help
-------------------------------------------------------------------------------
-v|--verbose Be verbose.
......@@ -131,10 +132,16 @@ def help():
-D|--days ARG List only WARNING/ERROR/CRITICAL messages of last ARG days.
If ARG is equal to 0 (zero) then all messages are listed
(default).
-S|--Status ARG Take additional csback status file into consideration. The
path to the status file is ARG. If a csback status file
contains CRITICAL entries the status of the mail always is
set to CRITICAL. After resolving the issues the content of
the file should be removed such that the actual notification
status only depends on logfile(s).
PATH Path(s) of the logfile(s) to check. If not specified the
logfiles in /var/log/ were investigated.
-------------------------------------------------------------------------------
csback distibuishes foru different levels of message criticality:
csback distiguishes four different levels of message criticality:
INFO: indicates normal operation
WARNING: indicates any problems which were expected and are tolerated
CRITICAL: indicates a checksum mismatch
......@@ -160,11 +167,12 @@ def main(argv=None):
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "vhdlr:s:P:H:u:p:ntoD:", ["help", \
opts, args = getopt.getopt(argv[1:], "vhdlr:s:P:H:u:p:ntoD:S:", ["help", \
"verbose", "debug", "logging", "receiver=", "sender=", "port=", \
"host=", "username=", "password=", 'nagios', 'tls', 'out', 'days'])
"host=", "username=", "password=", 'nagios', 'tls', 'out', 'days', \
"Status="])
except getopt.GetoptError as err:
raise Usage(167,err.msg)
raise Usage(175,err.msg)
verbose = False
debugMode = False
receivers = []
......@@ -177,6 +185,7 @@ def main(argv=None):
useTLS = False
stdoutMode = False
daysToList=0
useCsbackStatusFile = False
# collect commandline arguments
for opt, arg in opts:
......@@ -209,14 +218,17 @@ def main(argv=None):
useTLS = True
elif opt in ("-o", "--out"):
stdoutMode = True
elif opt in ("-S", "--Status"):
useCsbackStatusFile = True
csbackStatusFile = arg
elif opt in ("-D", "--days"):
daysToList = int(arg)
if daysToList < 0:
raise Usage(215,\
raise Usage(227,\
"Invalid argument passed. Value must be equal to or \
\t greater than 0.")
else:
raise Usage(219,"Unhandled option chosen.")
raise Usage(231,"Unhandled option chosen.")
if verbose or debugMode:
logger.addHandler(console)
......@@ -232,7 +244,7 @@ def main(argv=None):
if None != re.match('^csback\.log$', logfile)]
logFilePathes.reverse()
else:
raise Usage(235,"Invalid argument(s).")
raise Usage(247,"Invalid argument(s).")
# compute time limit for WARNING/ERROR/CRITICAL messages to display
now=dt.datetime.now()
......@@ -259,21 +271,31 @@ def main(argv=None):
for n in line.split()[0:3]),"%Y %b %d %H:%M:%S")
if 'CRITICAL' in line:
if timeStamp > timeLimit:
criticalList.append("logfile:"+path+"\n"+line)
criticalList.append("logfile: "+path+"\n"+line)
elif 'ERROR' in line:
if timeStamp > timeLimit:
errorList.append("logfile:"+path+"\n"+line)
errorList.append("logfile: "+path+"\n"+line)
elif 'WARNING' in line:
if timeStamp > timeLimit:
warningDeque.appendleft("logfile:"+path+"\n"+line)
warningDeque.appendleft("logfile: "+path+"\n"+line)
elif 'INFO' in line:
infoDeque.appendleft("logfile:"+path+"\n"+line)
infoDeque.appendleft("logfile: "+path+"\n"+line)
else:
logger.getLogger().info("Illegal line in logfile found: '"+line+"'")
except IOError as err:
raise Error(274, "Error while reading logfiles: "+err.filename)
raise Error(286, "Error while reading logfiles: "+err.filename)
logger.getLogger().debug("Finished reading logfile(s).")
# take status file into consideration
if useCsbackStatusFile:
logger.getLogger().info("Taking csback status file into consideration.")
try:
for line in open(csbackStatusFile, 'r').readlines():
if 'CRITICAL' in line:
criticalList.append("CSBACK STATUS FILE: "+path+"\n"+line)
except:
logger.getLogger().info("csback status file not available.")
# if nagios mode had been enabled just print the status to stdout
if nagiosMode:
if len(criticalList):
......@@ -289,25 +311,25 @@ def main(argv=None):
if not stdoutMode:
logger.getLogger().debug("Checking email addresses.")
if 0 == len(sender):
raise Usage(292, "Email address of sender missing.")
raise Usage(314, "Email address of sender missing.")
if None == re.match( \
'^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$', sender):
raise Error(295, "Email address of sender not valid.")
raise Error(317, "Email address of sender not valid.")
if 0 == len(receivers):
raise Usage(297, "Email address of receiver missing.")
raise Usage(319, "Email address of receiver missing.")
for add in receivers:
if None == re.match( \
'^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$', add):
raise Error(301, "Email address of receiver not valid.")
raise Error(323, "Email address of receiver not valid.")
if 0 == len(host):
raise Usage(304, "Hostname missing.")
raise Usage(326, "Hostname missing.")
if 0 == len(username):
raise Usage(306, "Username missing.")
raise Usage(328, "Username missing.")
if 0 == len(password):
raise Usage(308, "Password missing.")
raise Usage(330, "Password missing.")
if -1 == port:
raise Usage(310, "Port missing.")
raise Usage(332, "Port missing.")
# prepare email
logger.getLogger().debug("Preparing content ...")
msg = '============================\n'
......
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