blob: b6d519afcac5d8c6d3b4a9b95220063beac11e92 [file] [log] [blame]
Andrew Geissler19672b62018-02-07 12:33:02 -06001#!/usr/bin/env python
2
3r"""
4BMC FFDC will at times include the journal in json format
5(journalctl -o json-pretty ). This is a quick and dirty script which
6will convert that json output into the standard journalctl output
7"""
8
9import json
10import re
11import time
12from argparse import ArgumentParser
13
14def jpretty_to_python(buf):
15 entries = []
16
17 for entry in re.findall(
18 '^{$(.+?)^}$', buf, re.DOTALL | re.MULTILINE):
19 entries += [ json.loads('{{{}}}'.format(entry)) ]
20
21 return entries
22
23if __name__ == '__main__':
24 parser = ArgumentParser()
25 parser.add_argument(
26 'journalfile', metavar='FILE', help='the file to parse')
27
28 args = parser.parse_args()
29
30 with open(args.journalfile) as fd:
31 entries = jpretty_to_python(fd.read())
32 entries = sorted(entries, key=lambda k: k['__REALTIME_TIMESTAMP'])
33
34 for e in entries:
35 e['ts'] = time.ctime(float(e['__REALTIME_TIMESTAMP'])/1000000).rstrip()
36 try:
37 print '{ts} {_HOSTNAME} {SYSLOG_IDENTIFIER}: {MESSAGE}'.format(**e)
38 except:
39 print "Unable to parse msg: " + str(e)
40 continue
41