From cf6d9c40405b907ce8ceb269173214196fa1fc27 Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Sat, 18 Aug 2018 00:23:48 +1000 Subject: [PATCH 1/1] more bugfixing & allowing for script to be called from anywhere --- logparse.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/logparse.py b/logparse.py index b416218..d7ec38e 100755 --- a/logparse.py +++ b/logparse.py @@ -24,7 +24,7 @@ HDDTEMPPORT = 7634 SUMMARYPATH = "/mnt/andrew/temp/logparse-test.html" OUTPUTPATH = "/mnt/andrew/temp/logparse-test2.html" MAILPATH = "/mnt/andrew/temp/log-parse-test-3.html" -HEADERPATH = "header.html" +HEADERPATH = os.path.dirname(os.path.realpath(__file__)) + "/header.html" STYLEPATH = "main.css" MAILOUT = "" HTMLOUT = "" @@ -176,7 +176,11 @@ def readlog(path = None, mode = 'r'): # read file, substituting known paths return else: path = pathpattern.sub(lambda m: pathfilter[re.escape(m.group(0))], path) - return open(path, mode).read() + if (os.path.isfile(path) is False): + logger.error(path + " does not exist") + return '' + else: + return open(path, mode).read() def writelog(path = None, content = "", mode = 'w'): # read file, substituting known paths if (path == None or content == None): @@ -305,7 +309,7 @@ def sudo(): else: for user in users: data.append(user[0] + ' (' + str(user[1]) + ')') - logger.debug("found " + str(len(matches)) + " sudo sessions for users " + str(data)) + logger.debug("found " + str(num) + " sudo sessions for users " + str(data)) writedata(subtitle, data) if (len(commands) > 0): commands = addtag(commands, 'code') @@ -460,12 +464,15 @@ def smbd(): logger.debug("starting smbd section") opentag('div', 1, 'smbd', 'section') files = glob.glob(SMBDDIR + "/log.*[!\.gz][!\.old]") # find list of logfiles + logger.debug("found log files " + str(files)) n_auths = 0 # total number of logins from all users sigma_auths = [] # contains users output = "" for file in files: # one log file for each client + logger.debug("looking at file " + file) + # find the machine (ip or hostname) that this file represents ip = re.search('log\.(.*)', file).group(1) # get ip or hostname from file path (/var/log/samba/log.host) host = resolve(ip) @@ -536,6 +543,7 @@ def zfs(): logger.debug("starting zfs section") opentag('div', 1, 'zfs', 'section') zfslog = readlog('zfs') + logger.debug("zfs log is " + zfslog) logger.debug("got zfs logfile\n" + zfslog + "---end log---") pool = re.search('.*---\n(\w*)', zfslog).group(1) scrub = re.search('.*scrub repaired (\d*) in \d*h\d*m with (\d*) errors on (\S*\s)(\S*)\s(\d+\s)', zfslog) -- 2.43.2