Skip to content

Commit

Permalink
Reduce ping failures to warning level only
Browse files Browse the repository at this point in the history
Ping failures can happen all the time for no reason, and don't interfere
with service polling. They are warnings at best.
  • Loading branch information
wrouesnel committed Aug 12, 2022
1 parent c393e0a commit 58d95d7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/pollers/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func Ping(ip net.IP, maxRTT time.Duration) (success bool, latency time.Duration)
} else if isIPv6(ip) {
socket, err = icmp.ListenPacket("ip6:ipv6-icmp", "::")
} else {
log.Error("IP did not match any known types?")
log.Warn("IP did not match any known types?")
return
}

if err != nil {
log.Error("Error listening to socket", zap.Error(err))
log.Warn("Error listening to socket", zap.Error(err))
return
}
defer socket.Close()
Expand Down Expand Up @@ -94,7 +94,7 @@ func Ping(ip net.IP, maxRTT time.Duration) (success bool, latency time.Duration)

icmpMessageBytes, err := icmpMessage.Marshal(nil)
if err != nil {
log.Error("Error marshalling packet", zap.String("ip_address", ip.String()), zap.Error(err))
log.Warn("Error marshalling packet", zap.String("ip_address", ip.String()), zap.Error(err))
return
}

Expand All @@ -103,7 +103,7 @@ func Ping(ip net.IP, maxRTT time.Duration) (success bool, latency time.Duration)
dst := &net.IPAddr{IP: ip}

if _, err := socket.WriteTo(icmpMessageBytes, dst); err != nil {
log.Error("Error writing to socket", zap.String("ip_address", ip.String()), zap.Error(err))
log.Warn("Error writing to socket", zap.String("ip_address", ip.String()), zap.Error(err))
return
}

Expand All @@ -114,19 +114,19 @@ func Ping(ip net.IP, maxRTT time.Duration) (success bool, latency time.Duration)
} else if isIPv6(ip) {
icmpMessage.Type = ipv6.ICMPTypeEchoReply
} else {
log.Error("IP did not match any known types?")
log.Warn("IP did not match any known types?")
return
}

icmpMessageBytes, err = icmpMessage.Marshal(nil)
if err != nil {
log.Error("Error marshalling packet", zap.String("ip_address", ip.String()), zap.Error(err))
log.Warn("Error marshalling packet", zap.String("ip_address", ip.String()), zap.Error(err))
return
}

receiveBuffer := make([]byte, 1500) //nolint:gomnd
if err := socket.SetReadDeadline(deadline); err != nil {
log.Error("Error setting socket deadline", zap.String("ip_address", ip.String()), zap.Error(err))
log.Warn("Error setting socket deadline", zap.String("ip_address", ip.String()), zap.Error(err))
return
}
for {
Expand All @@ -140,7 +140,7 @@ func Ping(ip net.IP, maxRTT time.Duration) (success bool, latency time.Duration)
return
}
}
log.Error("Error reading from socket for", zap.String("ip_address", ip.String()), zap.Error(err))
log.Warn("Error reading from socket for", zap.String("ip_address", ip.String()), zap.Error(err))
continue
}
if peer.String() != ip.String() {
Expand Down

0 comments on commit 58d95d7

Please sign in to comment.