This commit is contained in:
Dmitry Belyaev 2025-03-13 12:07:25 +03:00
parent f59b7ab639
commit 5ff690d4d6
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

@ -30,10 +30,8 @@ def log_lines(filepath: pathlib.Path):
yield line
def filter_log_lines_for_date(filepath: pathlib.Path, date: str):
return filter(
lambda line: datepattern.match(line).group("date") == date, log_lines(filepath)
)
def filter_log_lines_for_date(lines, date: str):
return filter(lambda line: line.startswith(date + " "), lines)
def parse_date_time(date: str, time: str) -> datetime.datetime:
@ -110,7 +108,7 @@ def print_fast_repeats(connmap: ConnectionMap, limit_for_one=10):
for name, infos in connmap.items():
print(f"- {name}:")
for n, info in enumerate(
reversed(sorted(infos, key=lambda info: info.datetime)), 1
sorted(infos, key=lambda info: info.datetime, reverse=True), 1
):
print(f" {n:2}. {info.ip}: {info.datetime}")
if n >= limit_for_one:
@ -125,7 +123,7 @@ def main():
date = datetime.date.today().strftime("%Y-%m-%d")
log_file = pathlib.Path(sys.argv[1])
lines = log_lines(log_file)
lines = filter_log_lines_for_date(pathlib.Path(log_file), date)
lines = filter_log_lines_for_date(lines, date)
connmap = get_conn_map(lines)
multiple_ips = find_names_with_multiple_ips(connmap)
fast_repeats = find_fast_repeats(connmap, datetime.timedelta(minutes=3), 10)