blob: 29149d8639755668886074925b810b9a6b7ddb12 [file] [log] [blame]
Jamie Hannafordd44daa82014-11-04 12:30:01 +01001package monitors
2
Jamie Hannafordc9a4d892014-11-04 14:01:56 +01003import (
4 "github.com/mitchellh/mapstructure"
5
6 "github.com/rackspace/gophercloud"
7)
Jamie Hannaford7afb7af2014-11-04 13:32:20 +01008
Jamie Hannafordd44daa82014-11-04 12:30:01 +01009// Type represents the type of Monitor.
10type Type string
11
12// Useful constants.
13const (
14 CONNECT Type = "CONNECT"
15 HTTP Type = "HTTP"
16 HTTPS Type = "HTTPS"
17)
18
Jamie Hannafordc9a4d892014-11-04 14:01:56 +010019// Monitor represents a health monitor API resource. A monitor comes in three
20// forms: CONNECT, HTTP or HTTPS.
21//
22// A CONNECT monitor establishes a basic connection to each node on its defined
23// port to ensure that the service is listening properly. The connect monitor
24// is the most basic type of health check and does no post-processing or
25// protocol specific health checks.
26//
27// HTTP and HTTPS health monitors are generally considered more intelligent and
28// powerful than CONNECT. It is capable of processing a HTTP or HTTPS response
29// to determine the condition of a node. It supports the same basic properties
30// as CONNECT and includes additional attributes that are used to evaluate the
31// HTTP response.
32type Monitor struct {
Jamie Hannafordd44daa82014-11-04 12:30:01 +010033 // Number of permissible monitor failures before removing a node from
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010034 // rotation.
Jamie Hannafordd44daa82014-11-04 12:30:01 +010035 AttemptLimit int `mapstructure:"attemptsBeforeDeactivation"`
36
37 // The minimum number of seconds to wait before executing the health monitor.
Jamie Hannafordd44daa82014-11-04 12:30:01 +010038 Delay int
39
40 // Maximum number of seconds to wait for a connection to be established
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010041 // before timing out.
Jamie Hannafordd44daa82014-11-04 12:30:01 +010042 Timeout int
43
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010044 // Type of the health monitor.
Jamie Hannafordd44daa82014-11-04 12:30:01 +010045 Type Type
46
47 // A regular expression that will be used to evaluate the contents of the
48 // body of the response.
49 BodyRegex string
50
51 // The name of a host for which the health monitors will check.
52 HostHeader string
53
54 // The HTTP path that will be used in the sample request.
55 Path string
56
57 // A regular expression that will be used to evaluate the HTTP status code
58 // returned in the response.
59 StatusRegex string
60}
61
Jamie Hannaford7afb7af2014-11-04 13:32:20 +010062// UpdateResult represents the result of an Update operation.
63type UpdateResult struct {
64 gophercloud.ErrResult
65}
Jamie Hannafordc9a4d892014-11-04 14:01:56 +010066
67// GetResult represents the result of a Get operation.
68type GetResult struct {
69 gophercloud.Result
70}
71
72// Extract interprets any GetResult as a Monitor.
73func (r GetResult) Extract() (*Monitor, error) {
74 if r.Err != nil {
75 return nil, r.Err
76 }
77
78 var response struct {
79 M Monitor `mapstructure:"healthMonitor"`
80 }
81
82 err := mapstructure.Decode(r.Body, &response)
83
84 return &response.M, err
85}