From: Andrew Lorimer Date: Fri, 17 Aug 2018 14:23:48 +0000 (+1000) Subject: more bugfixing & allowing for script to be called from anywhere X-Git-Url: https://git.lorimer.id.au/logparse.git/diff_plain/cf6d9c40405b907ce8ceb269173214196fa1fc27?ds=sidebyside;hp=0bd8554d80b6e6089afce88562cf12e847f7d7c4 more bugfixing & allowing for script to be called from anywhere --- 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)