blob: eec556f343c6130762349a369fc2d9f862d42668 [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
Jamie Hannaford227d9592014-11-13 10:32:07 +010025// protocol-specific health checks.
Jamie Hannafordc9a4d892014-11-04 14:01:56 +010026//
27// HTTP and HTTPS health monitors are generally considered more intelligent and
Jamie Hannaford227d9592014-11-13 10:32:07 +010028// powerful than CONNECT. It is capable of processing an HTTP or HTTPS response
Jamie Hannafordc9a4d892014-11-04 14:01:56 +010029// 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
Jamie Hannafordd7301dd2014-11-04 14:05:39 +010072// DeleteResult represents the result of an Delete operation.
73type DeleteResult struct {
74 gophercloud.ErrResult
75}
76
Jamie Hannafordc9a4d892014-11-04 14:01:56 +010077// Extract interprets any GetResult as a Monitor.
78func (r GetResult) Extract() (*Monitor, error) {
79 if r.Err != nil {
80 return nil, r.Err
81 }
82
83 var response struct {
84 M Monitor `mapstructure:"healthMonitor"`
85 }
86
87 err := mapstructure.Decode(r.Body, &response)
88
89 return &response.M, err
90}