class Diplomat::Check

Methods for interacting with the Consul check API endpoint

Public Instance Methods

checks() click to toggle source

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

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

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

# File lib/diplomat/check.rb, line 52
def deregister(check_id)
  ret = @conn.get "/v1/agent/check/deregister/#{check_id}"
  ret.status == 200
end
fail(check_id) click to toggle source

Warn a check @param check_id [String] the unique id of the check @return [Integer] Status code

# File lib/diplomat/check.rb, line 76
def fail(check_id)
  ret = @conn.get "/v1/agent/check/fail/#{check_id}"
  ret.status == 200
end
pass(check_id) click to toggle source

Pass a check @param check_id [String] the unique id of the check @return [Integer] Status code

# File lib/diplomat/check.rb, line 60
def pass(check_id)
  ret = @conn.get "/v1/agent/check/pass/#{check_id}"
  ret.status == 200
end
register_script(check_id, name, notes, script, interval) 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 script [String] command to be run for check @param interval [String] frequency (with units) of the check execution @param ttl [String] time (with units) to mark a check down @return [Integer] Status code

# File lib/diplomat/check.rb, line 23
def register_script(check_id, name, notes, script, interval)
  ret = @conn.put do |req|
    req.url '/v1/agent/check/register'
    req.body = JSON.generate(
      'ID' => check_id, 'Name' => name, 'Notes' => notes, 'Script' => script, 'Interval' => interval
    )
  end
  ret.status == 200
end
register_ttl(check_id, name, notes, ttl) 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 @return [Boolean] Success

# File lib/diplomat/check.rb, line 39
def register_ttl(check_id, name, notes, ttl)
  ret = @conn.put do |req|
    req.url '/v1/agent/check/register'
    req.body = JSON.generate(
      'ID' => check_id, 'Name' => name, 'Notes' => notes, 'TTL' => ttl
    )
  end
  ret.status == 200
end
warn(check_id) click to toggle source

Warn a check @param check_id [String] the unique id of the check @return [Integer] Status code

# File lib/diplomat/check.rb, line 68
def warn(check_id)
  ret = @conn.get "/v1/agent/check/warn/#{check_id}"
  ret.status == 200
end