Files
scadaproj/docs/deploy/2026-11-19-vd03-nam-ldap/otelgrep.py
T

14 lines
759 B
Python

# usage: python3 otelgrep.py <logs.jsonl pulled from E:\ApiInstall\OtelCollector\data> <service.name regex> <body regex>
import json,sys,re
svcpat=re.compile(sys.argv[2]); pat=re.compile(sys.argv[3],re.I)
for line in open(sys.argv[1]):
try: d=json.loads(line)
except: continue
for rl in d.get('resourceLogs',[]):
svc=next((a['value'].get('stringValue') for a in rl['resource'].get('attributes',[]) if a['key']=='service.name'),'?')
if not svcpat.search(svc): continue
for sl in rl.get('scopeLogs',[]):
for r in sl.get('logRecords',[]):
body=r.get('body',{}).get('stringValue','')
if pat.search(body): print(svc,r.get('timeUnixNano','')[:10],r.get('severityText'),'|',body[:260])