Merge pull request #11 from geissonator/prettyFormat

Script to parse journalctl json output
diff --git a/post-process/pretty-journal.py b/post-process/pretty-journal.py
new file mode 100644
index 0000000..b6d519a
--- /dev/null
+++ b/post-process/pretty-journal.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+r"""
+BMC FFDC will at times include the journal in json format 
+(journalctl -o json-pretty ).  This is a quick and dirty script which
+will convert that json output into the standard journalctl output
+"""
+
+import json
+import re
+import time
+from argparse import ArgumentParser
+
+def jpretty_to_python(buf):
+    entries = []
+
+    for entry in re.findall(
+            '^{$(.+?)^}$', buf, re.DOTALL | re.MULTILINE):
+        entries += [ json.loads('{{{}}}'.format(entry)) ]
+
+    return entries
+
+if __name__ == '__main__':
+    parser = ArgumentParser()
+    parser.add_argument(
+        'journalfile', metavar='FILE', help='the file to parse')
+
+    args = parser.parse_args()
+
+    with open(args.journalfile) as fd:
+        entries = jpretty_to_python(fd.read())
+        entries = sorted(entries, key=lambda k: k['__REALTIME_TIMESTAMP'])
+
+        for e in entries:
+            e['ts'] = time.ctime(float(e['__REALTIME_TIMESTAMP'])/1000000).rstrip()
+	    try:
+            	print '{ts} {_HOSTNAME} {SYSLOG_IDENTIFIER}: {MESSAGE}'.format(**e)
+	    except:
+		print "Unable to parse msg: " + str(e)
+		continue
+