Created
February 27, 2021 18:38
-
-
Save mtask/27613ca6069eccf1e8d88cc3a583ca01 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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