Method: CloudLB::HealthMonitor#update

Defined in:
lib/cloudlb/health_monitor.rb

#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