Search for chronyc only when chrony input plugin is enabled (#7005)

This commit is contained in:
Daniel Nelson 2020-02-10 14:22:07 -08:00 committed by GitHub
parent d3b89ec51f
commit 5b8c71e61a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -33,11 +33,16 @@ func (*Chrony) SampleConfig() string {
`
}
func (c *Chrony) Gather(acc telegraf.Accumulator) error {
if len(c.path) == 0 {
func (c *Chrony) Init() error {
var err error
c.path, err = exec.LookPath("chronyc")
if err != nil {
return errors.New("chronyc not found: verify that chrony is installed and that chronyc is in your PATH")
}
return nil
}
func (c *Chrony) Gather(acc telegraf.Accumulator) error {
flags := []string{}
if !c.DNSLookup {
flags = append(flags, "-n")
@ -120,12 +125,7 @@ func processChronycOutput(out string) (map[string]interface{}, map[string]string
}
func init() {
c := Chrony{}
path, _ := exec.LookPath("chronyc")
if len(path) > 0 {
c.path = path
}
inputs.Add("chrony", func() telegraf.Input {
return &c
return &Chrony{}
})
}