Skip to content

Commit

Permalink
Add not_statuses support
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeymakinen committed Dec 30, 2023
1 parent 6b9e07d commit 8daff5c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ In this case:
statuses:
[ - <string>, ... ]

# Ignore specific statuses.
not_statuses:
[ - <string>, ... ]

# The regular expression matching the reply code, enhanced code or text.
regexp: <regex>

Expand Down
9 changes: 5 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func Load(name string) (*Config, error) {
}

type StatusReplyMatchConfig struct {
Statuses []string `yaml:"statuses,omitempty"`
Regexp *Regexp `yaml:"regexp"`
Match MatchType `yaml:"match,omitempty"`
Text string `yaml:"text"`
Statuses []string `yaml:"statuses,omitempty"`
NotStatuses []string `yaml:"not_statuses,omitempty"`
Regexp *Regexp `yaml:"regexp"`
Match MatchType `yaml:"match,omitempty"`
Text string `yaml:"text"`
}

func (cfg *StatusReplyMatchConfig) UnmarshalYAML(value *yaml.Node) error {
Expand Down
5 changes: 5 additions & 0 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func (e *Exporter) scrape(r record, err error) {
return nil
}
}
for _, status := range cfg.NotStatuses {
if status == matches[2] {
return nil
}
}
return cfg.Regexp.FindStringSubmatchIndex(match(cfg.Match))
}); m != nil {
text := string(cfg.Regexp.ExpandString(nil, cfg.Text, match(cfg.Match), m))
Expand Down
4 changes: 2 additions & 2 deletions exporter/testdata/postfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ status_replies:
text: sent
- regexp: (?i)spf|dkim|dns
text: local_conf_problem
- statuses:
- sent
- not_statuses:
- bounced
regexp: (.+)
text: $1
smtp_replies:
Expand Down

0 comments on commit 8daff5c

Please sign in to comment.