Skip to content

Instantly share code, notes, and snippets.

@mtask
Created February 27, 2021 18:38
Show Gist options
  • Save mtask/27613ca6069eccf1e8d88cc3a583ca01 to your computer and use it in GitHub Desktop.
Save mtask/27613ca6069eccf1e8d88cc3a583ca01 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import re
import json
fw_lines = []
def make_dict(str_value):
d = {}
for item in str_value.split():
if re.match(r'.*=.*', item):
d[item.split("=")[0]] = item.split("=")[1]
return d
with open("/var/log/syslog") as syslog:
for line in syslog.readlines():
if re.match(r'.*IN=.*OUT.*MAC=.*SRC=.*', line):
fw_lines.append(make_dict(("IN={}".format(line.split('IN=')[1]))))
print(json.dumps(fw_lines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment