Adding get monitor
diff --git a/rackspace/lb/v1/monitors/requests.go b/rackspace/lb/v1/monitors/requests.go
index dac0cab..bf96d88 100644
--- a/rackspace/lb/v1/monitors/requests.go
+++ b/rackspace/lb/v1/monitors/requests.go
@@ -155,3 +155,15 @@
return res
}
+
+func Get(c *gophercloud.ServiceClient, id int) GetResult {
+ var res GetResult
+
+ _, res.Err = perigee.Request("GET", rootURL(c, id), perigee.Options{
+ MoreHeaders: c.AuthenticatedHeaders(),
+ Results: &res.Body,
+ OkCodes: []int{200},
+ })
+
+ return res
+}
diff --git a/rackspace/lb/v1/monitors/requests_test.go b/rackspace/lb/v1/monitors/requests_test.go
index 8c2756f..9841227 100644
--- a/rackspace/lb/v1/monitors/requests_test.go
+++ b/rackspace/lb/v1/monitors/requests_test.go
@@ -44,3 +44,22 @@
err := Update(client.ServiceClient(), lbID, opts).ExtractErr()
th.AssertNoErr(t, err)
}
+
+func TestGet(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ mockGetResponse(t, lbID)
+
+ m, err := Get(client.ServiceClient(), lbID).Extract()
+ th.AssertNoErr(t, err)
+
+ expected := &Monitor{
+ Type: CONNECT,
+ Delay: 10,
+ Timeout: 10,
+ AttemptLimit: 3,
+ }
+
+ th.AssertDeepEquals(t, expected, m)
+}
diff --git a/rackspace/lb/v1/monitors/results.go b/rackspace/lb/v1/monitors/results.go
index 666f504..29149d8 100644
--- a/rackspace/lb/v1/monitors/results.go
+++ b/rackspace/lb/v1/monitors/results.go
@@ -1,6 +1,10 @@
package monitors
-import "github.com/rackspace/gophercloud"
+import (
+ "github.com/mitchellh/mapstructure"
+
+ "github.com/rackspace/gophercloud"
+)
// Type represents the type of Monitor.
type Type string
@@ -12,32 +16,20 @@
HTTPS Type = "HTTPS"
)
-// ConnectMonitor represents a CONNECT monitor which performs a basic connection
-// to each node on its defined port to ensure that the service is listening
-// properly. The connect monitor is the most basic type of health check and
-// does no post-processing or protocol specific health checks.
-type ConnectMonitor struct {
- // Number of permissible monitor failures before removing a node from
- // rotation.
- AttemptLimit int `mapstructure:"attemptsBeforeDeactivation"`
-
- // The minimum number of seconds to wait before executing the health monitor.
- Delay int
-
- // Maximum number of seconds to wait for a connection to be established
- // before timing out.
- Timeout int
-
- // Type of the health monitor.
- Type Type
-}
-
-// HTTPMonitor represents a HTTP monitor type, which is generally considered a
-// more intelligent and powerful type than CONNECT. It is capable of processing
-// a HTTP or HTTPS response to determine the condition of a node. It supports
-// the same basic properties as CONNECT and includes additional attributes that
-// are used to evaluate the HTTP response.
-type HTTPMonitor struct {
+// Monitor represents a health monitor API resource. A monitor comes in three
+// forms: CONNECT, HTTP or HTTPS.
+//
+// A CONNECT monitor establishes a basic connection to each node on its defined
+// port to ensure that the service is listening properly. The connect monitor
+// is the most basic type of health check and does no post-processing or
+// protocol specific health checks.
+//
+// HTTP and HTTPS health monitors are generally considered more intelligent and
+// powerful than CONNECT. It is capable of processing a HTTP or HTTPS response
+// to determine the condition of a node. It supports the same basic properties
+// as CONNECT and includes additional attributes that are used to evaluate the
+// HTTP response.
+type Monitor struct {
// Number of permissible monitor failures before removing a node from
// rotation.
AttemptLimit int `mapstructure:"attemptsBeforeDeactivation"`
@@ -67,10 +59,27 @@
StatusRegex string
}
-// HTTPSMonitor the HTTPS equivalent of HTTPMonitor
-type HTTPSMonitor HTTPMonitor
-
// UpdateResult represents the result of an Update operation.
type UpdateResult struct {
gophercloud.ErrResult
}
+
+// GetResult represents the result of a Get operation.
+type GetResult struct {
+ gophercloud.Result
+}
+
+// Extract interprets any GetResult as a Monitor.
+func (r GetResult) Extract() (*Monitor, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+
+ var response struct {
+ M Monitor `mapstructure:"healthMonitor"`
+ }
+
+ err := mapstructure.Decode(r.Body, &response)
+
+ return &response.M, err
+}