Skip to content

Commit

Permalink
Print webhook plugin after service plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
cduez committed May 27, 2016
1 parent 0380ea2 commit 9e8dfca
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ var serviceInputHeader = `
###############################################################################
`

var webhookInputHeader = `
###############################################################################
# WEBHOOK INPUT PLUGINS #
###############################################################################
`

// PrintSampleConfig prints the sample config
func PrintSampleConfig(inputFilters []string, outputFilters []string) {
fmt.Printf(header)
Expand Down Expand Up @@ -292,11 +299,16 @@ func printFilteredInputs(inputFilters []string, commented bool) {
}
sort.Strings(pnames)

// cache service inputs to print them at the end
servInputs := make(map[string]telegraf.ServiceInput)
// cache service inputs to print them after inputs
servInputs := make(map[string]telegraf.Input)
// for alphabetical looping:
servInputNames := []string{}

// cache service inputs to print them after at the end
webhookInputs := make(map[string]telegraf.Input)
// for alphabetical looping:
webhookInputNames := []string{}

// Print Inputs
for _, pname := range pnames {
creator := inputs.Inputs[pname]
Expand All @@ -307,19 +319,31 @@ func printFilteredInputs(inputFilters []string, commented bool) {
servInputs[pname] = p
servInputNames = append(servInputNames, pname)
continue
case telegraf.WebhookInput:
webhookInputs[pname] = p
webhookInputNames = append(webhookInputNames, pname)
continue
}

printConfig(pname, input, "inputs", commented)
}

// Print Service Inputs
if len(servInputs) == 0 {
// Print service input
printOtherInputs(serviceInputHeader, servInputs, servInputNames, commented)

// Print webhook input
printOtherInputs(webhookInputHeader, webhookInputs, webhookInputNames, commented)
}

func printOtherInputs(header string, inputs map[string]telegraf.Input, names []string, commented bool) {
if len(names) == 0 {
return
}
sort.Strings(servInputNames)
fmt.Printf(serviceInputHeader)
for _, name := range servInputNames {
printConfig(name, servInputs[name], "inputs", commented)

sort.Strings(names)
fmt.Printf(header)
for _, name := range names {
printConfig(name, inputs[name], "inputs", commented)
}
}

Expand Down

0 comments on commit 9e8dfca

Please sign in to comment.