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" }