fail2ban.server.datetemplate module¶
- class fail2ban.server.datetemplate.DateEpoch¶
Bases: fail2ban.server.datetemplate.DateTemplate
A date template which searches for Unix timestamps.
This includes Unix timestamps which appear at start of a line, optionally within square braces (nsd), or on SELinux audit log lines.
Attributes
name Name assigned to template. regex Regex used to search for date. Methods
getDate(line) Method to return the date for a log line. getRegex() matchDate(line) Check if regex for date matches on a log line. setRegex(regex[, wordBegin]) Sets regex to use for searching for date in log line. - getDate(line)¶
Method to return the date for a log line.
Parameters: line : str
Log line, of which the date should be extracted from.
Returns: (float, str)
Tuple containing a Unix timestamp, and the string of the date which was matched and in turned used to calculated the timestamp.
- getRegex()¶
- matchDate(line)¶
Check if regex for date matches on a log line.
- name¶
Name assigned to template.
- regex¶
Regex used to search for date.
- setRegex(regex, wordBegin=True)¶
Sets regex to use for searching for date in log line.
Parameters: regex : str
The regex the template will use for searching for a date.
wordBegin : bool
Defines whether the regex should be modified to search at beginning of a word, by adding “b” to start of regex. Default True.
Raises: re.error
If regular expression fails to compile
- class fail2ban.server.datetemplate.DatePatternRegex(pattern=None)¶
Bases: fail2ban.server.datetemplate.DateTemplate
Date template, with regex/pattern
Parameters: pattern : str
Sets the date templates pattern.
Attributes
name Name assigned to template. regex Regex used to search for date. pattern The pattern used for regex with strptime “%” time fields. Methods
getDate(line) Method to return the date for a log line. getRegex() matchDate(line) Check if regex for date matches on a log line. setRegex(value) - getDate(line)¶
Method to return the date for a log line.
This uses a custom version of strptime, using the named groups from the instances pattern property.
Parameters: line : str
Log line, of which the date should be extracted from.
Returns: (float, str)
Tuple containing a Unix timestamp, and the string of the date which was matched and in turned used to calculated the timestamp.
- getRegex()¶
- matchDate(line)¶
Check if regex for date matches on a log line.
- name¶
Name assigned to template.
- pattern¶
The pattern used for regex with strptime “%” time fields.
This should be a valid regular expression, of which matching string will be extracted from the log line. strptime style “%” fields will be replaced by appropriate regular expressions, or custom regex groups with names as per the strptime fields can also be used instead.
- regex¶
Regex used to search for date.
- setRegex(value)¶
- class fail2ban.server.datetemplate.DateTai64n¶
Bases: fail2ban.server.datetemplate.DateTemplate
A date template which matches TAI64N formate timestamps.
Attributes
name Name assigned to template. regex Regex used to search for date. Methods
getDate(line) Method to return the date for a log line. getRegex() matchDate(line) Check if regex for date matches on a log line. setRegex(regex[, wordBegin]) Sets regex to use for searching for date in log line. - getDate(line)¶
Method to return the date for a log line.
Parameters: line : str
Log line, of which the date should be extracted from.
Returns: (float, str)
Tuple containing a Unix timestamp, and the string of the date which was matched and in turned used to calculated the timestamp.
- getRegex()¶
- matchDate(line)¶
Check if regex for date matches on a log line.
- name¶
Name assigned to template.
- regex¶
Regex used to search for date.
- setRegex(regex, wordBegin=True)¶
Sets regex to use for searching for date in log line.
Parameters: regex : str
The regex the template will use for searching for a date.
wordBegin : bool
Defines whether the regex should be modified to search at beginning of a word, by adding “b” to start of regex. Default True.
Raises: re.error
If regular expression fails to compile
- class fail2ban.server.datetemplate.DateTemplate¶
Bases: object
A template which searches for and returns a date from a log line.
This is an not functional abstract class which other templates should inherit from.
Attributes
name Name assigned to template. regex Regex used to search for date. Methods
getDate(line) Abstract method, which should return the date for a log line getRegex() matchDate(line) Check if regex for date matches on a log line. setRegex(regex[, wordBegin]) Sets regex to use for searching for date in log line. - getDate(line)¶
Abstract method, which should return the date for a log line
This should return the date for a log line, typically taking the date from the part of the line which matched the templates regex. This requires abstraction, therefore just raises exception.
Parameters: line : str
Log line, of which the date should be extracted from.
Raises: NotImplementedError
Abstract method, therefore always returns this.
- getRegex()¶
- matchDate(line)¶
Check if regex for date matches on a log line.
- name¶
Name assigned to template.
- regex¶
Regex used to search for date.
- setRegex(regex, wordBegin=True)¶
Sets regex to use for searching for date in log line.
Parameters: regex : str
The regex the template will use for searching for a date.
wordBegin : bool
Defines whether the regex should be modified to search at beginning of a word, by adding “b” to start of regex. Default True.
Raises: re.error
If regular expression fails to compile