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

37 lines
779 B
Go

package core
import (
"fmt"
"time"
)
var checkMeasurementAge = checkType{
name: "measurement_age",
toString: func(r CheckResult) string {
return fmt.Sprintf("No measurement from %s (%s) since %s", r.TargetName, r.Target, r.Value)
},
checkFunc: func(e NotifyEvent, s Sensor, b Box) (CheckResult, error) {
result := CheckResult{
Event: e.Type,
Target: s.Id,
TargetName: s.Phenomenon,
Threshold: e.Threshold,
Value: s.LastMeasurement.Date.String(),
Status: CheckOk,
}
thresh, err := time.ParseDuration(e.Threshold)
if err != nil {
return CheckResult{}, err
}
if time.Since(s.LastMeasurement.Date) > thresh {
result.Status = CheckErr
}
result.Value = s.LastMeasurement.Date.String()
return result, nil
},
}