태그 보관물: logrotate

logrotate

fail2ban은 회전 된 로그 파일을 모니터합니까? 규칙이 있습니다. 지난 10 일

fail2ban이 회전 된 로그 파일을 계속 모니터링합니까?

예를 들어 매주 (7 일)마다 시스템에서 자동으로 회전하는 /var/log/fail2ban.log를 모니터링하는 규칙이 있습니다. 지난 10 일 동안 5 번 금지 된 반복 위반자를 찾기 위해 해당 로그에서 금지 된 IP를 모니터링하는 규칙을 원합니다. 가능합니까?



답변

예, 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.


답변

두 가지 방법 중 하나 (또는 ​​조합)로 여러 개의 로그를 지정할 수 있습니다. 파일 글롭 (와일드 카드)을 사용하여 모니터 할 로그 파일 (예 logpath = /var/log/*somefile.log🙂 또는 모니터 할 로그 파일 목록을 공백 (공백, 탭, 줄 바꾸기)으로 구분 하여 일치시킬 수 있습니다.

    logpath = /var/log/auth.log /var/log/auth.log.1

또는

    logpath = /var/log/auth.log
              /var/log/auth.log.1


답변

귀하의 질문과 관련하여 위의 답변이 잘못되었습니다. 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)

거기에는 구문 분석 할 회전 파일을 찾는 코드가 없습니다.


답변