Last active
October 17, 2024 09:31
-
-
Save TinLe/f9763ac68c122cd11b91 to your computer and use it in GitHub Desktop.
postfix grok patterns for logstash
This file contains hidden or 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
# Syslog stuff | |
COMPONENT ([\w._\/%-]+) | |
COMPID postfix\/%{COMPONENT:component}(?:\[%{NUMBER:pid}\])? | |
POSTFIX (?:%{SYSLOGTIMESTAMP:timestamp}|%{TIMESTAMP_ISO8601:timestamp8601}) (?:%{SYSLOGFACILITY} )?%{SYSLOGHOST:logsource} %{COMPID}: | |
# Milter | |
HELO (?:\[%{IP:helo}\]|%{HOST:helo}|%{DATA:helo}) | |
MILTERCONNECT %{QUEUEID:qid}: milter-reject: CONNECT from %{RELAY:relay}: %{GREEDYDATA:milter_reason}; proto=%{WORD:proto} | |
MILTERUNKNOWN %{QUEUEID:qid}: milter-reject: UNKNOWN from %{RELAY:relay}: %{GREEDYDATA:milter_reason}; proto=%{WORD:proto} | |
MILTEREHLO %{QUEUEID:qid}: milter-reject: EHLO from %{RELAY:relay}: %{GREEDYDATA:milter_reason}; proto=%{WORD:proto} helo=<%{HELO}> | |
MILTERMAIL %{QUEUEID:qid}: milter-reject: MAIL from %{RELAY:relay}: %{GREEDYDATA:milter_reason}; from=<%{EMAILADDRESS:from}> proto=%{WORD:proto} helo=<%{HELO}> | |
MILTERHELO %{QUEUEID:qid}: milter-reject: HELO from %{RELAY:relay}: %{GREEDYDATA:milter_reason}; proto=%{WORD:proto} helo=<%{HELO}> | |
MILTERRCPT %{QUEUEID:qid}: milter-reject: RCPT from %{RELAY:relay}: %{GREEDYDATA:milter_reason}; from=<%{EMAILADDRESS:from}> to=<%{EMAILADDRESS:to}> proto=%{WORD:proto} helo=<%{HELO}> | |
MILTERENDOFMESSAGE %{QUEUEID:qid}: milter-reject: END-OF-MESSAGE from %{RELAY:relay}: %{GREEDYDATA:milter_reason}; from=<%{EMAILADDRESS:from}> to=<%{EMAILADDRESS:to}> proto=%{WORD:proto} helo=<%{HELO}> | |
# Postfix stuff | |
HELO (?:\[%{IP:helo}\]|%{HOST:helo}|%{DATA:helo}) | |
QUEUEID (?:[A-F0-9]+|NOQUEUE) | |
EMAILADDRESSPART [a-zA-Z0-9_.+-=:~]+ | |
EMAILADDRESS %{EMAILADDRESSPART:local}@%{EMAILADDRESSPART:remote} | |
RELAY (?:%{HOSTNAME:relayhost}(?:\[%{IP:relayip}\](?::[0-9]+(.[0-9]+)?)?)?) | |
POSREAL [0-9]+(.[0-9]+)? | |
DSN %{NONNEGINT}.%{NONNEGINT}.%{NONNEGINT} | |
STATUS sent|deferred|bounced|expired | |
PERMERROR 5[0-9]{2} | |
MESSAGELEVEL reject|warning|error|fatal|panic | |
POSTFIXSMTPMESSAGE %{MESSAGELEVEL}: %{GREEDYDATA:reason} | |
POSTFIXACTION discard|dunno|filter|hold|ignore|info|prepend|redirect|replace|reject|warn | |
# postfix/smtp and postfix/lmtp, postfix/local and postfix/error | |
POSTFIXSMTP %{POSTFIXSMTPRELAY}|%{POSTFIXSMTPCONNECT}|%{POSTFIXSMTP5XX}|%{POSTFIXSMTPREFUSAL}|%{POSTFIXSMTPLOSTCONNECTION}|%{POSTFIXSMTPTIMEOUT} | |
POSTFIXSMTPRELAY %{QUEUEID:qid}: to=<%{DATA:to}>,(?:\sorig_to=<%{DATA:orig_to}>,)? relay=%{RELAY},(?: delay=%{POSREAL:delay},)?(?: delays=%{DATA:delays}?,)?(?: conn_use=%{POSREAL:conn_use},)?( %{WORD}=%{DATA},)+? dsn=%{DSN:dsn}, status=%{STATUS:result} %{GREEDYDATA:reason} | |
POSTFIXSMTPCONNECT connect to %{RELAY}: %{GREEDYDATA:reason} | |
POSTFIXSMTP5XX %{QUEUEID:qid}: to=<%{EMAILADDRESS:to}>,(?:\sorig_to=<%{EMAILADDRESS:orig_to}>,)? relay=%{RELAY}, (%{WORD}=%{DATA},)+ dsn=%{DSN:dsn}, status=%{STATUS:result} \(host %{HOSTNAME}\[%{IP}\] said: %{PERMERROR:responsecode} %{DATA:smtp_response} \(in reply to %{DATA:command} command\)\) | |
POSTFIXSMTPREFUSAL %{QUEUEID:qid}: host %{RELAY} refused to talk to me: %{GREEDYDATA:reason} | |
POSTFIXSMTPLOSTCONNECTION %{QUEUEID:qid}: lost connection with %{RELAY} while %{GREEDYDATA:reason} | |
POSTFIXSMTPTIMEOUT %{QUEUEID:qid}: conversation with %{RELAY} timed out while %{GREEDYDATA:reason} | |
# postfix/smtpd | |
POSTFIXSMTPD %{POSTFIXSMTPDCONNECTS}|%{POSTFIXSMTPDMILTER}|%{POSTFIXSMTPDACTIONS}|%{POSTFIXSMTPDTIMEOUTS}|%{POSTFIXSMTPDLOGIN}|%{POSTFIXSMTPDCLIENT}|%{POSTFIXSMTPDNOQUEUE}|%{POSTFIXSMTPDWARNING}|%{POSTFIXSMTPDLOSTCONNECTION} | |
POSTFIXSMTPDCONNECTS (?:dis)?connect from %{RELAY} | |
POSTFIXSMTPDMILTER %{MILTERCONNECT}|%{MILTERUNKNOWN}|%{MILTEREHLO}|%{MILTERMAIL}|%{MILTERHELO}|%{MILTERRCPT} | |
POSTFIXSMTPDACTIONS %{QUEUEID:qid}: %{POSTFIXACTION:postfix_action}: %{DATA:command} from %{RELAY}: %{PERMERROR:responsecode} %{DSN:dsn} %{DATA}: %{DATA:reason}; from=<%{EMAILADDRESS:from}> to=<%{EMAILADDRESS:to}> proto=%{DATA:proto} helo=<%{HELO}> | |
POSTFIXSMTPDTIMEOUTS timeout after %{DATA:command} from %{RELAY} | |
POSTFIXSMTPDLOGIN %{QUEUEID:qid}: client=%{DATA:client}, sasl_method=%{DATA:saslmethod}, sasl_username=%{GREEDYDATA:saslusername} | |
POSTFIXSMTPDCLIENT %{QUEUEID:qid}: client=%{GREEDYDATA:client} | |
POSTFIXSMTPDNOQUEUE NOQUEUE: %{POSTFIXACTION:postfix_action}: %{DATA:command} from %{RELAY}: %{GREEDYDATA:reason} | |
POSTFIXSMTPDWARNING warning:( %{IP}: | hostname %{HOSTNAME} )?%{GREEDYDATA:reason} | |
POSTFIXSMTPDLOSTCONNECTION (?:lost connection after %{DATA:smtp_response} from %{RELAY}|improper command pipelining after HELO from %{GREEDYDATA:reason}) | |
# postfix/cleanup | |
POSTFIXCLEANUP %{POSTFIXCLEANUPMESSAGE}|%{POSTFIXCLEANUPMILTER} | |
POSTFIXCLEANUPMESSAGE %{QUEUEID:qid}: (resent-)?message-id=(<)?%{GREEDYDATA:messageid}(>)? | |
POSTFIXCLEANUPMILTER %{MILTERENDOFMESSAGE} | |
# postfix/bounce | |
POSTFIXBOUNCE %{QUEUEID:qid}: sender (non-)?delivery( status)? notification: %{QUEUEID:bouncequeueid} | |
# postfix/qmgr and postfix/pickup | |
POSTFIXQMGR %{QUEUEID:qid}: (?:removed|from=<(?:%{DATA:from})?>(?:, size=%{NUMBER:size}, nrcpt=%{NUMBER:nrcpt} \(%{GREEDYDATA:queuestatus}\))?) | |
# postfix/anvil | |
POSTFIXANVIL statistics: %{GREEDYDATA:reason} | |
# postfix/trivial-rewrite | |
POSTFIXREWRITE warning: do not list domain %{DATA:domain} in BOTH mydestination and virtual_alias_domains | |
# Dovecot | |
DOVEIMAP imap\(%{DATA:user}\): %{DATA:reason} in=%{NUMBER:inbytes} out=%{NUMBER:outbytes} | |
DOVECMD anvil|auth|config|log|master | |
DOVEMISC %{DOVECMD:command}: %{GREEDYDATA:reason} | |
DOVELOGIN imap-login: %{DATA:action}:(?: user=<(%{DATA:user})?>, (method=%{DATA:loginmethod}, )?rip=%{IP:rip}, lip=%{IP:lip},( mpid=%{NUMBER:mpid},( %{DATA:sectype},)?| %{DATA:securesession},)? session=<%{DATA:session}>| %{GREEDYDATA:reason}) | |
DOVELDA lda\((%{DATA:user})?\):( %{DATA:action}:)? msgid=(?:<%{DATA:mesgid}@%{DATA:domain}>|%{DATA:mesgid}):( saved mail to| stored mail into mailbox) .*?%{DATA:folder}.*? | |
DOVEAUTH auth-worker\(%{NUMBER:pid}\): pam\((?:%{USERNAME:user}|%{EMAILADDRESS:user}),%{IP:ip}\): %{GREEDYDATA:reason} | |
# Dovecot wrap em up | |
DOVECOT (?:%{SYSLOGTIMESTAMP:timestamp}|%{TIMESTAMP_ISO8601:timestamp8601}) (?:%{SYSLOGFACILITY} )?%{SYSLOGHOST:logsource} dovecot: (%{DOVEIMAP}|%{DOVELOGIN}|%{DOVELDA}|%{DOVEAUTH}|%{DOVEMISC}) | |
# Postfix wrap em up | |
PF %{POSTFIX} (?:%{POSTFIXSMTP}|%{POSTFIXANVIL}|%{POSTFIXQMGR}|%{POSTFIXBOUNCE}|%{POSTFIXCLEANUP}|%{POSTFIXSMTPD}|%{POSTFIXREWRITE}) |
Postfix pattern causes error in latest Logstash:
[2020-10-01T11:28:30,027][ERROR][logstash.agent ] Failed to execute action {:id=>:main, :action_type=>LogStash::ConvergeResult::FailedAction, :message=>"Could not execute action: PipelineAction::Create<main>, action_result: false", :backtrace=>nil}
HELO (?:[%{IP:helo}]|%{HOSTNAME:helo}|%{DATA:helo})
This was the cause of the error. Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there any postfix filter for multiple lines.
Sep 23 18:11:48 share postfix/pickup[11067]: E1010623160E: uid=0 from=[email protected]
Sep 23 18:11:48 share postfix/cleanup[17185]: E1010623160E: warning: header Subject: Review and update IT assets - US from local; from=[email protected] to=[email protected]
Sep 23 18:11:48 share postfix/cleanup[17185]: E1010623160E: message-id=5d88bd8c.53hwfoOxAPVNmQpT%[email protected]
Sep 23 18:11:48 share postfix/cleanup[17185]: E1010623160E: warning: header Content-Disposition: attachment;? filename="ConfIncomingPostfixForTM.sh" from local; from=[email protected] to=[email protected]
Sep 23 18:11:48 share postfix/qmgr[11068]: E1010623160E: from=[email protected], size=13835, nrcpt=1 (queue active)
Sep 23 18:11:49 share postfix/smtp[17187]: E1010623160E: to=[email protected], relay=abc.cde.com[xx.xx.xx.xx]:587, delay=0.82, delays=0.12/0.01/0.23/0.47, dsn=2.0.0, status=sent (250 ok 1569242509 qp 55892 by mail.com)
Sep 23 18:11:49 share postfix/qmgr[11068]: E1010623160E: removed
I want to filter following content from these lines.
from=[email protected], Subject: Review and update IT assets - US, to=[email protected], message-id=5d88bd8c.53hwfoOxAPVNmQpT%[email protected], attachment;? filename="ConfIncomingPostfixForTM.sh", size=13835, relay=abc.cde.com[xx.xx.xx.xx]:587, delay=0.82, delays=0.12/0.01/0.23/0.47, dsn=2.0.0, status=sent