Set the User Agent for HTTP health checks

This commit is contained in:
Anton Lindström 2015-05-18 19:12:10 +02:00
parent 9417fd3768
commit ce93fdd76b
1 changed files with 14 additions and 1 deletions

View File

@ -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())