status/scanner/icmp.go
2024-09-25 20:30:37 +00:00

20 lines
387 B
Go

package scanner
import (
"context"
"github.com/prometheus-community/pro-bing"
)
func CheckICMPUp(ctx context.Context, host string) (bool, string) {
pinger, err := probing.NewPinger(host)
if err != nil {
return false, err.Error()
}
pinger.Count = 1
err = pinger.RunWithContext(ctx) // blocks until finished
if err != nil {
return false, err.Error()
}
return true, "OK"
}