Open
Description
Sometimes there's a need for this util function:
func convertStateToInt(state string) (int, error) {
state = strings.ToUpper(state)
switch state {
case "OK", "0":
return check.OK, nil
case "WARNING", "1":
return check.Warning, nil
case "CRITICAL", "2":
return check.Critical, nil
case "UNKNOWN", "3":
return check.Unknown, nil
default:
return check.Unknown, errors.New("invalid state")
}
}
For example when providing a state via a CLI flag.
See:
- https://github.com/NETWAYS/check_elasticsearch/blob/main/cmd/snapshot.go
- https://github.com/NETWAYS/check_prometheus/pull/66/files
Should we maybe provide this in the go-check lib?
Metadata
Metadata
Assignees
Labels
No labels