diff --git a/modsec-log-compare.py b/modsec-log-compare.py index ae53f2b..d3eafcb 100755 --- a/modsec-log-compare.py +++ b/modsec-log-compare.py @@ -40,14 +40,14 @@ def load(fname): def print_help(): - print " " - print "Use: modsec-log-compare.py [options] " - print " " + print(" ") + print("Use: modsec-log-compare.py [options] ") + print(" ") def plog(a): for i in a: - print " - " + str(i) + print(" - " + str(i)) def main(): parser = argparse.ArgumentParser() @@ -65,8 +65,8 @@ def main(): contentFileA = load(fileA) contentFileB = load(fileB) - print "file A: " + fileA + ". Elements: " + str(len(contentFileA)) + "." - print "file B: " + fileB + ". Elements: " + str(len(contentFileB)) + "." + print("file A: " + fileA + ". Elements: " + str(len(contentFileA)) + ".") + print("file B: " + fileB + ". Elements: " + str(len(contentFileB)) + ".") for i in contentFileA: @@ -84,15 +84,15 @@ def main(): diff = True if diff: - print "*** diff at: " + str(i) - print "In: " + str(fileA) + print("*** diff at: " + str(i)) + print("In: " + str(fileA)) plog(objA) - print " " - print "In: " + str(fileB) + print(" ") + print("In: " + str(fileB)) plog(objB) - print " " + print(" ") else: - #print "B does not have: " + str(i) + #print("B does not have: " + str(i)) pass diff --git a/modsec-log-parser.py b/modsec-log-parser.py index ab5e800..8533a85 100755 --- a/modsec-log-parser.py +++ b/modsec-log-parser.py @@ -28,14 +28,13 @@ def main(): parser.add_argument('--delim', type=str) parser.add_argument('files', nargs='*') args = parser.parse_args() - print(args.files, args.summary) files = args.files summary = args.summary delim = args.delim if len(files) == 0: files = "/dev/stdin" - if len(summary) == 0: + if not summary or len(summary) == 0: summary = "id,msg" msclp = ModSecLogParser(files) @@ -47,19 +46,19 @@ def main(): for i in data: z = "" - for xx in summary.split(","): + for xx in summary.split(","): if len(z) > 0: - z = z + str(delim) + z = z + str(delim) z = z + str(i.__dict__[xx]) - if i.id in ar: - ar[z] = ar[str(i.id)] + 1 - else: - ar[z] = 1 + if i.id in ar: + ar[z] = ar[str(i.id)] + 1 + else: + ar[z] = 1 for i in ar: - print str(i) + print(str(i)) if __name__=="__main__": main() diff --git a/src/log_entry.py b/src/log_entry.py index 9591832..94a4410 100644 --- a/src/log_entry.py +++ b/src/log_entry.py @@ -42,7 +42,7 @@ def __init__(self, string = None): if string != None: a = re.findall(r"\[[^\]]+]", string) for i in a: - b = re.findall(r"\[([^ ]+) \"?(.*)\"?\]$", i) + b = re.findall(r"\[([^ ]+) \"?([^\"]*)\"?\]$", i) if len(b) == 0: continue b = b[0] diff --git a/src/modsec_log_parser.py b/src/modsec_log_parser.py index d571b24..540350e 100644 --- a/src/modsec_log_parser.py +++ b/src/modsec_log_parser.py @@ -17,7 +17,7 @@ """ import fileinput -from log_entry import LogEntry +from .log_entry import LogEntry class ModSecLogParser: def __init__(self, watch = None): @@ -25,9 +25,10 @@ def __init__(self, watch = None): self.logs = [] def run(self): - for line in fileinput.input(self.watch): + for line in fileinput.input(self.watch): l = LogEntry(string = line) - self.logs.append(l) + if l.id is not None: + self.logs.append(l) return self.logs self.sumarize()