Fix ntpq parse issue when using dns_lookup (#3026)

This commit is contained in:
DanKans
2017-07-18 19:01:08 +01:00
committed by Daniel Nelson
parent f5a8415c78
commit d2626f1da6
2 changed files with 32 additions and 0 deletions

View File

@@ -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