support for 1 attemt
@@ -12,7 +12,7 @@ from moler.events.lineevent import LineEvent
class FailedLoginCounter(LineEvent):
# There were 2 failed login attempts since the last successful login
_re_attempts = re.compile(
- r'There were (?P<ATTEMPTS_NR>\d+) failed login attempts since the last successful login', re.I)
+ r'There (?:were|was) (?P<ATTEMPTS_NR>\d+) failed login attempts? since the last successful login', re.I)
def __init__(self, connection, till_occurs_times=-1, runner=None):
"""
@@ -25,7 +25,9 @@ class FailedLoginCounter(LineEvent):
super(FailedLoginCounter, self).__init__(connection=connection,
runner=runner,
till_occurs_times=till_occurs_times,
- detect_patterns=[FailedLoginCounter._re_attempts])
+ detect_patterns=[FailedLoginCounter._re_attempts, ],
+ match='any')
+
self.process_full_lines_only = True
@@ -39,10 +41,24 @@ EVENT_KWARGS = {
EVENT_RESULT = [
{'groups': (2,),
- 'line': 'There were 2 failed login attempts since the last successful '
- 'login.',
- 'matched': 'There were 2 failed login attempts since the last '
- 'successful login',
+ 'line': 'There were 2 failed login attempts since the last successful login.',
+ 'matched': 'There were 2 failed login attempts since the last successful login',
'named_groups': {'ATTEMPTS_NR': 2},
'time': datetime.datetime(2019, 5, 17, 12, 42, 38, 278418)}
]
+
+EVENT_OUTPUT_one = """
+There was 1 failed login attempts since the last successful login.
+"""
+
+EVENT_KWARGS_one = {
+ "till_occurs_times": 1
+}
+
+EVENT_RESULT_one = [
+ {'groups': (1,),
+ 'line': 'There was 1 failed login attempts since the last successful login.',
+ 'matched': 'There was 1 failed login attempts since the last successful login',
+ 'named_groups': {'ATTEMPTS_NR': 1},
+ 'time': datetime.datetime(2019, 5, 17, 12, 42, 38, 278418)}
+]
