From 27fe823fd2f0ec26ea3409b60c6f604839d16f68 Mon Sep 17 00:00:00 2001 From: Nicholas Capo Date: Mon, 12 Jan 2015 22:35:28 +0000 Subject: [PATCH] command/agent: HTTP Check: Include response in check status --- command/agent/check.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/command/agent/check.go b/command/agent/check.go index 2750ee909..c1bb7a351 100644 --- a/command/agent/check.go +++ b/command/agent/check.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/armon/circbuf" "github.com/hashicorp/consul/consul/structs" + "io/ioutil" "log" "net/http" "os/exec" @@ -319,12 +320,17 @@ func (c *CheckHTTP) check() { c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, err.Error()) return } - resp.Body.Close() + defer resp.Body.Close() 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) + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + c.Logger.Printf("[WARN] check '%v': Get error while reading body: %s", c.CheckID, err) + body = []byte{} + } + result := fmt.Sprintf("HTTP GET %s: %s Output: %s", c.HTTP, resp.Status, body) + c.Logger.Printf("[DEBUG] agent: http check '%v' is passing: %s", c.CheckID, result) c.Notify.UpdateCheck(c.CheckID, structs.HealthPassing, result) } else if resp.StatusCode == 429 {