You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

26 lines
589 B

package serial
import "time"
// Allow several normal four-second sweeps to recover from a slow/noisy reply.
// After a confirmed UP, sustained response loss is reported as DOWN.
const CRResponseGracePeriod = 15 * time.Second
func CRConnectionStatus(probe CRProbeState, now time.Time) string {
if !probe.Enabled {
return "unknown"
}
if probe.Up {
return "up"
}
if probe.EverUp && probe.LastResponseAt != nil {
age := now.Sub(*probe.LastResponseAt)
if age >= 0 && age <= CRResponseGracePeriod {
return "up"
}
}
if probe.EverUp {
return "down"
}
return "unknown"
}