Class: Diplomat::Check

Inherits:
RestClient show all
Defined in:
lib/diplomat/check.rb

Overview

Methods for interacting with the Consul check API endpoint

Instance Method Summary collapse

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(options = {})
  ret = send_get_request(@conn, ['/v1/agent/checks'], options)
  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, options = {})
  ret = send_put_request(@conn, ["/v1/agent/check/deregister/#{check_id}"], options, 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, options = {})
  update_ttl(check_id, 'critical', output, options)
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, options = {})
  update_ttl(check_id, 'passing', output, options)
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, options = {})
  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'], options, 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, options = {})
  definition = JSON.generate(
    'ID' => check_id,
    'Name' => name,
    'Notes' => notes,
    'TTL' => ttl
  )
  ret = send_put_request(@conn, ['/v1/agent/check/register'], options, 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, options = {})
  definition = JSON.generate(
    'Status' => status,
    'Output' => output
  )
  ret = send_put_request(@conn, ["/v1/agent/check/update/#{check_id}"], options, 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, options = {})
  update_ttl(check_id, 'warning', output, options)
end