Skip to content

Commit

Permalink
Fix ping not working logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias- committed Nov 18, 2024
1 parent 5c4c7c7 commit 937288f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,16 @@ func setupMqtt() {
}

func pingIP(pinger *ping.Pinger) error {
oldStats := pinger.Statistics()
oldPacketsRecv := pinger.PacketsRecv

err := pinger.Run()
if err != nil {
log.Logger.Error().Err(err).Msgf("Failed to ping %s", pinger.Addr())
}
stats := pinger.Statistics()
pinger.Stop()
time.Sleep(1 * time.Second)

if oldStats.PacketsRecv < stats.PacketsRecv {
if pinger.PacketsRecv <= oldPacketsRecv {
log.Warn().Msgf("Expected %d to be more than %d", pinger.PacketsRecv, oldPacketsRecv)
return fmt.Errorf("no packets received")
}
return nil
Expand Down

0 comments on commit 937288f

Please sign in to comment.