Skip to content

Commit

Permalink
fix: backwards compatible
Browse files Browse the repository at this point in the history
support telegraf *filters* config
  • Loading branch information
Sebastian Spaink committed Jun 15, 2022
1 parent c818e92 commit 4c1285c
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,39 @@ func main() {
if err != nil {
log.Fatal("E! " + err.Error())
}

// The sub_Filters are populated when the filter flags are set after the subcommand config
// e.g. telegraf config --section-filter inputs
subSectionFilters := deleteEmpty(strings.Split(":"+strings.TrimSpace(*fSubSectionFilters)+":", ":"))
subInputFilters := deleteEmpty(strings.Split(":"+strings.TrimSpace(*fSubInputFilters)+":", ":"))
subOutputFilters := deleteEmpty(strings.Split(":"+strings.TrimSpace(*fSubOutputFilters)+":", ":"))
subAggregatorFilters := deleteEmpty(strings.Split(":"+strings.TrimSpace(*fsubAggregatorFilters)+":", ":"))
subProcessorFilters := deleteEmpty(strings.Split(":"+strings.TrimSpace(*fSubProcessorFilters)+":", ":"))

// Overwrite the global filters if the subfilters are defined, this allows for backwards compatibility
// Now you can still filter the sample config like so: telegraf --section-filter inputs config
if len(subSectionFilters) > 0 {
sectionFilters = subSectionFilters
}
if len(subInputFilters) > 0 {
inputFilters = subInputFilters
}
if len(subOutputFilters) > 0 {
outputFilters = subOutputFilters
}
if len(subAggregatorFilters) > 0 {
aggregatorFilters = subAggregatorFilters
}
if len(subProcessorFilters) > 0 {
processorFilters = subProcessorFilters
}

config.PrintSampleConfig(
deleteEmpty(strings.Split(":"+strings.TrimSpace(*fSubSectionFilters)+":", ":")),
deleteEmpty(strings.Split(":"+strings.TrimSpace(*fSubInputFilters)+":", ":")),
deleteEmpty(strings.Split(":"+strings.TrimSpace(*fSubOutputFilters)+":", ":")),
deleteEmpty(strings.Split(":"+strings.TrimSpace(*fsubAggregatorFilters)+":", ":")),
deleteEmpty(strings.Split(":"+strings.TrimSpace(*fSubProcessorFilters)+":", ":")),
sectionFilters,
inputFilters,
outputFilters,
aggregatorFilters,
processorFilters,
)
return
}
Expand Down

0 comments on commit 4c1285c

Please sign in to comment.