alrm/check/check_ping.go

47 lines
693 B
Go
Raw Normal View History

package check
2020-08-20 08:44:56 -08:00
import (
2021-01-02 06:29:12 -09:00
"alrm/check/ping"
"fmt"
2021-01-02 06:29:12 -09:00
"time"
)
2020-08-20 08:44:56 -08:00
type CheckPing struct {
2021-01-02 06:29:12 -09:00
Type string
Address string
Count int
Timeout time.Duration
2020-08-20 08:44:56 -08:00
}
2021-01-02 06:29:12 -09:00
func (c *CheckPing) Check(debuglvl int) error {
if debuglvl > 0 {
fmt.Printf("Pinging %s .. \n", c.Address)
}
p, err := ping.NewPinger(c.Address)
if err != nil {
return err
}
p.Count = 1
p.Timeout = time.Second * 5
err = p.Run()
if err != nil {
return err
}
stats := p.Statistics()
if len(stats.Rtts) < 1 {
return fmt.Errorf("ping failure")
}
if debuglvl > 0 {
fmt.Printf("Ping RTT: %s\n", stats.Rtts[0])
}
2020-08-20 08:44:56 -08:00
return nil
}
func (c *CheckPing) Parse(tk string) (bool, error) {
return false, nil
}