diff --git a/modsec-log-parser.py b/modsec-log-parser.py index ab5e800..ed02051 100755 --- a/modsec-log-parser.py +++ b/modsec-log-parser.py @@ -49,19 +49,17 @@ def main(): z = "" 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 + if z in ar: + ar[z] = ar[z] + 1 else: ar[z] = 1 for i in ar: - print str(i) + print str(i) + str(delim) + str(ar[i]) if __name__=="__main__": main() - - diff --git a/src/log_entry.py b/src/log_entry.py index 9591832..e59d9ba 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] @@ -54,4 +54,3 @@ def __init__(self, string = None): def __repr__(self): return str(self.id) + ": " + str(self.msg) - diff --git a/src/modsec_log_parser.py b/src/modsec_log_parser.py index d571b24..bfc4b5c 100644 --- a/src/modsec_log_parser.py +++ b/src/modsec_log_parser.py @@ -20,16 +20,15 @@ from log_entry import LogEntry class ModSecLogParser: - def __init__(self, watch = None): + def __init__(self, watch = None): self.watch = watch self.logs = [] def run(self): for line in fileinput.input(self.watch): - l = LogEntry(string = line) - self.logs.append(l) + if line.strip().startswith("ModSecurity"): + l = LogEntry(string = line) + self.logs.append(l) return self.logs self.sumarize() - -