-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add server option to unbound plugin #3713
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"bufio" | ||
"bytes" | ||
"fmt" | ||
"net" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
|
@@ -15,13 +16,14 @@ import ( | |
"github.com/influxdata/telegraf/plugins/inputs" | ||
) | ||
|
||
type runner func(cmdName string, Timeout internal.Duration, UseSudo bool) (*bytes.Buffer, error) | ||
type runner func(cmdName string, Timeout internal.Duration, UseSudo bool, Server string) (*bytes.Buffer, error) | ||
|
||
// Unbound is used to store configuration values | ||
type Unbound struct { | ||
Binary string | ||
Timeout internal.Duration | ||
UseSudo bool | ||
Server string | ||
|
||
filter filter.Filter | ||
run runner | ||
|
@@ -42,6 +44,10 @@ var sampleConfig = ` | |
|
||
## Use the builtin fielddrop/fieldpass telegraf filters in order to keep/remove specific fields | ||
fieldpass = ["total_*", "num_*","time_up", "mem_*"] | ||
|
||
## IP of server to connect to, read from unbound conf default, optionally '@port' | ||
## Will lookup IP if given a hostname | ||
server = "127.0.0.1@8953" | ||
` | ||
|
||
func (s *Unbound) Description() string { | ||
|
@@ -54,9 +60,18 @@ func (s *Unbound) SampleConfig() string { | |
} | ||
|
||
// Shell out to unbound_stat and return the output | ||
func unboundRunner(cmdName string, Timeout internal.Duration, UseSudo bool) (*bytes.Buffer, error) { | ||
func unboundRunner(cmdName string, Timeout internal.Duration, UseSudo bool, Server string) (*bytes.Buffer, error) { | ||
cmdArgs := []string{"stats_noreset"} | ||
|
||
if Server != "" { | ||
// Unbound control requires an IP address, and we want to be nice to the user | ||
serverIp, err := net.LookupIP(Server) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you will need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a resolver that can accept a timeout. |
||
if err != nil { | ||
return nil, fmt.Errorf("error looking up ip for server: %s: %s", Server, err) | ||
} | ||
cmdArgs = append(cmdArgs, "-s", serverIp[0].String()) | ||
} | ||
|
||
cmd := exec.Command(cmdName, cmdArgs...) | ||
|
||
if UseSudo { | ||
|
@@ -86,7 +101,7 @@ func (s *Unbound) Gather(acc telegraf.Accumulator) error { | |
return err | ||
} | ||
|
||
out, err := s.run(s.Binary, s.Timeout, s.UseSudo) | ||
out, err := s.run(s.Binary, s.Timeout, s.UseSudo, s.Server) | ||
if err != nil { | ||
return fmt.Errorf("error gathering metrics: %s", err) | ||
} | ||
|
@@ -132,6 +147,7 @@ func init() { | |
Binary: defaultBinary, | ||
Timeout: defaultTimeout, | ||
UseSudo: false, | ||
Server: "", | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
:
as separator