Cover more postfix logs#49
Open
afeefghannam89 wants to merge 13 commits into
Open
Conversation
widhalmt
approved these changes
May 21, 2026
Member
widhalmt
left a comment
There was a problem hiding this comment.
I could not test the rules with actual log messages. So I had to rely on my memory and it's possible that I missed something. I tried my best to review the rules but it's a huge PR.
I love how you use [@metadata] and parse it in the end of the ruleset. And how you only add the ECS field when a message is marked grokked
Comment on lines
+30
to
51
| if [message] =~ /^reject: header/ { | ||
| grok { | ||
| # header rejected by header_checks map — captures sender, recipient, protocol and reject reason | ||
| match => ["message", "reject: header %{DATA:[postfix][header]} from %{HOSTNAME:[client][address]}\[%{IP:[client][ip]}\]; from=<(%{DATA:[source][user][email]})?> to=<%{DATA:[destination][user][email]}> proto=%{WORD:[postfix][proto]} helo=%{DATA:[postfix][helo]}: %{GREEDYDATA:[postfix][detail]}"] | ||
| tag_on_failure => ["_grokparsefailure", "postfix_cleanup_reject_header_failed"] | ||
| id => "postfix_cleanup_reject_header" | ||
| add_field => { | ||
| "[postfix][eventtype]" => "cleanup_reject_header" | ||
| } | ||
| add_tag => "grokked" | ||
| } | ||
| } | ||
|
|
||
| if [message] =~ /^reject:/ { | ||
| if [message] =~ /^reject: header/ { | ||
| grok { | ||
| match => ["message","reject: header %{DATA:[postfix][header]} from %{HOSTNAME:[client][address]}\[%{IP:[client][ip]}\]; from=<(%{DATA:[destination][user][email]})?> to=<%{DATA:[destination][user][email]}> proto=%{WORD:[postfx][proto]} helo=%{DATA:[postfix][helo]}: %{GREEDYDATA:[postfix][detail]}"] | ||
| tag_on_failure => ["_grokparsefailure","postfix_cleanup_reject_header"] | ||
| id => "postfix_cleanup_reject_header" | ||
| add_field => { | ||
| "[postfix][eventtype]" => "cleanup_reject_header" | ||
| } | ||
| add_tag => "grokked" | ||
| if [message] =~ /^reject: body/ { | ||
| # body content rejected by body_checks map or a milter after the DATA phase | ||
| grok { | ||
| match => ["message", "reject: body %{DATA:[postfix][body_text]} from %{HOSTNAME:[client][address]}\[%{IP:[client][ip]}\]; from=<(%{DATA:[source][user][email]})?> to=<%{DATA:[destination][user][email]}> proto=%{WORD:[postfix][proto]} helo=%{DATA:[postfix][helo]}: %{GREEDYDATA:[postfix][detail]}"] | ||
| tag_on_failure => ["_grokparsefailure", "postfix_cleanup_reject_body_failed"] | ||
| id => "postfix_cleanup_reject_body" | ||
| add_field => { | ||
| "[postfix][eventtype]" => "cleanup_reject_body" | ||
| } |
Member
There was a problem hiding this comment.
Suggested change
| if [message] =~ /^reject: header/ { | |
| grok { | |
| # header rejected by header_checks map — captures sender, recipient, protocol and reject reason | |
| match => ["message", "reject: header %{DATA:[postfix][header]} from %{HOSTNAME:[client][address]}\[%{IP:[client][ip]}\]; from=<(%{DATA:[source][user][email]})?> to=<%{DATA:[destination][user][email]}> proto=%{WORD:[postfix][proto]} helo=%{DATA:[postfix][helo]}: %{GREEDYDATA:[postfix][detail]}"] | |
| tag_on_failure => ["_grokparsefailure", "postfix_cleanup_reject_header_failed"] | |
| id => "postfix_cleanup_reject_header" | |
| add_field => { | |
| "[postfix][eventtype]" => "cleanup_reject_header" | |
| } | |
| add_tag => "grokked" | |
| } | |
| } | |
| if [message] =~ /^reject:/ { | |
| if [message] =~ /^reject: header/ { | |
| grok { | |
| match => ["message","reject: header %{DATA:[postfix][header]} from %{HOSTNAME:[client][address]}\[%{IP:[client][ip]}\]; from=<(%{DATA:[destination][user][email]})?> to=<%{DATA:[destination][user][email]}> proto=%{WORD:[postfx][proto]} helo=%{DATA:[postfix][helo]}: %{GREEDYDATA:[postfix][detail]}"] | |
| tag_on_failure => ["_grokparsefailure","postfix_cleanup_reject_header"] | |
| id => "postfix_cleanup_reject_header" | |
| add_field => { | |
| "[postfix][eventtype]" => "cleanup_reject_header" | |
| } | |
| add_tag => "grokked" | |
| if [message] =~ /^reject: body/ { | |
| # body content rejected by body_checks map or a milter after the DATA phase | |
| grok { | |
| match => ["message", "reject: body %{DATA:[postfix][body_text]} from %{HOSTNAME:[client][address]}\[%{IP:[client][ip]}\]; from=<(%{DATA:[source][user][email]})?> to=<%{DATA:[destination][user][email]}> proto=%{WORD:[postfix][proto]} helo=%{DATA:[postfix][helo]}: %{GREEDYDATA:[postfix][detail]}"] | |
| tag_on_failure => ["_grokparsefailure", "postfix_cleanup_reject_body_failed"] | |
| id => "postfix_cleanup_reject_body" | |
| add_field => { | |
| "[postfix][eventtype]" => "cleanup_reject_body" | |
| } | |
| if [message] =~ /^reject: / { | |
| grok { | |
| # header rejected by header_checks map — captures sender, recipient, protocol and reject reason | |
| match => ["message", "reject: (header %{DATA:[postfix][header]}|body %{DATA:[postfix][body_text]}) from %{HOSTNAME:[client][address]}\[%{IP:[client][ip]}\]; from=<(%{DATA:[source][user][email]})?> to=<%{DATA:[destination][user][email]}> proto=%{WORD:[postfix][proto]} helo=%{DATA:[postfix][helo]}: %{GREEDYDATA:[postfix][detail]}"] | |
| tag_on_failure => ["_grokparsefailure", "postfix_cleanup_reject_header_failed"] | |
| id => "postfix_cleanup_reject_header" | |
| add_field => { | |
| "[postfix][eventtype]" => "cleanup_reject_header" | |
| } | |
| add_tag => "grokked" | |
| } | |
| } |
Wouldn't this work as well? Maybe it's harder to understand and your attempt is still better.
Comment on lines
+37
to
+48
| # numeric status_code used by the OpenSearch upsert script to track final delivery outcome | ||
| # sent=1 wins over deferred=2 wins over bounced=3 (higher code = worse outcome) | ||
| if [postfix][status] == "sent" { | ||
| mutate { add_field => { "[postfix][status_code]" => "1" } } | ||
| } else if [postfix][status] == "deferred" { | ||
| mutate { add_field => { "[postfix][status_code]" => "2" } } | ||
| } else if [postfix][status] == "bounced" { | ||
| mutate { add_field => { "[postfix][status_code]" => "3" } } | ||
| } | ||
| if [postfix][status_code] { | ||
| mutate { convert => { "[postfix][status_code]" => "integer" } } | ||
| } |
Member
There was a problem hiding this comment.
Is there some sort of "official return code" or status code for Postfix actions? While I understand, why we need this for a specific project, we need to keep the project as generic as possible.
Comment on lines
+20
to
+30
| # numeric status_code used by the OpenSearch upsert script to track final delivery outcome | ||
| # sent=1 wins over deferred=2 wins over bounced=3 (higher code = worse outcome) | ||
| if [postfix][status] == "sent" { | ||
| mutate { add_field => { "[postfix][status_code]" => "1" } } | ||
| } else if [postfix][status] == "deferred" { | ||
| mutate { add_field => { "[postfix][status_code]" => "2" } } | ||
| } else if [postfix][status] == "bounced" { | ||
| mutate { add_field => { "[postfix][status_code]" => "3" } } | ||
| } | ||
| if [postfix][status_code] { | ||
| mutate { convert => { "[postfix][status_code]" => "integer" } } |
Comment on lines
+21
to
+32
| # numeric status_code used by the OpenSearch upsert script to track final delivery outcome | ||
| # sent=1 wins over deferred=2 wins over bounced=3 (higher code = worse outcome) | ||
| if [postfix][status] == "sent" { | ||
| mutate { add_field => { "[postfix][status_code]" => "1" } } | ||
| } else if [postfix][status] == "deferred" { | ||
| mutate { add_field => { "[postfix][status_code]" => "2" } } | ||
| } else if [postfix][status] == "bounced" { | ||
| mutate { add_field => { "[postfix][status_code]" => "3" } } | ||
| } | ||
| if [postfix][status_code] { | ||
| mutate { convert => { "[postfix][status_code]" => "integer" } } | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub workflow: