Created
July 10, 2024 19:18
-
-
Save sulrich/20b33bcb688d2858b5a241dd2d13edf2 to your computer and use it in GitHub Desktop.
script to parse GoBMP dump outputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import base64 | |
import argparse | |
import pprint as pprint | |
import sys | |
def parse_logentry(entry): | |
parsed_entry = {} | |
for k, v in entry.items(): | |
val = "" | |
if k == "key": | |
# keys are just the router_hash base64 encoded | |
val = base64.b64decode(v).decode("utf-8") | |
elif k == "value": | |
# values are json dicts that have been base64 encoded and need to | |
# be unfurled into json objects. | |
val = json.loads(base64.b64decode(v).decode("utf-8")) | |
else: | |
val = v | |
parsed_entry[k] = val | |
return parsed_entry | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
dest="bmplog", | |
help="GoBMP log file to parse", | |
) | |
args = parser.parse_args() | |
try: | |
with open(args.bmplog) as f: | |
for i in f.readlines(): | |
d = json.loads(i) | |
logentry = parse_logentry(d) | |
pprint.pprint(logentry) | |
except IOError: | |
print("error opening log file:", args.bmplog) | |
sys.exit() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment