Browse Source

- Added and changed some logging level and messages.

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@697 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 17 years ago
parent
commit
2f629525d9
  1. 4
      server/filter.py
  2. 4
      server/filtergamin.py
  3. 4
      server/filterpoll.py
  4. 7
      server/jail.py
  5. 20
      server/server.py

4
server/filter.py

@ -64,7 +64,7 @@ class Filter(JailThread):
self.__findTime = 6000
## The ignore IP list.
self.__ignoreIpList = []
logSys.info("Created Filter")
logSys.debug("Created Filter")
##
@ -411,7 +411,7 @@ import md5
class FileContainer:
def __init__(self, filename, tail = False):
def __init__(self, filename, tail = True):
self.__filename = filename
self.__tail = tail
self.__handler = None

4
server/filtergamin.py

@ -53,7 +53,7 @@ class FilterGamin(FileFilter):
self.__modified = False
# Gamin monitor
self.monitor = gamin.WatchMonitor()
logSys.info("Created FilterGamin")
logSys.debug("Created FilterGamin")
def callback(self, path, event):
@ -69,7 +69,7 @@ class FilterGamin(FileFilter):
#
# @param path log file path
def addLogPath(self, path, tail = False):
def addLogPath(self, path, tail = True):
if self.containsLogPath(path):
logSys.error(path + " already exists")
else:

4
server/filterpoll.py

@ -54,14 +54,14 @@ class FilterPoll(FileFilter):
## The time of the last modification of the file.
self.__lastModTime = dict()
self.__file404Cnt = dict()
logSys.info("Created FilterPoll")
logSys.debug("Created FilterPoll")
##
# Add a log file path
#
# @param path log file path
def addLogPath(self, path, tail = False):
def addLogPath(self, path, tail = True):
if self.containsLogPath(path):
logSys.error(path + " already exists")
else:

7
server/jail.py

@ -37,6 +37,7 @@ class Jail:
self.__name = name
self.__queue = Queue.Queue()
self.__filter = None
logSys.info("Creating new jail '%s'" % self.__name)
if backend == "polling":
self.__initPoller()
else:
@ -47,14 +48,14 @@ class Jail:
self.__action = Actions(self)
def __initPoller(self):
logSys.info("Using poller")
logSys.info("Jail '%s' uses poller" % self.__name)
from filterpoll import FilterPoll
self.__filter = FilterPoll(self)
def __initGamin(self):
# Try to import gamin
import gamin
logSys.info("Using Gamin")
logSys.info("Jail '%s' uses Gamin" % self.__name)
from filtergamin import FilterGamin
self.__filter = FilterGamin(self)
@ -82,12 +83,14 @@ class Jail:
def start(self):
self.__filter.start()
self.__action.start()
logSys.info("Jail '%s' started" % self.__name)
def stop(self):
self.__filter.stop()
self.__action.stop()
self.__filter.join()
self.__action.join()
logSys.info("Jail '%s' stopped" % self.__name)
def isAlive(self):
isAlive0 = self.__filter.isAlive()

20
server/server.py

@ -46,11 +46,11 @@ class Server:
self.__daemon = daemon
self.__transm = Transmitter(self)
self.__asyncServer = AsyncServer(self.__transm)
self.__logLevel = 3
self.__logTarget = "STDOUT"
self.__logLevel = None
self.__logTarget = None
# Set logging level
self.setLogLevel(self.__logLevel)
self.setLogTarget(self.__logTarget)
self.setLogLevel(3)
self.setLogTarget("STDOUT")
def __sigTERMhandler(self, signum, frame):
logSys.debug("Caught signal %d. Exiting" % signum)
@ -66,6 +66,7 @@ class Server:
# First set the mask to only allow access to owner
os.umask(0077)
if self.__daemon:
logSys.info("Starting in daemon mode")
ret = self.__createDaemon()
if ret:
logSys.info("Daemon started")
@ -264,7 +265,7 @@ class Server:
length = len(jailList)
if not length == 0:
jailList = jailList[:length-2]
ret = [("Number of jail", self.__jails.size()),
ret = [("Number of jail", self.__jails.size()),
("Jail list", jailList)]
return ret
finally:
@ -331,7 +332,7 @@ class Server:
# Syslog daemons already add date to the message.
formatter = logging.Formatter("%(name)-16s: %(levelname)-6s %(message)s")
facility = logging.handlers.SysLogHandler.LOG_DAEMON
hdlr = logging.handlers.SysLogHandler("/dev/log",
hdlr = logging.handlers.SysLogHandler("/dev/log",
facility = facility)
elif target == "STDOUT":
hdlr = logging.StreamHandler(sys.stdout)
@ -346,7 +347,6 @@ class Server:
logSys.error("Unable to log to " + target)
logSys.info("Logging to previous target " + self.__logTarget)
return False
self.__logTarget = target
# Removes previous handlers
for handler in logging.getLogger("fail2ban").handlers:
# Closes the handler.
@ -355,6 +355,12 @@ class Server:
# tell the handler to use this format
hdlr.setFormatter(formatter)
logging.getLogger("fail2ban").addHandler(hdlr)
# Does not display this message at startup.
if not self.__logTarget == None:
logSys.info("Changed logging target to %s for Fail2ban v%s" %
(target, version.version))
# Sets the logging target.
self.__logTarget = target
return True
finally:
self.__loggingLock.release()

Loading…
Cancel
Save