(feature): Add basic streamalerts.

This commit is contained in:
2024-08-02 20:45:18 +10:00
parent 850c5d7abb
commit c3c8baa4b2
25 changed files with 5471 additions and 0 deletions

View File

@@ -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