Issues with "inputs.ping" (panic: runtime error and result_code 2)

Hi, I use telegraf and so far everything was running well, but after the last update the ping plugin stopped working:
First I got this error after upgrading from 1.17.0-1 to 1.17.1-1:

telegraf --debug
2021-01-28T02:18:01Z I! Starting Telegraf 1.17.1
2021-01-28T02:18:01Z I! Using config file: /etc/telegraf/telegraf.conf
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1b2542a]
goroutine 109 [running]:
github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).pingToURL(0xc00021e380, 0xc0002dea31, 0x7, 0x34ae180, 0xc0                                                                                                             00c75f40)
        /go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping_notwindows.go:22 +0x18a
github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).Gather.func1(0xc00021e380, 0x34ae180, 0xc000c75f40, 0xc000                                                                                                             2dea31, 0x7)
        /go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping.go:138 +0x9b
created by github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).Gather
        /go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping.go:131 +0xd2

This lead to the service constantly restarting and occured with method=“exec” regardless of the other parameters. It also occured with only urls = [“example.org”] enabled for the ping plugin.

Then I wanted to switch to the method=“native” as an alternative, because it’s supposed to have better performance. After adding the capability using sysctl I checked the process has the capability using:

getpcaps $(ps -A | grep telegraf | cut -d ' ' -f 1)
Capabilities for `22518': = cap_net_raw+i

The database entries only contain result_code 2 and the url/ip. Using --debug there is no additional output:

telegraf --config /etc/telegraf/telegraf.conf --input-filter ping --test --debug
2021-01-28T02:51:40Z I! Starting Telegraf 1.17.1
> ping,url=8.8.8.8 result_code=2i 1611802300000000000

The documentation of the ping plugin just notes that result_code=2 is a “ping error”.

Running this command as root also does not work and has the same result.

Because there is no error in the log or stdout I don’t know what else to try.
My system is debian buster on amd64.

same here on my Unraid box… was wondering why my Grafana dashboard stopped working and I too, narrowed it down to the inputs.ping command.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1b1e30a]

goroutine 81 [running]:
github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).pingToURL(0xc00021c380, 0xc0000b9ec1, 0x7, 0x34a52e0, 0xc000654540)
/go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping_notwindows.go:22 +0x18a
github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).Gather.func1(0xc00021c380, 0x34a52e0, 0xc000654540, 0xc0000b9ec1, 0x7)
/go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping.go:138 +0x9b
created by github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).Gather
/go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping.go:131 +0xd2
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1b1e30a]

goroutine 16 [running]:
github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).pingToURL(0xc00021c380, 0xc0000b9e41, 0x7, 0x34a52e0, 0xc000654540)
/go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping_notwindows.go:22 +0x18a
github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).Gather.func1(0xc00021c380, 0x34a52e0, 0xc000654540, 0xc0000b9e41, 0x7)
/go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping.go:138 +0x9b
created by github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).Gather
/go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping.go:131 +0xd2

I have the same issue.

2021-01-28T18:18:32Z I! Starting Telegraf 1.17.1
2021-01-28T18:18:32Z I! Using config file: /etc/telegraf/telegraf.conf
2021-01-28T18:18:32Z I! Loaded inputs: ping
2021-01-28T18:18:32Z I! Loaded aggregators: 
2021-01-28T18:18:32Z I! Loaded processors: 
2021-01-28T18:18:32Z I! Loaded outputs: influxdb
2021-01-28T18:18:32Z I! Tags enabled: host=telegraf
2021-01-28T18:18:32Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"telegraf", Flush 
Interval:10s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1b2542a]

goroutine 59 [running]:
github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).pingToURL(0xc000238380, 0xc000053fc1, 
0xe, 0x34ae180, 0xc00000f3e0) 
/go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping_notwindows.go:22 +0x18a
github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).Gather.func1(0xc000238380, 0x34ae180, 
0xc00000f3e0, 0xc000053fc1, 0xe)
/go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping.go:138 +0x9b
created by github.com/influxdata/telegraf/plugins/inputs/ping.(*Ping).Gather
/go/src/github.com/influxdata/telegraf/plugins/inputs/ping/ping.go:131 +0xd2
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1b2542a]

I provisioned a container with telegraf:latest with the issues listed above. Thanks to your comments, I choose I earlier release of 1.16 and it works.

2021-01-28T18:24:18Z I! Starting Telegraf 1.16.3
2021-01-28T18:24:18Z I! Using config file: /etc/telegraf/telegraf.conf
2021-01-28T18:24:18Z I! Loaded inputs: ping
2021-01-28T18:24:18Z I! Loaded aggregators: 
2021-01-28T18:24:18Z I! Loaded processors: 
2021-01-28T18:24:18Z I! Loaded outputs: influxdb
2021-01-28T18:24:18Z I! Tags enabled: host=telegraf
2021-01-28T18:24:18Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"telegraf", Flush 
Interval:10s

I have the same problem after upgrading to 1.17.1 - also in Docker on UnRAID:

2021-01-29T03:01:47Z I! Starting Telegraf 1.17.1
2021-01-29T03:01:47Z I! Using config file: /etc/telegraf/telegraf.conf
2021-01-29T03:01:47Z I! Loaded inputs: cpu disk diskio exec (13x) internal kernel mem net ping processes smart swap system
2021-01-29T03:01:47Z I! Loaded aggregators:
2021-01-29T03:01:47Z I! Loaded processors:
2021-01-29T03:01:47Z I! Loaded outputs: influxdb
2021-01-29T03:01:47Z I! Tags enabled: host=NAS
2021-01-29T03:01:47Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"NAS", Flush Interval:10s
2021-01-29T03:01:47Z W! [inputs.smart] nvme not found: verify that nvme is installed and it is in your PATH (or specified in config) to gather vendor specific attributes: provided path does not exist: []
panic: runtime error: invalid memory address or nil pointer dereference

Like @Vulco_Viljoen, I’ve reverted to 1.16.3 and it’s working again.

The issue with the panic:runtime error with method=“exec” was fixed in 1.17.2-1, but I still can’t get method=“native” to work.

It looks fixed for me in the latest docker update.