Skip to content

Commit

Permalink
Added all fields if there are no in Ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvtitan committed Nov 1, 2023
1 parent 6329343 commit 2f3239c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plugins/processors/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -256,6 +258,8 @@ func (f *Filter) Init() error {
f.Log.Error(err)
return err
}

f.rAll = regexp.MustCompile(".*")
f.setTags()

return nil
Expand Down

0 comments on commit 2f3239c

Please sign in to comment.