I am using Postfix and I need to parse the mail logs after the mails are sent. Right now, I have been trying to get things to work using Fluentd using the tail plugin to parse Postfix logs.
The problem that I am facing is that I cannot parse them by using the multiline option of the tail plugin. I can parse them individually using regular expressions but not together. This may be because of the fact that the logs are asynchronous in nature and each process logs into the file whenever it has information to be logged. I am planning to write a ruby script for this purpose but this might take a lot of time.
Is there a better solution than writing the script/custom plugin for Fluentd, considering I don't know Ruby/Perl?
Logs for which I do not care to extract information from:
Jan 5 09:02:48 localhost postfix/pickup[5501]: 1733D16A90A: uid=0 from=<root>
Jan 5 09:02:51 localhost postfix/qmgr[2596]: 1733D16A90A: removed
Logs for which I care to extract information from:
Jan 5 09:02:48 localhost postfix/cleanup[5978]: 1733D16A90A: message-id=<[email protected]>
Jan 5 09:02:48 localhost postfix/qmgr[2596]: 1733D16A90A: from=<[email protected]>, size=460, nrcpt=1 (queue active)
Jan 5 09:02:51 localhost postfix/smtp[5980]: 1733D16A90A: to=<[email protected]>, relay=gmail-smtp-in.l.google.com[74.125.130.27]:25, delay=3.4, delays=0.05/0.01/1.9/1.5, dsn=2.0.0, status=sent (250 2.0.0 OK 1483624971 s11si76004239pgc.259 - gsmtp)
The example logs need to be sent to ElasticSearch as a JSON File, which will then save them for further processing.
If you have only to track if a mail is sent. You could use Postfix queue id
(1733D16A90A in your log) as index key in elasticsearch. Then you have to parse each line with grok and update the status for your entry. Take a look at this example for grok patterns :
https://github.com/whyscream/postfix-grok-patterns/blob/master/50-filter-postfix.conf