feat(client): Add network config for ICMP endpoint client (#661)

* feat(client): Add network to config

* feat(client): Use network client config for pinger

* feat(client): Add client network configuration and demo to README

* feat(client): Add tests for pinger using network config

* feat(client): Drop integration tests

* feat(client): Add comment to tests

* feat(client): Add tests

* Update README.md

---------

Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
Nicolas Thumann
2024-02-07 03:15:51 +01:00
committed by GitHub
parent 6cbc59b0e8
commit 3d1b4e566d
4 changed files with 34 additions and 5 deletions

View File

@ -235,10 +235,7 @@ func ExecuteSSHCommand(sshClient *ssh.Client, body string, config *Config) (bool
//
// Note that this function takes at least 100ms, even if the address is 127.0.0.1
func Ping(address string, config *Config) (bool, time.Duration) {
pinger, err := ping.NewPinger(address)
if err != nil {
return false, 0
}
pinger := ping.New(address)
pinger.Count = 1
pinger.Timeout = config.Timeout
// Set the pinger's privileged mode to true for every GOOS except darwin
@ -247,7 +244,8 @@ func Ping(address string, config *Config) (bool, time.Duration) {
// Note that for this to work on Linux, Gatus must run with sudo privileges.
// See https://github.com/prometheus-community/pro-bing#linux
pinger.SetPrivileged(runtime.GOOS != "darwin")
err = pinger.Run()
pinger.SetNetwork(config.Network)
err := pinger.Run()
if err != nil {
return false, 0
}