status/scanner/icmp.go
2023-10-01 22:56:35 +05:30

24 lines
487 B
Go

package scanner
import (
"github.com/prometheus-community/pro-bing"
"time"
"context"
)
func CheckICMPUp(host string) (bool, string) {
timeout := time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
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"
}