fix(inputs.ping): Avoid -x/-X on FreeBSD 13 and newer with ping6 (#12171)
This commit is contained in:
parent
cd7a4f2756
commit
969188e9db
|
|
@ -105,7 +105,7 @@ func (p *Ping) args(url string, system string) []string {
|
||||||
case "darwin":
|
case "darwin":
|
||||||
args = append(args, "-W", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64))
|
args = append(args, "-W", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64))
|
||||||
case "freebsd":
|
case "freebsd":
|
||||||
if strings.Contains(p.Binary, "ping6") {
|
if strings.Contains(p.Binary, "ping6") && freeBSDMajorVersion() <= 12 {
|
||||||
args = append(args, "-x", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64))
|
args = append(args, "-x", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64))
|
||||||
} else {
|
} else {
|
||||||
args = append(args, "-W", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64))
|
args = append(args, "-W", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64))
|
||||||
|
|
@ -122,7 +122,7 @@ func (p *Ping) args(url string, system string) []string {
|
||||||
if p.Deadline > 0 {
|
if p.Deadline > 0 {
|
||||||
switch system {
|
switch system {
|
||||||
case "freebsd":
|
case "freebsd":
|
||||||
if strings.Contains(p.Binary, "ping6") {
|
if strings.Contains(p.Binary, "ping6") && freeBSDMajorVersion() <= 12 {
|
||||||
args = append(args, "-X", strconv.Itoa(p.Deadline))
|
args = append(args, "-X", strconv.Itoa(p.Deadline))
|
||||||
} else {
|
} else {
|
||||||
args = append(args, "-t", strconv.Itoa(p.Deadline))
|
args = append(args, "-t", strconv.Itoa(p.Deadline))
|
||||||
|
|
@ -251,3 +251,21 @@ func checkRoundTripTimeStats(line string) (roundTripTimeStats, error) {
|
||||||
}
|
}
|
||||||
return roundTripTimeStats, err
|
return roundTripTimeStats, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Due to different behavior in version of freebsd, get the major
|
||||||
|
// version number. In the event of an error we assume we return a low number
|
||||||
|
// to avoid changing behavior.
|
||||||
|
func freeBSDMajorVersion() int {
|
||||||
|
out, err := exec.Command("freebsd-version", "-u").Output()
|
||||||
|
if err != nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
majorVersionStr := strings.Split(string(out), ".")[0]
|
||||||
|
majorVersion, err := strconv.Atoi(majorVersionStr)
|
||||||
|
if err != nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return majorVersion
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue