diff --git a/CONFIGURATION.md b/CONFIGURATION.md index ba2899e..c56ce7b 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -41,6 +41,10 @@ In this case: statuses: [ - , ... ] +# Ignore specific statuses. +not_statuses: + [ - , ... ] + # The regular expression matching the reply code, enhanced code or text. regexp: diff --git a/config/config.go b/config/config.go index fc5e99e..ade72bb 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/exporter/exporter.go b/exporter/exporter.go index 79dca67..65b8a66 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -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)) diff --git a/exporter/testdata/postfix.yml b/exporter/testdata/postfix.yml index 16316bd..1a793fc 100644 --- a/exporter/testdata/postfix.yml +++ b/exporter/testdata/postfix.yml @@ -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: