class Diplomat::Check

Methods for interacting with the Consul check API endpoint

Public Instance Methods

checks(options = {}) click to toggle source

Get registered checks @return [OpenStruct] all data associated with the service

# File lib/diplomat/check.rb, line 9
def checks(options = {})
  ret = send_get_request(@conn, ['/v1/agent/checks'], options)
  JSON.parse(ret.body)
end
deregister(check_id, options = {}) click to toggle source

Deregister a check @param check_id [String] the unique id of the check @param options [Hash] options parameter hash @return [Integer] Status code

# File lib/diplomat/check.rb, line 62
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 = {}) click to toggle source

Fail a check @param check_id [String] the unique id of the check @param output [String] human-readable message will be passed through to the check's Output field @param options [Hash] options parameter hash @return [Integer] Status code

# File lib/diplomat/check.rb, line 105
def fail(check_id, output = nil, options = {})
  update_ttl(check_id, 'critical', output, options)
end
pass(check_id, output = nil, options = {}) click to toggle source

Pass a check @param check_id [String] the unique id of the check @param output [String] human-readable message will be passed through to the check's Output field @param options [Hash] options parameter hash @return [Integer] Status code

# File lib/diplomat/check.rb, line 87
def pass(check_id, output = nil, options = {})
  update_ttl(check_id, 'passing', output, options)
end
register_script(check_id, name, notes, args, interval, options = {}) click to toggle source

Register a check @param check_id [String] the unique id of the check @param name [String] the name @param notes [String] notes about the check @param args [String command to be run for check @param interval [String] frequency (with units) of the check execution @param options [Hash] options parameter hash @return [Integer] Status code rubocop:disable ParameterLists

# File lib/diplomat/check.rb, line 23
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 = {}) click to toggle source

Register a TTL check @param check_id [String] the unique id of the check @param name [String] the name @param notes [String] notes about the check @param ttl [String] time (with units) to mark a check down @param options [Hash] options parameter hash @return [Boolean] Success

# File lib/diplomat/check.rb, line 47
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 = {}) click to toggle source

Update a TTL check @param check_id [String] the unique id of the check @param status [String] status of the check. Valid values are “passing”, “warning”, and “critical” @param output [String] human-readable message will be passed through to the check's Output field @param options [Hash] options parameter hash @return [Integer] Status code

# File lib/diplomat/check.rb, line 73
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 = {}) click to toggle source

Warn a check @param check_id [String] the unique id of the check @param output [String] human-readable message will be passed through to the check's Output field @param options [Hash] options parameter hash @return [Integer] Status code

# File lib/diplomat/check.rb, line 96
def warn(check_id, output = nil, options = {})
  update_ttl(check_id, 'warning', output, options)
end