From ce93fdd76bcac6d0e154f5c6be189990f74d258b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Lindstr=C3=B6m?= Date: Mon, 18 May 2015 19:12:10 +0200 Subject: [PATCH] Set the User Agent for HTTP health checks --- command/agent/check.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/command/agent/check.go b/command/agent/check.go index 82f83f6ba4..66578db8e7 100644 --- a/command/agent/check.go +++ b/command/agent/check.go @@ -23,6 +23,10 @@ const ( // last CheckBufSize. Prevents an enormous buffer // from being captured CheckBufSize = 4 * 1024 // 4KB + + // Use this user agent when doing requests for + // HTTP health checks. + HttpUserAgent = "Consul Health Check" ) // CheckType is used to create either the CheckMonitor @@ -344,7 +348,16 @@ func (c *CheckHTTP) run() { // check is invoked periodically to perform the HTTP check func (c *CheckHTTP) check() { - resp, err := c.httpClient.Get(c.HTTP) + req, err := http.NewRequest("GET", c.HTTP, nil) + if err != nil { + c.Logger.Printf("[WARN] agent: http request failed '%s': %s", c.HTTP, err) + c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, err.Error()) + return + } + + req.Header.Set("User-Agent", HttpUserAgent) + + resp, err := c.httpClient.Do(req) if err != nil { c.Logger.Printf("[WARN] agent: http request failed '%s': %s", c.HTTP, err) c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, err.Error())