Skip to content

Commit

Permalink
Added several fields to check
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvtitan committed Oct 31, 2023
1 parent 02e68f9 commit 6329343
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions plugins/processors/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,30 @@ func (f *Filter) ifCondition(item *FilterIf, metric telegraf.Metric) bool {
return flag
}

func (f *Filter) skipFields(item *FilterIf, metric telegraf.Metric) bool {
func (f *Filter) findFields(item *FilterIf, metric telegraf.Metric) []string {

r := []string{}
if item.field == nil {
return false
return r
}
for k := range metric.Fields() {
if !item.field.MatchString(k) {
return true
if item.field.MatchString(k) {
r = append(r, k)
}
}
return false
return r
}

func (f *Filter) skipMinMax(item *FilterIf, metric telegraf.Metric) bool {
func (f *Filter) skipMinMax(item *FilterIf, metric telegraf.Metric, fields []string) bool {

if item.Min == nil && item.Max == nil {
return false
}
for _, field := range metric.Fields() {
for n, field := range metric.Fields() {

if !utils.Contains(fields, n) {
continue
}
v, err := strconv.ParseFloat(fmt.Sprintf("%v", field), 64)
if err != nil {
return true
Expand Down Expand Up @@ -165,11 +170,12 @@ func (f *Filter) Apply(in ...telegraf.Metric) []telegraf.Metric {
continue
}

if f.skipFields(item, metric) {
fields := f.findFields(item, metric)
if len(fields) == 0 {
continue
}

if f.skipMinMax(item, metric) {
if f.skipMinMax(item, metric, fields) {
continue
}

Expand Down

0 comments on commit 6329343

Please sign in to comment.