class Diplomat::Health

Methods for interacting with the Consul health API endpoint

Public Instance Methods

any() click to toggle source

Convenience method to get services in any state

# File lib/diplomat/health.rb, line 62
def any
  state('any')
end
checks(s, options = {}) click to toggle source

Get service checks @param s [String] the service @param options [Hash] :dc string for dc specific query @return [OpenStruct] all data associated with the node

# File lib/diplomat/health.rb, line 23
def checks(s, options = {})
  custom_params = []
  custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]

  ret = send_get_request(@conn, ["/v1/health/checks/#{s}"], options, custom_params)
  JSON.parse(ret.body).map { |check| OpenStruct.new check }
end
critical() click to toggle source

Convenience method to get services in critical state

# File lib/diplomat/health.rb, line 77
def critical
  state('critical')
end
node(n, options = {}) click to toggle source

Get node health @param n [String] the node @param options [Hash] :dc string for dc specific query @return [OpenStruct] all data associated with the node

# File lib/diplomat/health.rb, line 11
def node(n, options = {})
  custom_params = []
  custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]

  ret = send_get_request(@conn, ["/v1/health/node/#{n}"], options, custom_params)
  JSON.parse(ret.body).map { |node| OpenStruct.new node }
end
passing() click to toggle source

Convenience method to get services in passing state

# File lib/diplomat/health.rb, line 67
def passing
  state('passing')
end
service(s, options = {}) click to toggle source

Get service health @param s [String] the service @param options [Hash] options parameter hash @return [OpenStruct] all data associated with the node rubocop:disable PerceivedComplexity

# File lib/diplomat/health.rb, line 36
def service(s, options = {})
  custom_params = []
  custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
  custom_params << ['passing'] if options[:passing]
  custom_params << use_named_parameter('tag', options[:tag]) if options[:tag]
  custom_params << use_named_parameter('near', options[:near]) if options[:near]

  ret = send_get_request(@conn, ["/v1/health/service/#{s}"], options, custom_params)
  JSON.parse(ret.body).map { |service| OpenStruct.new service }
end
state(s, options = {}) click to toggle source

Get service health @param s [String] the state (“any”, “passing”, “warning”, or “critical”) @param options [Hash] :dc string for dc specific query @return [OpenStruct] all data associated with the node

# File lib/diplomat/health.rb, line 52
def state(s, options = {})
  custom_params = []
  custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
  custom_params << use_named_parameter('near', options[:near]) if options[:near]

  ret = send_get_request(@conn, ["/v1/health/state/#{s}"], options, custom_params)
  JSON.parse(ret.body).map { |status| OpenStruct.new status }
end
warning() click to toggle source

Convenience method to get services in warning state

# File lib/diplomat/health.rb, line 72
def warning
  state('warning')
end