Skip to content
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

Fix indentation and convert to Python3 #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 12 additions & 12 deletions modsec-log-compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def load(fname):


def print_help():
print " "
print "Use: modsec-log-compare.py [options] <file a> <file b> "
print " "
print(" ")
print("Use: modsec-log-compare.py [options] <file a> <file b> ")
print(" ")


def plog(a):
for i in a:
print " - " + str(i)
print(" - " + str(i))

def main():
parser = argparse.ArgumentParser()
Expand All @@ -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:
Expand All @@ -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


Expand Down
17 changes: 8 additions & 9 deletions modsec-log-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/log_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions src/modsec_log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
"""

import fileinput
from log_entry import LogEntry
from .log_entry import LogEntry

class ModSecLogParser:
def __init__(self, watch = None):
self.watch = watch
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()
Expand Down