Class: Diplomat::Health
- Inherits:
-
RestClient
- Object
- RestClient
- Diplomat::Health
- Defined in:
- lib/diplomat/health.rb
Overview
Methods for interacting with the Consul health API endpoint
Instance Method Summary collapse
-
#any(options = {}) ⇒ OpenStruct
Convenience method to get services in any state.
-
#checks(s, options = {}) ⇒ OpenStruct
Get service checks.
-
#critical(options = {}) ⇒ OpenStruct
Convenience method to get services in critical state.
-
#node(n, options = {}) ⇒ OpenStruct
Get node health.
-
#passing(options = {}) ⇒ OpenStruct
Convenience method to get services in passing state.
-
#service(s, options = {}, meta = nil) ⇒ OpenStruct
Get service health rubocop:disable Metrics/PerceivedComplexity.
-
#state(s, options = {}) ⇒ OpenStruct
Get service health.
-
#warning(options = {}) ⇒ OpenStruct
Convenience method to get services in warning state.
Methods inherited from RestClient
access_method?, #concat_url, #configuration, #initialize, method_missing, respond_to?, respond_to_missing?, #use_named_parameter
Constructor Details
This class inherits a constructor from Diplomat::RestClient
Instance Method Details
#any(options = {}) ⇒ OpenStruct
Convenience method to get services in any state
80 81 82 |
# File 'lib/diplomat/health.rb', line 80 def any( = {}) state('any', ) end |
#checks(s, options = {}) ⇒ OpenStruct
Get service checks
26 27 28 29 30 31 32 33 |
# File 'lib/diplomat/health.rb', line 26 def checks(s, = {}) custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] custom_params << use_named_parameter('filter', [:filter]) if [:filter] ret = send_get_request(@conn, ["/v1/health/checks/#{s}"], , custom_params) JSON.parse(ret.body).map { |check| OpenStruct.new check } end |
#critical(options = {}) ⇒ OpenStruct
Convenience method to get services in critical state
101 102 103 |
# File 'lib/diplomat/health.rb', line 101 def critical( = {}) state('critical', ) end |
#node(n, options = {}) ⇒ OpenStruct
Get node health
13 14 15 16 17 18 19 20 |
# File 'lib/diplomat/health.rb', line 13 def node(n, = {}) custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] custom_params << use_named_parameter('filter', [:filter]) if [:filter] ret = send_get_request(@conn, ["/v1/health/node/#{n}"], , custom_params) JSON.parse(ret.body).map { |node| OpenStruct.new node } end |
#passing(options = {}) ⇒ OpenStruct
Convenience method to get services in passing state
87 88 89 |
# File 'lib/diplomat/health.rb', line 87 def passing( = {}) state('passing', ) end |
#service(s, options = {}, meta = nil) ⇒ OpenStruct
Get service health rubocop:disable Metrics/PerceivedComplexity
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/diplomat/health.rb', line 41 def service(s, = {}, = nil) custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] custom_params << ['passing'] if [:passing] custom_params += [*[:tag]].map { |value| use_named_parameter('tag', value) } if [:tag] custom_params << use_named_parameter('near', [:near]) if [:near] custom_params << use_named_parameter('node-meta', [:node_meta]) if [:node_meta] custom_params << use_named_parameter('index', [:index]) if [:index] custom_params << use_named_parameter('filter', [:filter]) if [:filter] ret = send_get_request(@conn, ["/v1/health/service/#{s}"], , custom_params) if && ret.headers [:index] = ret.headers['x-consul-index'] if ret.headers['x-consul-index'] [:knownleader] = ret.headers['x-consul-knownleader'] if ret.headers['x-consul-knownleader'] [:lastcontact] = ret.headers['x-consul-lastcontact'] if ret.headers['x-consul-lastcontact'] end JSON.parse(ret.body).map { |service| OpenStruct.new service } end |
#state(s, options = {}) ⇒ OpenStruct
Get service health
67 68 69 70 71 72 73 74 75 |
# File 'lib/diplomat/health.rb', line 67 def state(s, = {}) custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] custom_params << use_named_parameter('near', [:near]) if [:near] custom_params << use_named_parameter('filter', [:filter]) if [:filter] ret = send_get_request(@conn, ["/v1/health/state/#{s}"], , custom_params) JSON.parse(ret.body).map { |status| OpenStruct.new status } end |
#warning(options = {}) ⇒ OpenStruct
Convenience method to get services in warning state
94 95 96 |
# File 'lib/diplomat/health.rb', line 94 def warning( = {}) state('warning', ) end |