Added some constants in the api for check health statuses

This commit is contained in:
Diptanu Choudhury 2016-03-24 11:26:07 -07:00
parent 77ad084229
commit 4811a72d80
2 changed files with 22 additions and 12 deletions

View File

@ -257,12 +257,12 @@ type checkUpdate struct {
// required to use this API). // required to use this API).
func (a *Agent) UpdateTTL(checkID, output, status string) error { func (a *Agent) UpdateTTL(checkID, output, status string) error {
switch status { switch status {
case "pass", "passing": case "pass", HealthPassing:
status = "passing" status = HealthPassing
case "warn", "warning": case "warn", HealthWarning:
status = "warning" status = HealthWarning
case "fail", "critical": case "fail", HealthCritical:
status = "critical" status = HealthCritical
default: default:
return fmt.Errorf("Invalid status: %s", status) return fmt.Errorf("Invalid status: %s", status)
} }

View File

@ -4,6 +4,16 @@ import (
"fmt" "fmt"
) )
const (
// HealthAny is special, and is used as a wild card,
// not as a specific state.
HealthAny = "any"
HealthUnknown = "unknown"
HealthPassing = "passing"
HealthWarning = "warning"
HealthCritical = "critical"
)
// HealthCheck is used to represent a single check // HealthCheck is used to represent a single check
type HealthCheck struct { type HealthCheck struct {
Node string Node string
@ -85,7 +95,7 @@ func (h *Health) Service(service, tag string, passingOnly bool, q *QueryOptions)
r.params.Set("tag", tag) r.params.Set("tag", tag)
} }
if passingOnly { if passingOnly {
r.params.Set("passing", "1") r.params.Set(HealthPassing, "1")
} }
rtt, resp, err := requireOK(h.c.doRequest(r)) rtt, resp, err := requireOK(h.c.doRequest(r))
if err != nil { if err != nil {
@ -108,11 +118,11 @@ func (h *Health) Service(service, tag string, passingOnly bool, q *QueryOptions)
// The wildcard "any" state can also be used for all checks. // The wildcard "any" state can also be used for all checks.
func (h *Health) State(state string, q *QueryOptions) ([]*HealthCheck, *QueryMeta, error) { func (h *Health) State(state string, q *QueryOptions) ([]*HealthCheck, *QueryMeta, error) {
switch state { switch state {
case "any": case HealthAny:
case "warning": case HealthWarning:
case "critical": case HealthCritical:
case "passing": case HealthPassing:
case "unknown": case HealthUnknown:
default: default:
return nil, nil, fmt.Errorf("Unsupported state: %v", state) return nil, nil, fmt.Errorf("Unsupported state: %v", state)
} }