Skip lines with missing refid in ntpq input (#5782)

This commit is contained in:
Daniel Nelson
2019-05-07 14:54:43 -07:00
committed by GitHub
parent a0f4c49fb4
commit 3011a009e5
2 changed files with 73 additions and 35 deletions

View File

@@ -75,6 +75,7 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error {
}
lineCounter := 0
numColumns := 0
scanner := bufio.NewScanner(bytes.NewReader(out))
for scanner.Scan() {
line := scanner.Text()
@@ -96,6 +97,7 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error {
// If lineCounter == 0, then this is the header line
if lineCounter == 0 {
numColumns = len(fields)
for i, field := range fields {
// Check if field is a tag:
if tagKey, ok := tagHeaders[field]; ok {
@@ -116,6 +118,10 @@ func (n *NTPQ) Gather(acc telegraf.Accumulator) error {
}
}
} else {
if len(fields) != numColumns {
continue
}
mFields := make(map[string]interface{})
// Get tags from output