From e32afe7ac6102c5b3f5181c60e1e98d7b4cc991e Mon Sep 17 00:00:00 2001 From: Daniel Salbert Date: Mon, 17 Jul 2017 13:06:54 +0100 Subject: [PATCH 1/3] Related to https://github.com/influxdata/telegraf/issues/2554 --- agent/agent.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/agent/agent.go b/agent/agent.go index b6db56c5bd3fd..75041a36fca00 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -360,6 +360,12 @@ func (a *Agent) Run(shutdown chan struct{}) error { a.Config.Agent.Interval.Duration, a.Config.Agent.Quiet, a.Config.Agent.Hostname, a.Config.Agent.FlushInterval.Duration) + if int64(a.Config.Agent.Interval.Duration) <= 0 { + log.Printf("E! Wrong Interval value (%s) in agent configuration. Please set bigger value.\n", + a.Config.Agent.Interval.Duration) + return nil + } + // channel shared between all input threads for accumulating metrics metricC := make(chan telegraf.Metric, 100) aggC := make(chan telegraf.Metric, 100) From e8ca023481da4063c8dce7c9242359e4e4ce40d0 Mon Sep 17 00:00:00 2001 From: Daniel Salbert Date: Tue, 18 Jul 2017 11:12:16 +0100 Subject: [PATCH 2/3] add regular expression to tackle a problem #2386 --- plugins/inputs/ntpq/ntpq.go | 11 +++++++++++ plugins/inputs/ntpq/ntpq_test.go | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/plugins/inputs/ntpq/ntpq.go b/plugins/inputs/ntpq/ntpq.go index 8280e51c1dc81..597db0bd1865e 100644 --- a/plugins/inputs/ntpq/ntpq.go +++ b/plugins/inputs/ntpq/ntpq.go @@ -7,6 +7,7 @@ import ( "bytes" "fmt" "os/exec" + "regexp" "strconv" "strings" @@ -67,6 +68,14 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error { return err } + // Due to problems with a parsing, we have to use regexp expression in order + // to remove string that starts from '(' and ends with space + // see: https://github.com/influxdata/telegraf/issues/2386 + reg, err := regexp.Compile("\\([\\S]*") + if err != nil { + return err + } + lineCounter := 0 scanner := bufio.NewScanner(bytes.NewReader(out)) for scanner.Scan() { @@ -80,6 +89,8 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error { line = strings.TrimLeft(line, "*#o+x.-") } + line = reg.ReplaceAllString(line, "") + fields := strings.Fields(line) if len(fields) < 2 { continue diff --git a/plugins/inputs/ntpq/ntpq_test.go b/plugins/inputs/ntpq/ntpq_test.go index 4b356e1f180af..d8da845d10e19 100644 --- a/plugins/inputs/ntpq/ntpq_test.go +++ b/plugins/inputs/ntpq/ntpq_test.go @@ -247,6 +247,21 @@ func TestBadWhenNTPQ(t *testing.T) { acc.AssertContainsTaggedFields(t, "ntpq", fields, tags) } +// TestParserNTPQ - realated to: +// https://github.com/influxdata/telegraf/issues/2386 +func TestParserNTPQ(t *testing.T) { + tt := tester{ + ret: []byte(multiParserNTPQ), + err: nil, + } + + n := &NTPQ{ + runQ: tt.runqTest, + } + acc := testutil.Accumulator{} + assert.NoError(t, acc.GatherError(n.Gather)) +} + func TestMultiNTPQ(t *testing.T) { tt := tester{ ret: []byte(multiNTPQ), @@ -463,3 +478,9 @@ var multiNTPQ = ` remote refid st t when poll reach delay 5.9.29.107 10.177.80.37 2 u 703 1024 377 205.704 160.406 449602. 91.189.94.4 10.177.80.37 2 u 673 1024 377 143.047 274.726 449445. ` +var multiParserNTPQ = ` remote refid st t when poll reach delay offset jitter +============================================================================== ++37.58.57.238 (d 192.53.103.103 2 u 10 1024 377 1.748 0.373 0.101 ++37.58.57.238 (domain) 192.53.103.103 2 u 10 1024 377 1.748 0.373 0.101 ++37.58.57.238 ( 192.53.103.103 2 u 10 1024 377 1.748 0.373 0.101 +` From a6aeea057aa4ed205871fca6633d76fc3f778bf2 Mon Sep 17 00:00:00 2001 From: Daniel Salbert Date: Tue, 18 Jul 2017 11:21:43 +0100 Subject: [PATCH 3/3] Revert "Related to https://github.com/influxdata/telegraf/issues/2554" This reverts commit e32afe7ac6102c5b3f5181c60e1e98d7b4cc991e. --- agent/agent.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 75041a36fca00..b6db56c5bd3fd 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -360,12 +360,6 @@ func (a *Agent) Run(shutdown chan struct{}) error { a.Config.Agent.Interval.Duration, a.Config.Agent.Quiet, a.Config.Agent.Hostname, a.Config.Agent.FlushInterval.Duration) - if int64(a.Config.Agent.Interval.Duration) <= 0 { - log.Printf("E! Wrong Interval value (%s) in agent configuration. Please set bigger value.\n", - a.Config.Agent.Interval.Duration) - return nil - } - // channel shared between all input threads for accumulating metrics metricC := make(chan telegraf.Metric, 100) aggC := make(chan telegraf.Metric, 100)