Created
January 3, 2018 16:00
-
-
Save savex83/79625a7836f4147b44aa2a1fdabb2c4b to your computer and use it in GitHub Desktop.
Postfix log parser to json, just queue-id, message-id and status with remote server response.
This file contains 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/env python | |
''' | |
This program is free software. It comes without any warranty, to | |
the extent permitted by applicable law. You can redistribute it | |
and/or modify it under the terms of the Do What The Fuck You Want | |
To Public License, Version 2, as published by Sam Hocevar. See | |
http://www.wtfpl.net/ for more details. | |
''' | |
import re | |
import json | |
maillog = open("the-file.log","r") | |
regex = re.compile("\s([A-Z0-9]{10}):.*(status|message-id)=(.+)\s", re.M) | |
mailinfo = {} | |
for line in maillog: | |
reobj = regex.search(line,) | |
if reobj: | |
if mailinfo.has_key(reobj.group(1)): | |
mailinfo[reobj.group(1)].update({reobj.group(2): reobj.group(3)}) | |
else: | |
mailinfo[reobj.group(1)] = {reobj.group(2): reobj.group(3)} | |
maillog.close() | |
print json.dumps(mailinfo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment