2023-05-26 21:57:53 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# ircp logs parser - developed by acidvegas in python (https://git.acid.vegas/ircp)
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2023-05-30 07:10:29 +00:00
|
|
|
def parse(option, data, raw=True):
|
2023-05-26 21:57:53 +00:00
|
|
|
if not raw:
|
2023-05-30 06:49:13 +00:00
|
|
|
data = ' '.join(line.split()[3:])
|
2023-05-26 21:57:53 +00:00
|
|
|
if data[:1] == ':':
|
|
|
|
data = data[1:]
|
2023-05-30 07:10:29 +00:00
|
|
|
print(data.replace(option, f'\033[31m{option}\033[0m'))
|
2023-05-30 06:49:13 +00:00
|
|
|
return data
|
2023-05-26 21:57:53 +00:00
|
|
|
|
|
|
|
# Main
|
|
|
|
if len(sys.argv) >= 2:
|
2023-05-30 06:49:13 +00:00
|
|
|
option = sys.argv[1]
|
2023-05-26 21:57:53 +00:00
|
|
|
raw = True
|
|
|
|
if len(sys.argv) == 3:
|
|
|
|
if sys.argv[2] == 'clean':
|
|
|
|
raw = False
|
|
|
|
logs = os.listdir('logs')
|
2023-05-28 03:25:51 +00:00
|
|
|
found = list()
|
2023-05-26 21:57:53 +00:00
|
|
|
for log in logs:
|
|
|
|
with open('logs/'+log) as logfile:
|
2023-05-30 07:10:29 +00:00
|
|
|
try:
|
|
|
|
data = json.loads(logfile.read())
|
|
|
|
except:
|
|
|
|
print('error: failed to load ' + log)
|
|
|
|
break
|
2023-05-30 06:49:13 +00:00
|
|
|
if option in data:
|
|
|
|
data = data[option]
|
2023-05-26 21:57:53 +00:00
|
|
|
if type(data) == str:
|
2023-05-30 07:30:58 +00:00
|
|
|
found.append(parse(option, data, raw))
|
2023-05-26 21:57:53 +00:00
|
|
|
elif type(data) == list:
|
|
|
|
for item in data:
|
2023-05-30 07:30:58 +00:00
|
|
|
found.append(option, parse(item, raw))
|
|
|
|
elif type(data) == bool:
|
|
|
|
found.append(parse(option, str(item), raw))
|
2023-05-30 07:10:29 +00:00
|
|
|
else:
|
|
|
|
for item in data:
|
|
|
|
_data = data[item]
|
|
|
|
if type(_data) == str and option in _data:
|
|
|
|
found.append(parse(option, item, raw))
|
|
|
|
elif type(_data) == list:
|
|
|
|
for _item in _data:
|
|
|
|
if option in _item:
|
|
|
|
found.append(parse(option, _item, raw))
|
2023-05-30 07:30:58 +00:00
|
|
|
elif type(_data) == bool:
|
|
|
|
found.append(parse(option, str(_item), raw))
|
2023-05-30 06:49:13 +00:00
|
|
|
if found:
|
|
|
|
print(f'\nfound {len(found)} results in {len(logs)} logs')
|
2023-05-26 21:57:53 +00:00
|
|
|
else:
|
|
|
|
print('usage: python parser.py <field> [clean]\n')
|
2023-05-30 07:10:29 +00:00
|
|
|
print(' <field> may be any item in the snapshots (001, NOTICE, 464, etc) or a string to search')
|
2023-05-26 21:57:53 +00:00
|
|
|
print(' [clean] may be optionally used to display a cleaner output')
|