diplomat 2.5.0 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d49b45dca93184126a7c0762ee8a56e878ef35c578d1e437b8831f01e3956ab
4
- data.tar.gz: e3c5bf7d7cfbf00a6b4672a88038427c22adb3f6121f6d11e67f402d65bb8bff
3
+ metadata.gz: 602c9e392d4e521d6b749aa0b9cfb46cead8e1a16547c6e62f480e12230bbde5
4
+ data.tar.gz: 67fac5cfa5529c346e3a7deb2108dda46aeda3c728b4376b347a34b9781edded
5
5
  SHA512:
6
- metadata.gz: 888579ae16fade603364f7f8aa671c172b2563fcff913d5f5361686406d0ae248e6365ee9c89532dd3127f540d4a41227c6663ad4055cf0d6868f7460b9b75d2
7
- data.tar.gz: 484da6f36e8207472912d7b107b8812f008791d83833967902b4e1b21af5cd90ad1ed4c6417c2d83dd466d6792c4b3c01a2d7a3bd035d3c41a28c2f61a0bc370
6
+ metadata.gz: e75b590b288dec5984484dca08ae682459fae2855cad9e09566b9d6f5cff151a53522b698e19542d986a8b1a6682f57f567e353f17d1c8166212d92e19f41a6c
7
+ data.tar.gz: 1d0f7b3878d1431a2e45525cd9ac74d11965a051141ef245e4fd884a8848ee8f1bf09ab356daa10914392152f5be7b10c81880ce934f0a6775a8e91e54163870
data/README.md CHANGED
@@ -331,6 +331,40 @@ Get the health status from autopilot
331
331
  Diplomat::Autopilot.get_health()
332
332
  ```
333
333
 
334
+ ### Health
335
+
336
+ Retrieve health of a node
337
+
338
+ ```ruby
339
+ Diplomat::Health.node('fooNode', :dc => 'abc')
340
+ ```
341
+
342
+ Retrieve health of a given check
343
+
344
+ ```ruby
345
+ Diplomat::Health.checks('fooCheck', :dc => 'abc')
346
+ ```
347
+
348
+ Retrieve health of a given service
349
+
350
+ ```ruby
351
+ Diplomat::Health.service('fooService', :dc => 'abc')
352
+ ```
353
+
354
+ Retrieve a list of anything that correspond to the state ("any", "passing", "warning", or "critical")
355
+ You can use filters too !
356
+
357
+ ```ruby
358
+ Diplomat::Health.state("critical", {:dc => 'abc', :filter => 'Node==foo'})
359
+ ```
360
+
361
+ You also have some convenience method (`any`, `passing`, `warning`, `critical`)
362
+ That can be filtered
363
+
364
+ ```ruby
365
+ Diplomat::Health.critical({:dc => 'abc', :filter => 'Service==foo'})
366
+ ```
367
+
334
368
  ### Maintenance mode
335
369
 
336
370
  Enable maintenance mode on a host, with optional reason and DC (requires access to local agent)
@@ -33,17 +33,25 @@ module Diplomat
33
33
  # Get service health
34
34
  # @param s [String] the service
35
35
  # @param options [Hash] options parameter hash
36
+ # @param meta [Hash] output structure containing header information about the request (index)
36
37
  # @return [OpenStruct] all data associated with the node
37
38
  # rubocop:disable Metrics/PerceivedComplexity
38
- def service(s, options = {})
39
+ def service(s, options = {}, meta = nil)
39
40
  custom_params = []
40
41
  custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
41
42
  custom_params << ['passing'] if options[:passing]
42
43
  custom_params += [*options[:tag]].map { |value| use_named_parameter('tag', value) } if options[:tag]
43
44
  custom_params << use_named_parameter('near', options[:near]) if options[:near]
44
45
  custom_params << use_named_parameter('node-meta', options[:node_meta]) if options[:node_meta]
46
+ custom_params << use_named_parameter('index', options[:index]) if options[:index]
45
47
 
46
48
  ret = send_get_request(@conn, ["/v1/health/service/#{s}"], options, custom_params)
49
+ if meta && ret.headers
50
+ meta[:index] = ret.headers['x-consul-index'] if ret.headers['x-consul-index']
51
+ meta[:knownleader] = ret.headers['x-consul-knownleader'] if ret.headers['x-consul-knownleader']
52
+ meta[:lastcontact] = ret.headers['x-consul-lastcontact'] if ret.headers['x-consul-lastcontact']
53
+ end
54
+
47
55
  JSON.parse(ret.body).map { |service| OpenStruct.new service }
48
56
  end
49
57
 
@@ -51,35 +59,44 @@ module Diplomat
51
59
 
52
60
  # Get service health
53
61
  # @param s [String] the state ("any", "passing", "warning", or "critical")
54
- # @param options [Hash] :dc string for dc specific query
62
+ # @param options [Hash] :dc, :near, :filter string for specific query
55
63
  # @return [OpenStruct] all data associated with the node
56
64
  def state(s, options = {})
57
65
  custom_params = []
58
66
  custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
59
67
  custom_params << use_named_parameter('near', options[:near]) if options[:near]
68
+ custom_params << use_named_parameter('filter', options[:filter]) if options[:filter]
60
69
 
61
70
  ret = send_get_request(@conn, ["/v1/health/state/#{s}"], options, custom_params)
62
71
  JSON.parse(ret.body).map { |status| OpenStruct.new status }
63
72
  end
64
73
 
65
74
  # Convenience method to get services in any state
66
- def any
67
- state('any')
75
+ # @param options [Hash] :dc, :near, :filter string for specific query
76
+ # @return [OpenStruct] all data associated with the node
77
+ def any(options = {})
78
+ state('any', options)
68
79
  end
69
80
 
70
81
  # Convenience method to get services in passing state
71
- def passing
72
- state('passing')
82
+ # @param options [Hash] :dc, :near, :filter string for specific query
83
+ # @return [OpenStruct] all data associated with the node
84
+ def passing(options = {})
85
+ state('passing', options)
73
86
  end
74
87
 
75
88
  # Convenience method to get services in warning state
76
- def warning
77
- state('warning')
89
+ # @param options [Hash] :dc, :near, :filter string for specific query
90
+ # @return [OpenStruct] all data associated with the node
91
+ def warning(options = {})
92
+ state('warning', options)
78
93
  end
79
94
 
80
95
  # Convenience method to get services in critical state
81
- def critical
82
- state('critical')
96
+ # @param options [Hash] :dc, :near, :filter string for specific query
97
+ # @return [OpenStruct] all data associated with the node
98
+ def critical(options = {})
99
+ state('critical', options)
83
100
  end
84
101
  end
85
102
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diplomat
4
- VERSION = '2.5.0'
4
+ VERSION = '2.6.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-02-10 00:00:00.000000000 Z
13
+ date: 2022-02-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -184,16 +184,22 @@ dependencies:
184
184
  name: faraday
185
185
  requirement: !ruby/object:Gem::Requirement
186
186
  requirements:
187
- - - "~>"
187
+ - - ">="
188
188
  - !ruby/object:Gem::Version
189
- version: '1.3'
189
+ version: '0.9'
190
+ - - "<"
191
+ - !ruby/object:Gem::Version
192
+ version: '2.0'
190
193
  type: :runtime
191
194
  prerelease: false
192
195
  version_requirements: !ruby/object:Gem::Requirement
193
196
  requirements:
194
- - - "~>"
197
+ - - ">="
195
198
  - !ruby/object:Gem::Version
196
- version: '1.3'
199
+ version: '0.9'
200
+ - - "<"
201
+ - !ruby/object:Gem::Version
202
+ version: '2.0'
197
203
  description: Diplomat is a simple wrapper for Consul
198
204
  email:
199
205
  - john@johnhamelink.com
@@ -252,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
258
  - !ruby/object:Gem::Version
253
259
  version: '0'
254
260
  requirements: []
255
- rubygems_version: 3.1.4
261
+ rubygems_version: 3.1.6
256
262
  signing_key:
257
263
  specification_version: 4
258
264
  summary: Diplomat is a simple wrapper for Consul