github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/elb/v3/monitors/results.go (about) 1 package monitors 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 type PoolID struct { 9 ID string `json:"id"` 10 } 11 12 // Monitor represents a load balancer health monitor. A health monitor is used 13 // to determine whether or not back-end members of the VIP's pool are usable 14 // for processing a request. A pool can have several health monitors associated 15 // with it. There are different types of health monitors supported: 16 // 17 // PING: used to ping the members using ICMP. 18 // TCP: used to connect to the members using TCP. 19 // HTTP: used to send an HTTP request to the member. 20 // HTTPS: used to send a secure HTTP request to the member. 21 // 22 // When a pool has several monitors associated with it, each member of the pool 23 // is monitored by all these monitors. If any monitor declares the member as 24 // unhealthy, then the member status is changed to INACTIVE and the member 25 // won't participate in its pool's load balancing. In other words, ALL monitors 26 // must declare the member to be healthy for it to stay ACTIVE. 27 type Monitor struct { 28 // The unique ID for the Monitor. 29 ID string `json:"id"` 30 31 // The Name of the Monitor. 32 Name string `json:"name"` 33 34 // TenantID is the owner of the Monitor. 35 TenantID string `json:"tenant_id"` 36 37 // The type of probe sent by the load balancer to verify the member state, 38 // which is PING, TCP, HTTP, or HTTPS. 39 Type string `json:"type"` 40 41 // The time, in seconds, between sending probes to members. 42 Delay int `json:"delay"` 43 44 // The maximum number of seconds for a monitor to wait for a connection to be 45 // established before it times out. This value must be less than the delay 46 // value. 47 Timeout int `json:"timeout"` 48 49 // Number of allowed connection failures before changing the status of the 50 // member to INACTIVE. A valid value is from 1 to 10. 51 MaxRetries int `json:"max_retries"` 52 53 // Number of permissible ping success before changing the member's 54 // status to ACTIVE. A valid value is from 1 to 10. 55 MaxRetriesDown int `json:"max_retries_down"` 56 57 // The HTTP method that the monitor uses for requests. 58 HTTPMethod string `json:"http_method"` 59 60 // The HTTP path of the request sent by the monitor to test the health of a 61 // member. Must be a string beginning with a forward slash (/). 62 URLPath string `json:"url_path" ` 63 64 // Domain Name. 65 DomainName string `json:"domain_name" ` 66 67 // Expected HTTP codes for a passing HTTP(S) monitor. 68 ExpectedCodes string `json:"expected_codes"` 69 70 // The administrative state of the health monitor, which is up (true) or 71 // down (false). 72 AdminStateUp bool `json:"admin_state_up"` 73 74 // The Port of the Monitor. 75 MonitorPort int `json:"monitor_port"` 76 77 // The status of the health monitor. Indicates whether the health monitor is 78 // operational. 79 Status string `json:"status"` 80 81 // List of pools that are associated with the health monitor. 82 Pools []PoolID `json:"pools"` 83 84 // The provisioning status of the monitor. 85 // This value is ACTIVE, PENDING_* or ERROR. 86 ProvisioningStatus string `json:"provisioning_status"` 87 88 // The creation time. 89 CreatedAt string `json:"created_at"` 90 91 // The updated time. 92 UpdatedAt string `json:"updated_at"` 93 } 94 95 // MonitorPage is the page returned by a pager when traversing over a 96 // collection of health monitors. 97 type MonitorPage struct { 98 pagination.LinkedPageBase 99 } 100 101 // NextPageURL is invoked when a paginated collection of monitors has reached 102 // the end of a page and the pager seeks to traverse over a new one. In order 103 // to do this, it needs to construct the next page's URL. 104 func (r MonitorPage) NextPageURL() (string, error) { 105 var s struct { 106 Links []golangsdk.Link `json:"healthmonitors_links"` 107 } 108 109 err := r.ExtractInto(&s) 110 if err != nil { 111 return "", err 112 } 113 114 return golangsdk.ExtractNextURL(s.Links) 115 } 116 117 // IsEmpty checks whether a MonitorPage struct is empty. 118 func (r MonitorPage) IsEmpty() (bool, error) { 119 is, err := ExtractMonitors(r) 120 return len(is) == 0, err 121 } 122 123 // ExtractMonitors accepts a Page struct, specifically a MonitorPage struct, 124 // and extracts the elements into a slice of Monitor structs. In other words, 125 // a generic collection is mapped into a relevant slice. 126 func ExtractMonitors(r pagination.Page) ([]Monitor, error) { 127 var s struct { 128 Monitors []Monitor `json:"healthmonitors"` 129 } 130 err := (r.(MonitorPage)).ExtractInto(&s) 131 return s.Monitors, err 132 } 133 134 type commonResult struct { 135 golangsdk.Result 136 } 137 138 // Extract is a function that accepts a result and extracts a monitor. 139 func (r commonResult) Extract() (*Monitor, error) { 140 var s struct { 141 Monitor *Monitor `json:"healthmonitor"` 142 } 143 err := r.ExtractInto(&s) 144 return s.Monitor, err 145 } 146 147 // CreateResult represents the result of a create operation. Call its Extract 148 // method to interpret it as a Monitor. 149 type CreateResult struct { 150 commonResult 151 } 152 153 // GetResult represents the result of a get operation. Call its Extract 154 // method to interpret it as a Monitor. 155 type GetResult struct { 156 commonResult 157 } 158 159 // UpdateResult represents the result of an update operation. Call its Extract 160 // method to interpret it as a Monitor. 161 type UpdateResult struct { 162 commonResult 163 } 164 165 // DeleteResult represents the result of a delete operation. Call its 166 // ExtractErr method to determine if the result succeeded or failed. 167 type DeleteResult struct { 168 golangsdk.ErrResult 169 }