fail2ban.server.datedetector module

class fail2ban.server.datedetector.DateDetector

Bases: object

Manages one or more date templates to find a date within a log line.

Attributes

templates List of template instances managed by the detector.

Methods

addDefaultTemplate() Add Fail2Ban’s default set of date templates.
appendTemplate(template) Add a date template to manage and use in search of dates.
getTime(line) Attempts to return the date on a log line using templates.
matchTime(line) Attempts to find date on a log line using templates.
sortTemplate() Sort the date templates by number of hits
addDefaultTemplate()

Add Fail2Ban’s default set of date templates.

appendTemplate(template)

Add a date template to manage and use in search of dates.

Parameters:

template : DateTemplate or str

Can be either a DateTemplate instance, or a string which will be used as the pattern for the DatePatternRegex template. The template will then be added to the detector.

Raises:

ValueError

If a template already exists with the same name.

getTime(line)

Attempts to return the date on a log line using templates.

This uses the templates’ getDate method in an attempt to find a date.

Parameters:

line : str

Line which is searched by the date templates.

Returns:

float

The Unix timestamp returned from the first successfully matched template.

matchTime(line)

Attempts to find date on a log line using templates.

This uses the templates’ matchDate method in an attempt to find a date. It also increments the match hit count for the winning template.

Parameters:

line : str

Line which is searched by the date templates.

Returns:

re.MatchObject

The regex match returned from the first successfully matched template.

sortTemplate()

Sort the date templates by number of hits

Sort the template lists using the hits score. This method is not called in this object and thus should be called from time to time. This ensures the most commonly matched templates are checked first, improving performance of matchTime and getTime.

templates

List of template instances managed by the detector.