diff --git a/elb/elb.go b/elb/elb.go index 61a515d9..75761447 100644 --- a/elb/elb.go +++ b/elb/elb.go @@ -302,6 +302,48 @@ func (elb *ELB) DeregisterInstancesFromLoadBalancer(options *DeregisterInstances return } +// ---------------------------------------------------------------------------- +// Health Checks + +type HealthCheck struct { + HealthyThreshold int64 + UnhealthyThreshold int64 + Interval int64 + Target string + Timeout int64 +} + +type ConfigureHealthCheck struct { + LoadBalancerName string + Check HealthCheck +} + +type ConfigureHealthCheckResp struct { + Check HealthCheck `xml:"ConfigureHealthCheckResult>HealthCheck"` + RequestId string `xml:"ResponseMetadata>RequestId"` +} + +func (elb *ELB) ConfigureHealthCheck(options *ConfigureHealthCheck) (resp *ConfigureHealthCheckResp, err error) { + params := makeParams("ConfigureHealthCheck") + + params["LoadBalancerName"] = options.LoadBalancerName + params["HealthCheck.HealthyThreshold"] = strconv.Itoa(int(options.Check.HealthyThreshold)) + params["HealthCheck.UnhealthyThreshold"] = strconv.Itoa(int(options.Check.UnhealthyThreshold)) + params["HealthCheck.Interval"] = strconv.Itoa(int(options.Check.Interval)) + params["HealthCheck.Target"] = options.Check.Target + params["HealthCheck.Timeout"] = strconv.Itoa(int(options.Check.Timeout)) + + resp = &ConfigureHealthCheckResp{} + + err = elb.query(params, resp) + + if err != nil { + resp = nil + } + + return +} + // ---------------------------------------------------------------------------- // Instance Health diff --git a/elb/elb_test.go b/elb/elb_test.go index 3043e720..eeae4bf0 100644 --- a/elb/elb_test.go +++ b/elb/elb_test.go @@ -136,6 +136,35 @@ func (s *S) TestDeregisterInstancesFromLoadBalancer(c *C) { c.Assert(resp.RequestId, Equals, "83c88b9d-12b7-11e3-8b82-87b12EXAMPLE") } +func (s *S) TestConfigureHealthCheck(c *C) { + testServer.Response(200, nil, ConfigureHealthCheckExample) + + options := elb.ConfigureHealthCheck{ + LoadBalancerName: "foobar", + Check: elb.HealthCheck{ + HealthyThreshold: 2, + UnhealthyThreshold: 2, + Interval: 30, + Target: "HTTP:80/ping", + Timeout: 3, + }, + } + + resp, err := s.elb.ConfigureHealthCheck(&options) + req := testServer.WaitRequest() + + c.Assert(req.Form["Action"], DeepEquals, []string{"ConfigureHealthCheck"}) + c.Assert(req.Form["LoadBalancerName"], DeepEquals, []string{"foobar"}) + c.Assert(err, IsNil) + + c.Assert(resp.Check.HealthyThreshold, Equals, 2) + c.Assert(resp.Check.UnhealthyThreshold, Equals, 2) + c.Assert(resp.Check.Interval, Equals, 30) + c.Assert(resp.Check.Target, Equals, "HTTP:80/ping") + c.Assert(resp.Check.Timeout, Equals, 3) + c.Assert(resp.RequestId, Equals, "83c88b9d-12b7-11e3-8b82-87b12EXAMPLE") +} + func (s *S) TestDescribeInstanceHealth(c *C) { testServer.Response(200, nil, DescribeInstanceHealthExample) diff --git a/elb/responses_test.go b/elb/responses_test.go index 6b8578dc..c9f8f15f 100644 --- a/elb/responses_test.go +++ b/elb/responses_test.go @@ -119,6 +119,23 @@ var DeregisterInstancesFromLoadBalancerExample = ` ` +// http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_ConfigureHealthCheck.html +var ConfigureHealthCheckExample = ` + + + + 30 + HTTP:80/ping + 2 + 3 + 2 + + + + 83c88b9d-12b7-11e3-8b82-87b12EXAMPLE + +` + // http://goo.gl/cGNxfj var DescribeInstanceHealthExample = `