From 6a2d763d5cbc340b18a3c836a9ae00d78956631a Mon Sep 17 00:00:00 2001 From: Nicholas Capo Date: Mon, 12 Jan 2015 21:58:57 +0000 Subject: [PATCH] command/agent: HTTP check: Any 2xx is OK, 429 is WARNING --- command/agent/check.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/command/agent/check.go b/command/agent/check.go index 2a383ae16d..2750ee9092 100644 --- a/command/agent/check.go +++ b/command/agent/check.go @@ -321,25 +321,21 @@ func (c *CheckHTTP) check() { } resp.Body.Close() - switch resp.StatusCode { - - // PASSING - case http.StatusOK: + if resp.StatusCode >= 200 && resp.StatusCode <= 299 { + // PASSING (2xx) c.Logger.Printf("[DEBUG] http check '%v' is passing", c.CheckID) result := fmt.Sprintf("%s from %s", resp.Status, c.HTTP) c.Notify.UpdateCheck(c.CheckID, structs.HealthPassing, result) - // WARNING - // 503 Service Unavailable - // The server is currently unable to handle the request due to - // a temporary overloading or maintenance of the server. - // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html - case http.StatusServiceUnavailable: + } else if resp.StatusCode == 429 { + // WARNING + // 429 Too Many Requests (RFC 6585) + // The user has sent too many requests in a given amount of time. c.Logger.Printf("[WARN] check '%v' is now warning", c.CheckID) c.Notify.UpdateCheck(c.CheckID, structs.HealthWarning, resp.Status) - // CRITICAL - default: + } else { + // CRITICAL c.Logger.Printf("[WARN] check '%v' is now critical", c.CheckID) c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, resp.Status) }