From 2f3239c227be81fc2ed1fab60ce66eeadadd8541 Mon Sep 17 00:00:00 2001 From: "tsv.titan@gmail.com" Date: Wed, 1 Nov 2023 15:28:26 +0200 Subject: [PATCH] Added all fields if there are no in Ifs --- plugins/processors/filter/filter.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/processors/filter/filter.go b/plugins/processors/filter/filter.go index d2ee4b18d0da4..1efa36f2ad8d8 100644 --- a/plugins/processors/filter/filter.go +++ b/plugins/processors/filter/filter.go @@ -32,6 +32,7 @@ type Filter struct { Fields []string `toml:"fields,omitempty"` Tags map[string]string `toml:"tags,omitempty"` Log telegraf.Logger `toml:"-"` + rAll *regexp.Regexp } var description = "Advanced filtering for metrics based on tags" @@ -94,11 +95,12 @@ func (f *Filter) ifCondition(item *FilterIf, metric telegraf.Metric) bool { func (f *Filter) findFields(item *FilterIf, metric telegraf.Metric) []string { r := []string{} - if item.field == nil { - return r - } for k := range metric.Fields() { - if item.field.MatchString(k) { + if item.field != nil { + if item.field.MatchString(k) { + r = append(r, k) + } + } else { r = append(r, k) } } @@ -256,6 +258,8 @@ func (f *Filter) Init() error { f.Log.Error(err) return err } + + f.rAll = regexp.MustCompile(".*") f.setTags() return nil