mirror of https://github.com/fail2ban/fail2ban
ENH: minor, just pythonized some parts of fail2ban-regex summary
parent
2245ff5b41
commit
d2ffee0b2d
|
@ -29,7 +29,7 @@ import getopt, sys, time, logging, os
|
||||||
|
|
||||||
# Inserts our own modules path first in the list
|
# Inserts our own modules path first in the list
|
||||||
# fix for bug #343821
|
# fix for bug #343821
|
||||||
sys.path.insert(1, "/usr/share/fail2ban")
|
#sys.path.insert(1, "/usr/share/fail2ban")
|
||||||
|
|
||||||
from client.configparserinc import SafeConfigParserWithIncludes
|
from client.configparserinc import SafeConfigParserWithIncludes
|
||||||
from ConfigParser import NoOptionError, NoSectionError, MissingSectionHeaderError
|
from ConfigParser import NoOptionError, NoSectionError, MissingSectionHeaderError
|
||||||
|
@ -248,50 +248,29 @@ class Fail2banRegex:
|
||||||
print "Results"
|
print "Results"
|
||||||
print "======="
|
print "======="
|
||||||
print
|
print
|
||||||
|
|
||||||
|
def print_failregexes(title, failregexes):
|
||||||
|
# Print title
|
||||||
|
print title
|
||||||
|
print "|- Regular expressions:"
|
||||||
|
for cnt, failregex in enumerate(failregexes):
|
||||||
|
print "| [%d] %s" % (cnt+1, failregex.getFailRegex())
|
||||||
|
print "|"
|
||||||
|
|
||||||
|
# Print stats
|
||||||
|
total = 0
|
||||||
|
print "`- Number of matches:"
|
||||||
|
for cnt, failregex in enumerate(failregexes):
|
||||||
|
match = failregex.getStats()
|
||||||
|
total += match
|
||||||
|
print " [%d] %s match(es)" % (cnt+1, match)
|
||||||
|
print
|
||||||
|
return total
|
||||||
|
|
||||||
# Print title
|
# Print title
|
||||||
cnt = 1
|
total = print_failregexes("Failregex", self.__failregex)
|
||||||
print "Failregex"
|
_ = print_failregexes("Ignoreregex", self.__ignoreregex)
|
||||||
print "|- Regular expressions:"
|
|
||||||
for failregex in self.__failregex:
|
|
||||||
print "| [" + str(cnt) + "] " + failregex.getFailRegex()
|
|
||||||
cnt += 1
|
|
||||||
cnt = 1
|
|
||||||
|
|
||||||
print "|"
|
|
||||||
|
|
||||||
# Print stats
|
|
||||||
cnt = 1
|
|
||||||
total = 0
|
|
||||||
print "`- Number of matches:"
|
|
||||||
for failregex in self.__failregex:
|
|
||||||
match = failregex.getStats()
|
|
||||||
total += match
|
|
||||||
print " [" + str(cnt) + "] " + str(match) + " match(es)"
|
|
||||||
cnt += 1
|
|
||||||
|
|
||||||
print
|
|
||||||
|
|
||||||
# Print title
|
|
||||||
cnt = 1
|
|
||||||
print "Ignoreregex"
|
|
||||||
print "|- Regular expressions:"
|
|
||||||
for failregex in self.__ignoreregex:
|
|
||||||
print "| [" + str(cnt) + "] " + failregex.getFailRegex()
|
|
||||||
cnt += 1
|
|
||||||
cnt = 1
|
|
||||||
|
|
||||||
print "|"
|
|
||||||
|
|
||||||
# Print stats
|
|
||||||
cnt = 1
|
|
||||||
print "`- Number of matches:"
|
|
||||||
for failregex in self.__ignoreregex:
|
|
||||||
match = failregex.getStats()
|
|
||||||
print " [" + str(cnt) + "] " + str(match) + " match(es)"
|
|
||||||
cnt += 1
|
|
||||||
|
|
||||||
print
|
|
||||||
print "Summary"
|
print "Summary"
|
||||||
print "======="
|
print "======="
|
||||||
print
|
print
|
||||||
|
@ -304,26 +283,19 @@ class Fail2banRegex:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
# Print stats
|
# Print stats
|
||||||
cnt = 1
|
|
||||||
print "Addresses found:"
|
print "Addresses found:"
|
||||||
for failregex in self.__failregex:
|
for cnt, failregex in enumerate(self.__failregex):
|
||||||
print "[" + str(cnt) + "]"
|
print "[%d]" % (cnt+1)
|
||||||
for ip in failregex.getIPList():
|
for ip in failregex.getIPList():
|
||||||
timeTuple = time.localtime(ip[1])
|
timeTuple = time.localtime(ip[1])
|
||||||
timeString = time.strftime("%a %b %d %H:%M:%S %Y", timeTuple)
|
timeString = time.strftime("%a %b %d %H:%M:%S %Y", timeTuple)
|
||||||
if ip[2]:
|
print " %s (%s)%s" % (
|
||||||
dup = " (already matched)"
|
ip[0], timeString, ip[2] and " (already matched)" or "")
|
||||||
else:
|
|
||||||
dup = ""
|
|
||||||
print " " + ip[0] + " (" + timeString + ")" + dup
|
|
||||||
cnt += 1
|
|
||||||
|
|
||||||
print
|
print
|
||||||
|
|
||||||
print "Date template hits:"
|
print "Date template hits:"
|
||||||
for template in self.__filter.dateDetector.getTemplates():
|
for template in self.__filter.dateDetector.getTemplates():
|
||||||
print `template.getHits()` + " hit(s): " + template.getName()
|
print `template.getHits()` + " hit(s): " + template.getName()
|
||||||
|
|
||||||
print
|
print
|
||||||
|
|
||||||
print "Success, the total number of match is " + str(total)
|
print "Success, the total number of match is " + str(total)
|
||||||
|
|
Loading…
Reference in New Issue