fail2ban-report/fail2ban-getlog

31 lines
749 B
Text
Raw Permalink Normal View History

2017-08-25 15:28:37 +02:00
#!/usr/bin/python3
# coding: utf-8
# Julien Pecqueur <julien@peclu.net>
from sys import argv
if len(argv) != 2:
print("Usage: fail2ban-getlog <file>")
print("Extract fail2ban logs to CSV file.")
else:
F_LOG = "/var/log/fail2ban.log"
f_old = open(argv[1], "r")
old = []
for l in f_old:
old.append(l[0:-1])
2017-09-04 10:00:35 +02:00
f_old.close()
print(len(old), "existing line(s).")
2017-08-25 15:28:37 +02:00
f_in = open(F_LOG, "r")
f_out = open(argv[1], "a+")
c = 0
for l in f_in:
l = l[0:-1].split(" ")
if "Ban" in l:
l = l[-1]+";"+l[0]+";"+l[1][0:-4]
if not l in old:
f_out.write(l+"\n")
c += 1
f_in.close()
f_out.close()
print("Added", c, "new line(s).")