in cmd/ptpcheck/cmd/diag.go [56:95]
func checkAgainstThreshold(name string, value, warnThreshold, failThreshold float64, explanation string, failOnZero bool) (status, string) {
msgTemplate := "%s is %s, we expect it to be within %s%s"
absValue := math.Abs(value)
thresholdStr := color.BlueString("%v", time.Duration(warnThreshold))
if failOnZero && absValue == 0 {
return FAIL, fmt.Sprintf(
"%s is %s, we expect it to be non-zero and within %s%s",
name,
color.RedString("%v", time.Duration(value)),
thresholdStr,
". "+explanation,
)
}
if absValue > failThreshold {
return FAIL, fmt.Sprintf(
msgTemplate,
name,
color.RedString("%v", time.Duration(value)),
thresholdStr,
". "+explanation,
)
}
if absValue > warnThreshold {
return WARN, fmt.Sprintf(
msgTemplate,
name,
color.YellowString("%v", time.Duration(value)),
thresholdStr,
". "+explanation,
)
}
return OK, fmt.Sprintf(
msgTemplate,
name,
color.GreenString("%v", time.Duration(value)),
thresholdStr,
"",
)
}