- Add log4py support

- Remove old verbose mode


git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@18 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.6
Cyril Jaquier 2004-10-11 10:23:53 +00:00
parent c286d56855
commit a2ea1164b3
2 changed files with 7 additions and 10 deletions

View File

@ -28,12 +28,12 @@ import os, sys
class LogReader: class LogReader:
def __init__(self, logPath, findTime = 3600, verbose = False): def __init__(self, logPath, logSys, findTime = 3600):
self.logPath = logPath self.logPath = logPath
self.findTime = findTime self.findTime = findTime
self.ignoreIpList = [] self.ignoreIpList = []
self.lastModTime = 0 self.lastModTime = 0
self.verbose = verbose self.logSys = logSys
def addIgnoreIP(self, ip): def addIgnoreIP(self, ip):
self.ignoreIpList.append(ip) self.ignoreIpList.append(ip)
@ -45,7 +45,7 @@ class LogReader:
try: try:
fileHandler = open(self.logPath) fileHandler = open(self.logPath)
except OSError: except OSError:
print "Unable to open", self.logPath self.logSys.error("Unable to open "+self.logPath)
sys.exit(-1) sys.exit(-1)
return fileHandler return fileHandler
@ -53,14 +53,13 @@ class LogReader:
try: try:
logStats = os.stat(self.logPath) logStats = os.stat(self.logPath)
except OSError: except OSError:
print "Unable to get stat on", logPath self.logSys.error("Unable to get stat on "+self.logPath)
sys.exit(-1) sys.exit(-1)
if self.lastModTime == logStats.st_mtime: if self.lastModTime == logStats.st_mtime:
return False return False
else: else:
if self.verbose: self.logSys.debug(self.logPath+" has been modified")
print self.logPath, 'has been modified'
self.lastModTime = logStats.st_mtime self.lastModTime = logStats.st_mtime
return True return True

View File

@ -41,11 +41,9 @@ class Metalog(LogReader):
if unixTime < time.time()-self.findTime: if unixTime < time.time()-self.findTime:
continue continue
if self.inIgnoreIPList(ip): if self.inIgnoreIPList(ip):
if self.verbose: self.logSys.debug("Ignore "+ip)
print 'Ignore', ip
continue continue
if self.verbose: self.logSys.debug("Found "+ip)
print 'Found', ip, 'at', unixTime
if ipList.has_key(ip): if ipList.has_key(ip):
ipList[ip] = (ipList[ip][0]+1, unixTime) ipList[ip] = (ipList[ip][0]+1, unixTime)
else: else: