Class: Diplomat::Check
- Inherits:
-
RestClient
- Object
- RestClient
- Diplomat::Check
- Defined in:
- lib/diplomat/check.rb
Overview
Methods for interacting with the Consul check API endpoint
Instance Method Summary collapse
-
#checks(options = {}) ⇒ OpenStruct
Get registered checks.
-
#deregister(check_id, options = {}) ⇒ Integer
Deregister a check.
-
#fail(check_id, output = nil, options = {}) ⇒ Integer
Fail a check.
-
#pass(check_id, output = nil, options = {}) ⇒ Integer
Pass a check.
-
#register_script(check_id, name, notes, args, interval, options = {}) ⇒ Integer
Register a check rubocop:disable Metrics/ParameterLists.
-
#register_ttl(check_id, name, notes, ttl, options = {}) ⇒ Boolean
Register a TTL check.
-
#update_ttl(check_id, status, output = nil, options = {}) ⇒ Integer
Update a TTL check.
-
#warn(check_id, output = nil, options = {}) ⇒ Integer
Warn a check.
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
#checks(options = {}) ⇒ OpenStruct
Get registered checks
11 12 13 14 |
# File 'lib/diplomat/check.rb', line 11 def checks( = {}) ret = send_get_request(@conn, ['/v1/agent/checks'], ) JSON.parse(ret.body) end |
#deregister(check_id, options = {}) ⇒ Integer
Deregister a check
64 65 66 67 |
# File 'lib/diplomat/check.rb', line 64 def deregister(check_id, = {}) ret = send_put_request(@conn, ["/v1/agent/check/deregister/#{check_id}"], , nil) ret.status == 200 end |
#fail(check_id, output = nil, options = {}) ⇒ Integer
Fail a check
107 108 109 |
# File 'lib/diplomat/check.rb', line 107 def fail(check_id, output = nil, = {}) update_ttl(check_id, 'critical', output, ) end |
#pass(check_id, output = nil, options = {}) ⇒ Integer
Pass a check
89 90 91 |
# File 'lib/diplomat/check.rb', line 89 def pass(check_id, output = nil, = {}) update_ttl(check_id, 'passing', output, ) end |
#register_script(check_id, name, notes, args, interval, options = {}) ⇒ Integer
Register a check rubocop:disable Metrics/ParameterLists
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/diplomat/check.rb', line 25 def register_script(check_id, name, notes, args, interval, = {}) unless args.is_a?(Array) raise(Diplomat::DeprecatedArgument, 'Script usage is deprecated, replace by an array of args') end definition = JSON.generate( 'ID' => check_id, 'Name' => name, 'Notes' => notes, 'Args' => args, 'Interval' => interval ) ret = send_put_request(@conn, ['/v1/agent/check/register'], , definition) ret.status == 200 end |
#register_ttl(check_id, name, notes, ttl, options = {}) ⇒ Boolean
Register a TTL check
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/diplomat/check.rb', line 49 def register_ttl(check_id, name, notes, ttl, = {}) definition = JSON.generate( 'ID' => check_id, 'Name' => name, 'Notes' => notes, 'TTL' => ttl ) ret = send_put_request(@conn, ['/v1/agent/check/register'], , definition) ret.status == 200 end |
#update_ttl(check_id, status, output = nil, options = {}) ⇒ Integer
Update a TTL check
75 76 77 78 79 80 81 82 |
# File 'lib/diplomat/check.rb', line 75 def update_ttl(check_id, status, output = nil, = {}) definition = JSON.generate( 'Status' => status, 'Output' => output ) ret = send_put_request(@conn, ["/v1/agent/check/update/#{check_id}"], , definition) ret.status == 200 end |
#warn(check_id, output = nil, options = {}) ⇒ Integer
Warn a check
98 99 100 |
# File 'lib/diplomat/check.rb', line 98 def warn(check_id, output = nil, = {}) update_ttl(check_id, 'warning', output, ) end |