fix(inputs.ping): Add option to force ipv4 (#15011)

This commit is contained in:
Joshua Powers 2024-03-20 06:02:23 -06:00 committed by GitHub
parent 86aedb4e8e
commit 60adc92014
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 3 deletions

View File

@ -80,7 +80,12 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
## etc) will be ignored.
# arguments = ["-c", "3"]
## Use only IPv6 addresses when resolving a hostname.
## Use only IPv4 addresses when resolving a hostname. By default, both IPv4
## and IPv6 can be used.
# ipv4 = false
## Use only IPv6 addresses when resolving a hostname. By default, both IPv4
## and IPv6 can be used.
# ipv6 = false
## Number of data bytes to be sent. Corresponds to the "-s"

View File

@ -73,6 +73,9 @@ type Ping struct {
// other options (ping_interval, timeout, etc.) will be ignored
Arguments []string
// Whether to resolve addresses using ipv4 or not.
IPv4 bool
// Whether to resolve addresses using ipv6 or not.
IPv6 bool
@ -129,7 +132,11 @@ func (p *Ping) nativePing(destination string) (*pingStats, error) {
pinger.SetPrivileged(true)
if p.IPv6 {
if p.IPv4 && p.IPv6 {
pinger.SetNetwork("ip")
} else if p.IPv4 {
pinger.SetNetwork("ip4")
} else if p.IPv6 {
pinger.SetNetwork("ip6")
}

View File

@ -43,7 +43,12 @@
## etc) will be ignored.
# arguments = ["-c", "3"]
## Use only IPv6 addresses when resolving a hostname.
## Use only IPv4 addresses when resolving a hostname. By default, both IPv4
## and IPv6 can be used.
# ipv4 = false
## Use only IPv6 addresses when resolving a hostname. By default, both IPv4
## and IPv6 can be used.
# ipv6 = false
## Number of data bytes to be sent. Corresponds to the "-s"