mirror of https://github.com/fail2ban/fail2ban
ENH: Tweak naming of getF2BLogger, and ensure consistent use
parent
f7da091437
commit
4fc7f1a831
|
@ -30,9 +30,10 @@ from fail2ban.protocol import printFormatted
|
||||||
from fail2ban.client.csocket import CSocket
|
from fail2ban.client.csocket import CSocket
|
||||||
from fail2ban.client.configurator import Configurator
|
from fail2ban.client.configurator import Configurator
|
||||||
from fail2ban.client.beautifier import Beautifier
|
from fail2ban.client.beautifier import Beautifier
|
||||||
|
from fail2ban.helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = logging.getLogger("fail2ban")
|
logSys = getLogger("fail2ban")
|
||||||
|
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
|
|
|
@ -45,9 +45,9 @@ from fail2ban.client.filterreader import FilterReader
|
||||||
from fail2ban.server.filter import Filter
|
from fail2ban.server.filter import Filter
|
||||||
from fail2ban.server.failregex import RegexException
|
from fail2ban.server.failregex import RegexException
|
||||||
|
|
||||||
from fail2ban.helpers import FormatterWithTraceBack
|
from fail2ban.helpers import FormatterWithTraceBack, getLogger
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = logging.getLogger("fail2ban")
|
logSys = getLogger("fail2ban")
|
||||||
|
|
||||||
def debuggexURL(sample, regex):
|
def debuggexURL(sample, regex):
|
||||||
q = urllib.urlencode({ 're': regex.replace('<HOST>', '(?&.ipv4)'),
|
q = urllib.urlencode({ 're': regex.replace('<HOST>', '(?&.ipv4)'),
|
||||||
|
|
|
@ -22,13 +22,14 @@ __author__ = "Cyril Jaquier"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
import getopt, sys, logging, os
|
import getopt, sys, os
|
||||||
|
|
||||||
from fail2ban.version import version
|
from fail2ban.version import version
|
||||||
from fail2ban.server.server import Server
|
from fail2ban.server.server import Server
|
||||||
|
from fail2ban.helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = logging.getLogger("fail2ban")
|
logSys = getLogger("fail2ban")
|
||||||
|
|
||||||
##
|
##
|
||||||
# \mainpage Fail2Ban
|
# \mainpage Fail2Ban
|
||||||
|
|
|
@ -25,7 +25,7 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2012- Yaroslav Halchenko"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
|
||||||
import unittest, logging, sys, time, os
|
import unittest, sys, time, os
|
||||||
|
|
||||||
# Check if local fail2ban module exists, and use if it exists by
|
# Check if local fail2ban module exists, and use if it exists by
|
||||||
# modifying the path. This is such that tests can be used in dev
|
# modifying the path. This is such that tests can be used in dev
|
||||||
|
@ -35,7 +35,7 @@ if os.path.exists("fail2ban/__init__.py"):
|
||||||
from fail2ban.version import version
|
from fail2ban.version import version
|
||||||
|
|
||||||
from fail2ban.tests.utils import gatherTests
|
from fail2ban.tests.utils import gatherTests
|
||||||
from fail2ban.helpers import FormatterWithTraceBack
|
from fail2ban.helpers import FormatterWithTraceBack, getLogger
|
||||||
from fail2ban.server.mytime import MyTime
|
from fail2ban.server.mytime import MyTime
|
||||||
|
|
||||||
from optparse import OptionParser, Option
|
from optparse import OptionParser, Option
|
||||||
|
@ -70,7 +70,7 @@ parser = get_opt_parser()
|
||||||
#
|
#
|
||||||
# Logging
|
# Logging
|
||||||
#
|
#
|
||||||
logSys = logging.getLogger("fail2ban")
|
logSys = getLogger("fail2ban")
|
||||||
|
|
||||||
# Numerical level of verbosity corresponding to a log "level"
|
# Numerical level of verbosity corresponding to a log "level"
|
||||||
verbosity = {'heavydebug': 4,
|
verbosity = {'heavydebug': 4,
|
||||||
|
|
|
@ -27,10 +27,10 @@ __license__ = "GPL"
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .configreader import ConfigReader, DefinitionInitConfigReader
|
from .configreader import ConfigReader, DefinitionInitConfigReader
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class ActionReader(DefinitionInitConfigReader):
|
class ActionReader(DefinitionInitConfigReader):
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,10 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2013- Yaroslav Halchenko"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
from ..exceptions import UnknownJailException, DuplicateJailException
|
from ..exceptions import UnknownJailException, DuplicateJailException
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Beautify the output of the client.
|
# Beautify the output of the client.
|
||||||
|
|
|
@ -25,7 +25,7 @@ __copyright__ = 'Copyright (c) 2007 Yaroslav Halchenko'
|
||||||
__license__ = 'GPL'
|
__license__ = 'GPL'
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
if sys.version_info >= (3,2): # pragma: no cover
|
if sys.version_info >= (3,2): # pragma: no cover
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ else: # pragma: no cover
|
||||||
from ConfigParser import SafeConfigParser
|
from ConfigParser import SafeConfigParser
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
__all__ = ['SafeConfigParserWithIncludes']
|
__all__ = ['SafeConfigParserWithIncludes']
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,10 @@ import glob, os
|
||||||
from ConfigParser import NoOptionError, NoSectionError
|
from ConfigParser import NoOptionError, NoSectionError
|
||||||
|
|
||||||
from .configparserinc import SafeConfigParserWithIncludes
|
from .configparserinc import SafeConfigParserWithIncludes
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class ConfigReader(SafeConfigParserWithIncludes):
|
class ConfigReader(SafeConfigParserWithIncludes):
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@ __license__ = "GPL"
|
||||||
|
|
||||||
from .fail2banreader import Fail2banReader
|
from .fail2banreader import Fail2banReader
|
||||||
from .jailsreader import JailsReader
|
from .jailsreader import JailsReader
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class Configurator:
|
class Configurator:
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
from .configreader import ConfigReader
|
from .configreader import ConfigReader
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class Fail2banReader(ConfigReader):
|
class Fail2banReader(ConfigReader):
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,10 @@ import os, shlex
|
||||||
|
|
||||||
from .configreader import ConfigReader, DefinitionInitConfigReader
|
from .configreader import ConfigReader, DefinitionInitConfigReader
|
||||||
from ..server.action import CommandAction
|
from ..server.action import CommandAction
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class FilterReader(DefinitionInitConfigReader):
|
class FilterReader(DefinitionInitConfigReader):
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,10 @@ import json
|
||||||
from .configreader import ConfigReader
|
from .configreader import ConfigReader
|
||||||
from .filterreader import FilterReader
|
from .filterreader import FilterReader
|
||||||
from .actionreader import ActionReader
|
from .actionreader import ActionReader
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class JailReader(ConfigReader):
|
class JailReader(ConfigReader):
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@ __license__ = "GPL"
|
||||||
|
|
||||||
from .configreader import ConfigReader
|
from .configreader import ConfigReader
|
||||||
from .jailreader import JailReader
|
from .jailreader import JailReader
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class JailsReader(ConfigReader):
|
class JailsReader(ConfigReader):
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ class FormatterWithTraceBack(logging.Formatter):
|
||||||
record.tbc = record.tb = self._tb()
|
record.tbc = record.tb = self._tb()
|
||||||
return logging.Formatter.format(self, record)
|
return logging.Formatter.format(self, record)
|
||||||
|
|
||||||
def getF2BLogger(name):
|
def getLogger(name):
|
||||||
"""Get logging.Logger instance with Fail2Ban logger name convention
|
"""Get logging.Logger instance with Fail2Ban logger name convention
|
||||||
"""
|
"""
|
||||||
return logging.getLogger("fail2ban.%s" % name.rpartition(".")[-1])
|
return logging.getLogger("fail2ban.%s" % name.rpartition(".")[-1])
|
||||||
|
@ -116,6 +116,6 @@ def getF2BLogger(name):
|
||||||
def fail2ban_excepthook(exctype, value, traceback):
|
def fail2ban_excepthook(exctype, value, traceback):
|
||||||
"""Except hook used to log unhandled exceptions to Fail2Ban log
|
"""Except hook used to log unhandled exceptions to Fail2Ban log
|
||||||
"""
|
"""
|
||||||
logging.getLogger("fail2ban").critical(
|
getLogger("fail2ban").critical(
|
||||||
"Unhandled exception in Fail2Ban:", exc_info=True)
|
"Unhandled exception in Fail2Ban:", exc_info=True)
|
||||||
return sys.__excepthook__(exctype, value, traceback)
|
return sys.__excepthook__(exctype, value, traceback)
|
||||||
|
|
|
@ -26,10 +26,10 @@ import threading, re
|
||||||
from abc import ABCMeta
|
from abc import ABCMeta
|
||||||
from collections import MutableMapping
|
from collections import MutableMapping
|
||||||
|
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
# Create a lock for running system commands
|
# Create a lock for running system commands
|
||||||
_cmd_lock = threading.Lock()
|
_cmd_lock = threading.Lock()
|
||||||
|
@ -136,8 +136,7 @@ class ActionBase(object):
|
||||||
def __init__(self, jail, name):
|
def __init__(self, jail, name):
|
||||||
self._jail = jail
|
self._jail = jail
|
||||||
self._name = name
|
self._name = name
|
||||||
self._logSys = logging.getLogger(
|
self._logSys = getLogger("fail2ban.%s" % self.__class__.__name__)
|
||||||
"fail2ban.%s" % self.__class__.__name__)
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Executed when the jail/action is started.
|
"""Executed when the jail/action is started.
|
||||||
|
|
|
@ -41,10 +41,10 @@ from .banmanager import BanManager
|
||||||
from .jailthread import JailThread
|
from .jailthread import JailThread
|
||||||
from .action import ActionBase, CommandAction, CallingMap
|
from .action import ActionBase, CommandAction, CallingMap
|
||||||
from .mytime import MyTime
|
from .mytime import MyTime
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class Actions(JailThread, Mapping):
|
class Actions(JailThread, Mapping):
|
||||||
"""Handles jail actions.
|
"""Handles jail actions.
|
||||||
|
|
|
@ -27,10 +27,10 @@ __license__ = "GPL"
|
||||||
from pickle import dumps, loads, HIGHEST_PROTOCOL
|
from pickle import dumps, loads, HIGHEST_PROTOCOL
|
||||||
import asyncore, asynchat, socket, os, sys, traceback, fcntl
|
import asyncore, asynchat, socket, os, sys, traceback, fcntl
|
||||||
|
|
||||||
from ..helpers import getF2BLogger,formatExceptionInfo
|
from ..helpers import getLogger,formatExceptionInfo
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
if sys.version_info >= (3,):
|
if sys.version_info >= (3,):
|
||||||
# b"" causes SyntaxError in python <= 2.5, so below implements equivalent
|
# b"" causes SyntaxError in python <= 2.5, so below implements equivalent
|
||||||
|
|
|
@ -28,10 +28,10 @@ from threading import Lock
|
||||||
|
|
||||||
from .ticket import BanTicket
|
from .ticket import BanTicket
|
||||||
from .mytime import MyTime
|
from .mytime import MyTime
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Banning Manager.
|
# Banning Manager.
|
||||||
|
|
|
@ -31,10 +31,10 @@ from threading import Lock
|
||||||
|
|
||||||
from .mytime import MyTime
|
from .mytime import MyTime
|
||||||
from .ticket import FailTicket
|
from .ticket import FailTicket
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
if sys.version_info >= (3,):
|
if sys.version_info >= (3,):
|
||||||
sqlite3.register_adapter(
|
sqlite3.register_adapter(
|
||||||
|
|
|
@ -24,10 +24,10 @@ __license__ = "GPL"
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
|
|
||||||
from .datetemplate import DatePatternRegex, DateTai64n, DateEpoch
|
from .datetemplate import DatePatternRegex, DateTai64n, DateEpoch
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class DateDetector(object):
|
class DateDetector(object):
|
||||||
"""Manages one or more date templates to find a date within a log line.
|
"""Manages one or more date templates to find a date within a log line.
|
||||||
|
|
|
@ -28,9 +28,9 @@ import re
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from .strptime import reGroupDictStrptime, timeRE
|
from .strptime import reGroupDictStrptime, timeRE
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DateTemplate(object):
|
class DateTemplate(object):
|
||||||
|
|
|
@ -24,10 +24,10 @@ __author__ = "Cyril Jaquier"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class FailData:
|
class FailData:
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ import logging
|
||||||
|
|
||||||
from .faildata import FailData
|
from .faildata import FailData
|
||||||
from .ticket import FailTicket
|
from .ticket import FailTicket
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class FailManager:
|
class FailManager:
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,10 @@ from .datetemplate import DatePatternRegex, DateEpoch, DateTai64n
|
||||||
from .mytime import MyTime
|
from .mytime import MyTime
|
||||||
from .failregex import FailRegex, Regex, RegexException
|
from .failregex import FailRegex, Regex, RegexException
|
||||||
from .action import CommandAction
|
from .action import CommandAction
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Log reader class.
|
# Log reader class.
|
||||||
|
|
|
@ -30,10 +30,10 @@ import gamin
|
||||||
from .failmanager import FailManagerEmpty
|
from .failmanager import FailManagerEmpty
|
||||||
from .filter import FileFilter
|
from .filter import FileFilter
|
||||||
from .mytime import MyTime
|
from .mytime import MyTime
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Log reader class.
|
# Log reader class.
|
||||||
|
|
|
@ -29,10 +29,10 @@ import time, os
|
||||||
from .failmanager import FailManagerEmpty
|
from .failmanager import FailManagerEmpty
|
||||||
from .filter import FileFilter
|
from .filter import FileFilter
|
||||||
from .mytime import MyTime
|
from .mytime import MyTime
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Log reader class.
|
# Log reader class.
|
||||||
|
|
|
@ -32,7 +32,7 @@ import pyinotify
|
||||||
from .failmanager import FailManagerEmpty
|
from .failmanager import FailManagerEmpty
|
||||||
from .filter import FileFilter
|
from .filter import FileFilter
|
||||||
from .mytime import MyTime
|
from .mytime import MyTime
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
|
|
||||||
if not hasattr(pyinotify, '__version__') \
|
if not hasattr(pyinotify, '__version__') \
|
||||||
|
@ -49,7 +49,7 @@ except Exception, e:
|
||||||
% str(e))
|
% str(e))
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Log reader class.
|
# Log reader class.
|
||||||
|
|
|
@ -32,10 +32,10 @@ if LooseVersion(getattr(journal, '__version__', "0")) < '204':
|
||||||
from .failmanager import FailManagerEmpty
|
from .failmanager import FailManagerEmpty
|
||||||
from .filter import JournalFilter
|
from .filter import JournalFilter
|
||||||
from .mytime import MyTime
|
from .mytime import MyTime
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Journal reader class.
|
# Journal reader class.
|
||||||
|
|
|
@ -26,10 +26,10 @@ __license__ = "GPL"
|
||||||
import Queue, logging
|
import Queue, logging
|
||||||
|
|
||||||
from .actions import Actions
|
from .actions import Actions
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class Jail:
|
class Jail:
|
||||||
"""Fail2Ban jail, which manages a filter and associated actions.
|
"""Fail2Ban jail, which manages a filter and associated actions.
|
||||||
|
|
|
@ -32,10 +32,10 @@ from .filter import FileFilter, JournalFilter
|
||||||
from .transmitter import Transmitter
|
from .transmitter import Transmitter
|
||||||
from .asyncserver import AsyncServer, AsyncServerException
|
from .asyncserver import AsyncServer, AsyncServerException
|
||||||
from .. import version
|
from .. import version
|
||||||
from ..helpers import getF2BLogger, fail2ban_excepthook
|
from ..helpers import getLogger, fail2ban_excepthook
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .database import Fail2BanDb
|
from .database import Fail2BanDb
|
||||||
|
@ -339,7 +339,7 @@ class Server:
|
||||||
def setLogLevel(self, value):
|
def setLogLevel(self, value):
|
||||||
try:
|
try:
|
||||||
self.__loggingLock.acquire()
|
self.__loggingLock.acquire()
|
||||||
logging.getLogger("fail2ban").setLevel(
|
getLogger("fail2ban").setLevel(
|
||||||
getattr(logging, value.upper()))
|
getattr(logging, value.upper()))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise ValueError("Invalid log level")
|
raise ValueError("Invalid log level")
|
||||||
|
@ -392,7 +392,7 @@ class Server:
|
||||||
return False
|
return False
|
||||||
# Removes previous handlers -- in reverse order since removeHandler
|
# Removes previous handlers -- in reverse order since removeHandler
|
||||||
# alter the list in-place and that can confuses the iterable
|
# alter the list in-place and that can confuses the iterable
|
||||||
logger = logging.getLogger("fail2ban")
|
logger = getLogger("fail2ban")
|
||||||
for handler in logger.handlers[::-1]:
|
for handler in logger.handlers[::-1]:
|
||||||
# Remove the handler.
|
# Remove the handler.
|
||||||
logger.removeHandler(handler)
|
logger.removeHandler(handler)
|
||||||
|
@ -429,7 +429,7 @@ class Server:
|
||||||
|
|
||||||
def flushLogs(self):
|
def flushLogs(self):
|
||||||
if self.__logTarget not in ['STDERR', 'STDOUT', 'SYSLOG']:
|
if self.__logTarget not in ['STDERR', 'STDOUT', 'SYSLOG']:
|
||||||
for handler in logging.getLogger("fail2ban").handlers:
|
for handler in getLogger("fail2ban").handlers:
|
||||||
try:
|
try:
|
||||||
handler.doRollover()
|
handler.doRollover()
|
||||||
logSys.info("rollover performed on %s" % self.__logTarget)
|
logSys.info("rollover performed on %s" % self.__logTarget)
|
||||||
|
@ -438,7 +438,7 @@ class Server:
|
||||||
logSys.info("flush performed on %s" % self.__logTarget)
|
logSys.info("flush performed on %s" % self.__logTarget)
|
||||||
return "rolled over"
|
return "rolled over"
|
||||||
else:
|
else:
|
||||||
for handler in logging.getLogger("fail2ban").handlers:
|
for handler in getLogger("fail2ban").handlers:
|
||||||
handler.flush()
|
handler.flush()
|
||||||
logSys.info("flush performed on %s" % self.__logTarget)
|
logSys.info("flush performed on %s" % self.__logTarget)
|
||||||
return "flushed"
|
return "flushed"
|
||||||
|
|
|
@ -24,10 +24,10 @@ __author__ = "Cyril Jaquier"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class Ticket:
|
class Ticket:
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,10 @@ __license__ = "GPL"
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
class Transmitter:
|
class Transmitter:
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ import datetime
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
from ..helpers import formatExceptionInfo, mbasename, TraceBack, FormatterWithTraceBack
|
from ..helpers import formatExceptionInfo, mbasename, TraceBack, FormatterWithTraceBack, getLogger
|
||||||
from ..server.datetemplate import DatePatternRegex
|
from ..server.datetemplate import DatePatternRegex
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ class TestsUtilsTest(unittest.TestCase):
|
||||||
|
|
||||||
# and both types of traceback at once
|
# and both types of traceback at once
|
||||||
fmt = ' %(tb)s | %(tbc)s : %(message)s'
|
fmt = ' %(tb)s | %(tbc)s : %(message)s'
|
||||||
logSys = logging.getLogger("fail2ban_tests")
|
logSys = getLogger("fail2ban_tests")
|
||||||
out = logging.StreamHandler(strout)
|
out = logging.StreamHandler(strout)
|
||||||
out.setFormatter(Formatter(fmt))
|
out.setFormatter(Formatter(fmt))
|
||||||
logSys.addHandler(out)
|
logSys.addHandler(out)
|
||||||
|
|
|
@ -30,14 +30,13 @@ import tempfile
|
||||||
import os
|
import os
|
||||||
import locale
|
import locale
|
||||||
import sys
|
import sys
|
||||||
import logging
|
|
||||||
|
|
||||||
from ..server.failregex import Regex, FailRegex, RegexException
|
from ..server.failregex import Regex, FailRegex, RegexException
|
||||||
from ..server.server import Server
|
from ..server.server import Server
|
||||||
from ..server.jail import Jail
|
from ..server.jail import Jail
|
||||||
from ..server.jailthread import JailThread
|
from ..server.jailthread import JailThread
|
||||||
from .utils import LogCaptureTestCase
|
from .utils import LogCaptureTestCase
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ..server import filtersystemd
|
from ..server import filtersystemd
|
||||||
|
@ -725,7 +724,7 @@ class TransmitterLogging(TransmitterBase):
|
||||||
os.close(f)
|
os.close(f)
|
||||||
self.server.setLogLevel("WARNING")
|
self.server.setLogLevel("WARNING")
|
||||||
self.assertEqual(self.transm.proceed(["set", "logtarget", fn]), (0, fn))
|
self.assertEqual(self.transm.proceed(["set", "logtarget", fn]), (0, fn))
|
||||||
l = logging.getLogger('fail2ban')
|
l = getLogger('fail2ban')
|
||||||
l.warning("Before file moved")
|
l.warning("Before file moved")
|
||||||
try:
|
try:
|
||||||
f2, fn2 = tempfile.mkstemp("fail2ban.log")
|
f2, fn2 = tempfile.mkstemp("fail2ban.log")
|
||||||
|
@ -806,7 +805,7 @@ class _BadThread(JailThread):
|
||||||
class LoggingTests(LogCaptureTestCase):
|
class LoggingTests(LogCaptureTestCase):
|
||||||
|
|
||||||
def testGetF2BLogger(self):
|
def testGetF2BLogger(self):
|
||||||
testLogSys = getF2BLogger("fail2ban.some.string.with.name")
|
testLogSys = getLogger("fail2ban.some.string.with.name")
|
||||||
self.assertEqual(testLogSys.parent.name, "fail2ban")
|
self.assertEqual(testLogSys.parent.name, "fail2ban")
|
||||||
self.assertEqual(testLogSys.name, "fail2ban.name")
|
self.assertEqual(testLogSys.name, "fail2ban.name")
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,9 @@ import unittest
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
from ..server.mytime import MyTime
|
from ..server.mytime import MyTime
|
||||||
from ..helpers import getF2BLogger
|
from ..helpers import getLogger
|
||||||
|
|
||||||
logSys = getF2BLogger(__name__)
|
logSys = getLogger(__name__)
|
||||||
|
|
||||||
def mtimesleep():
|
def mtimesleep():
|
||||||
# no sleep now should be necessary since polling tracks now not only
|
# no sleep now should be necessary since polling tracks now not only
|
||||||
|
@ -187,7 +187,7 @@ class LogCaptureTestCase(unittest.TestCase):
|
||||||
|
|
||||||
# For extended testing of what gets output into logging
|
# For extended testing of what gets output into logging
|
||||||
# system, we will redirect it to a string
|
# system, we will redirect it to a string
|
||||||
logSys = logging.getLogger("fail2ban")
|
logSys = getLogger("fail2ban")
|
||||||
|
|
||||||
# Keep old settings
|
# Keep old settings
|
||||||
self._old_level = logSys.level
|
self._old_level = logSys.level
|
||||||
|
@ -200,7 +200,7 @@ class LogCaptureTestCase(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
"""Call after every test case."""
|
"""Call after every test case."""
|
||||||
# print "O: >>%s<<" % self._log.getvalue()
|
# print "O: >>%s<<" % self._log.getvalue()
|
||||||
logSys = logging.getLogger("fail2ban")
|
logSys = getLogger("fail2ban")
|
||||||
logSys.handlers = self._old_handlers
|
logSys.handlers = self._old_handlers
|
||||||
logSys.level = self._old_level
|
logSys.level = self._old_level
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue