J. *_*hin 10 logrotate fail2ban
fail2ban 是否继续监视轮换的日志文件?
例如,我有一个规则监控/var/log/fail2ban.log,它每周(7 天)由系统自动轮换。我想要一个规则来监控该日志中被禁止的 IP,以查找在过去 10 天内被禁止 5 次的重复违规者。那可能吗?
可以通过两种方式之一(或组合)指定多个日志。您可以使用文件通配符(通配符)来匹配要监控的日志文件(即logpath = /var/log/*somefile.log
)或要监控的日志文件列表,以空格(空格、制表符、换行符)分隔,例如
logpath = /var/log/auth.log /var/log/auth.log.1
Run Code Online (Sandbox Code Playgroud)
或者
logpath = /var/log/auth.log
/var/log/auth.log.1
Run Code Online (Sandbox Code Playgroud)
对于您的问题,上述接受的答案是不正确的。FileContainer 仅使用文件日志旋转检测将日志读取重置回文件的开头,而不是从最后一个偏移量继续的标准过程:
class FileContainer:
...
def open(self):
self.__handler = open(self.__filename, 'rb')
...
# Compare hash and inode
if self.__hash != myHash or self.__ino != stats.st_ino:
logSys.info("Log rotation detected for %s" % self.__filename)
self.__hash = myHash
self.__ino = stats.st_ino
self.__pos = 0
# Sets the file pointer to the last position.
self.__handler.seek(self.__pos)
Run Code Online (Sandbox Code Playgroud)
那里没有代码去寻找旋转的文件来解析。
是的,fail2ban 继续监视轮换日志文件。从server/filter.py
439 ##
440 # FileContainer class.
441 #
442 # This class manages a file handler and takes care of log rotation detection.
443 # In order to detect log rotation, the hash (MD5) of the first line of the file
444 # is computed and compared to the previous hash of this line.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4469 次 |
最近记录: |