Skip to content

fix parser and print rows counter #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions modsec-log-parser.py
Original file line number Diff line number Diff line change
@@ -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()


3 changes: 1 addition & 2 deletions src/log_entry.py
Original file line number Diff line number Diff line change
@@ -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)

9 changes: 4 additions & 5 deletions src/modsec_log_parser.py
Original file line number Diff line number Diff line change
@@ -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()