Page MenuHomePhabricator

parse_fsck.py

Authored By
dcaro
Sep 21 2021, 9:21 AM
Size
1 KB
Subscribers
None

parse_fsck.py

#!/usr/bin/env python3
from pprint import pprint
import click
from datetime import date, datetime
@click.command()
@click.argument('infile', type=click.File('r'))
def main(infile):
minute_to_hosts = {}
host = None
for line in infile:
if line.startswith('('):
host = line.split(")", 1)[-1].strip()
continue
elif line.startswith('[') and host is not None:
datestamp_str = line.split(']', 1)[0][1:]
datestamp = datetime.strptime(datestamp_str, "%c")
minute_bucket = datetime(
year = datestamp.year,
month=datestamp.month,
day=datestamp.day,
hour=datestamp.hour,
minute=datestamp.minute,
)
if minute_bucket in minute_to_hosts:
minute_to_hosts[minute_bucket].append(host)
else:
minute_to_hosts[minute_bucket] = [host]
for minute, hosts in sorted(minute_to_hosts.items()):
print("{minute} - count: {len_hosts}\n hosts:".format(minute=minute, len_hosts=len(hosts)))
print(" " + "\n ".join(hosts))
if __name__ == "__main__":
main()

File Metadata

Mime Type
text/x-python
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9185900
Default Alt Text
parse_fsck.py (1 KB)

Event Timeline