Class: CloudLB::HealthMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudlb/health_monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(load_balancer) ⇒ HealthMonitor

Initializes a new CloudLB::ConnectionThrottle object



13
14
15
16
17
18
19
20
21
22
# File 'lib/cloudlb/health_monitor.rb', line 13

def initialize(load_balancer)
  @connection    = load_balancer.connection
  @load_balancer = load_balancer
  @lbmgmthost   = @connection.lbmgmthost
  @lbmgmtpath   = @connection.lbmgmtpath
  @lbmgmtport   = @connection.lbmgmtport
  @lbmgmtscheme = @connection.lbmgmtscheme
  populate
  return self
end

Instance Attribute Details

#attempts_before_deactivationObject

Returns the value of attribute attempts_before_deactivation.



7
8
9
# File 'lib/cloudlb/health_monitor.rb', line 7

def attempts_before_deactivation
  @attempts_before_deactivation
end

#body_regexObject

Returns the value of attribute body_regex.



10
11
12
# File 'lib/cloudlb/health_monitor.rb', line 10

def body_regex
  @body_regex
end

#delayObject

Returns the value of attribute delay.



5
6
7
# File 'lib/cloudlb/health_monitor.rb', line 5

def delay
  @delay
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/cloudlb/health_monitor.rb', line 8

def path
  @path
end

#status_regexObject

Returns the value of attribute status_regex.



9
10
11
# File 'lib/cloudlb/health_monitor.rb', line 9

def status_regex
  @status_regex
end

#timeoutObject

Returns the value of attribute timeout.



6
7
8
# File 'lib/cloudlb/health_monitor.rb', line 6

def timeout
  @timeout
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/cloudlb/health_monitor.rb', line 4

def type
  @type
end

Instance Method Details

#destroy!Object

Removes the current health monitor. Returns true if successful, exception otherwise.

>> monitor.destroy!
=> true


128
129
130
131
132
133
# File 'lib/cloudlb/health_monitor.rb', line 128

def destroy!
  response = @connection.lbreq("DELETE",@lbmgmthost,"#{@lbmgmtpath}/loadbalancers/#{CloudLB.escape(@load_balancer.id.to_s)}/healthmonitor",@lbmgmtport,@lbmgmtscheme)
  CloudLB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/)
  @enabled = false
  true
end

#enabled?Boolean

Returns true if the health monitor is defined and has data, returns false if not.

Returns:

  • (Boolean)


42
43
44
# File 'lib/cloudlb/health_monitor.rb', line 42

def enabled?
  @enabled
end

#populateObject Also known as: refresh



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cloudlb/health_monitor.rb', line 24

def populate
  response = @connection.lbreq("GET",@lbmgmthost,"#{@lbmgmtpath}/loadbalancers/#{CloudLB.escape(@load_balancer.id.to_s)}/healthmonitor",@lbmgmtport,@lbmgmtscheme)
  CloudLB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/)
  data = JSON.parse(response.body)['healthMonitor']
  @enabled = data == {} ? false : true
  return nil unless @enabled
  @type = data["type"]
  @delay = data["delay"]
  @timeout = data["timeout"]
  @attempts_before_deactivation = data["attemptsBeforeDeactivation"]
  @path = data["path"]
  @status_regex = data["statusRegex"]
  @body_regex = data["bodyRegex"]
  true
end

#update(options = {}) ⇒ Object

Updates (or creates) the health monitor with the supplied arguments

To create a health monitor for the first time, you must supply all required options. However, to modify an existing monitor, you need only supply the :type and whatever it is that you want to change.

Options include:

* :type - The type of health monitor. Can be CONNECT (simple TCP connections), HTTP, or HTTPS. The HTTP and HTTPS
          monitors require additional options. *required*
* :delay - The minimum number of seconds to wait before executing the health monitor. *required*
* :timeout - Maximum number of seconds to wait for a connection to be established before timing out. *required*
* :attempts_before_deactivation - Number of permissible monitor failures before removing a node from rotation. *required*

For HTTP and HTTPS monitors, there are additional options. You must supply the :path and either the :status_regex or :body_regex

* :path - The HTTP path that will be used in the sample request. *required*
* :status_regex - A regular expression that will be used to evaluate the HTTP status code returned in the response 
* :body_regex - A regular expression that will be used to evaluate the contents of the body of the response.


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cloudlb/health_monitor.rb', line 64

def update(options={})
  data = Hash.new
  data[:type] = options[:type].upcase if options[:type]
  data[:delay] = options[:delay] if options[:delay]
  data[:timeout] = options[:timeout] if options[:timeout]
  data['attemptsBeforeDeactivation'] = options[:attempts_before_deactivation] if options[:attempts_before_deactivation]
  data[:type].upcase! if data[:type]
  if ['HTTP','HTTPS'].include?(data[:type])
    data[:path] = options[:path] if options[:path]
    data['statusRegex'] = options[:status_regex] if options[:status_regex]
    data['bodyRegex'] = options[:body_regex] if options[:body_regex]
  end
  response = @connection.lbreq("PUT",@lbmgmthost,"#{@lbmgmtpath}/loadbalancers/#{CloudLB.escape(@load_balancer.id.to_s)}/healthmonitor",@lbmgmtport,@lbmgmtscheme,{},data.to_json)
  CloudLB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/)
  populate
  true
end