(feature): Add basic streamalerts.
This commit is contained in:
@@ -845,3 +845,35 @@ def write_records(records: list[dict[str, Any]], stream: StringIO):
|
||||
for record in records:
|
||||
stream.write(','.join(map(str, record.values())))
|
||||
stream.write('\n')
|
||||
|
||||
|
||||
parse_dur_exps = [
|
||||
(
|
||||
r"(?P<value>\d+)\s*(?:(d)|(day))",
|
||||
60 * 60 * 24,
|
||||
),
|
||||
(
|
||||
r"(?P<value>\d+)\s*(?:(h)|(hour))",
|
||||
60 * 60
|
||||
),
|
||||
(
|
||||
r"(?P<value>\d+)\s*(?:(m)|(min))",
|
||||
60
|
||||
),
|
||||
(
|
||||
r"(?P<value>\d+)\s*(?:(s)|(sec))",
|
||||
1
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def parse_duration(string: str) -> Optional[int]:
|
||||
seconds = 0
|
||||
found = False
|
||||
for expr, multiplier in parse_dur_exps:
|
||||
match = re.search(expr, string, flags=re.IGNORECASE)
|
||||
if match:
|
||||
found = True
|
||||
seconds += int(match.group('value')) * multiplier
|
||||
|
||||
return seconds if found else None
|
||||
|
||||
Reference in New Issue
Block a user