diff --git a/plugins/inputs/ntpq/ntpq.go b/plugins/inputs/ntpq/ntpq.go index 067888b95..25d1fa3cc 100644 --- a/plugins/inputs/ntpq/ntpq.go +++ b/plugins/inputs/ntpq/ntpq.go @@ -223,6 +223,10 @@ func (n *NTPQ) gatherServer(acc telegraf.Accumulator, server string) { } fields[col.name] = value case FieldDuration: + // Ignore fields only containing a minus + if raw == "-" { + continue + } factor := int64(1) suffix := raw[len(raw)-1:] switch suffix { diff --git a/plugins/inputs/ntpq/testcases/pool_when_minus/expected.out b/plugins/inputs/ntpq/testcases/pool_when_minus/expected.out new file mode 100644 index 000000000..13cb8c442 --- /dev/null +++ b/plugins/inputs/ntpq/testcases/pool_when_minus/expected.out @@ -0,0 +1,2 @@ +ntpq,remote=0.eu.pool.ntp.o,refid=.POOL.,stratum=16,type=p poll=64i,reach=0i,delay=0.0,offset=0.0,jitter=0.0 0 +ntpq,remote=195.201.19.162,refid=187.182.182.166,stratum=3,type=u poll=64i,reach=1i,delay=12.692,offset=1.283,jitter=0.0 0 diff --git a/plugins/inputs/ntpq/testcases/pool_when_minus/input.txt b/plugins/inputs/ntpq/testcases/pool_when_minus/input.txt new file mode 100644 index 000000000..1a2014b53 --- /dev/null +++ b/plugins/inputs/ntpq/testcases/pool_when_minus/input.txt @@ -0,0 +1,4 @@ + remote refid st t when poll reach delay offset jitter +============================================================================== + 0.eu.pool.ntp.o .POOL. 16 p - 64 0 0.000 +0.000 0.000 + 195.201.19.162 187.182.182.166 3 u - 64 1 12.692 +1.283 0.000 diff --git a/plugins/inputs/ntpq/testcases/pool_when_minus/telegraf.conf b/plugins/inputs/ntpq/testcases/pool_when_minus/telegraf.conf new file mode 100644 index 000000000..1265dc219 --- /dev/null +++ b/plugins/inputs/ntpq/testcases/pool_when_minus/telegraf.conf @@ -0,0 +1 @@ +[[inputs.ntpq]] \ No newline at end of file