class Diplomat::Check

Public Class Methods

checks() click to toggle source

@note This is sugar, see (checks)

# File lib/diplomat/check.rb, line 92
def self.checks
  Diplomat::Check.new.checks
end
deregister(*args) click to toggle source

@note This is sugar, see (deregister)

# File lib/diplomat/check.rb, line 107
def self.deregister *args
  Diplomat::Check.new.deregister *args
end
fail(*args) click to toggle source

@note This is sugar, see (fail)

# File lib/diplomat/check.rb, line 122
def self.fail *args
  Diplomat::Check.new.fail *args
end
pass(*args) click to toggle source

@note This is sugar, see (pass)

# File lib/diplomat/check.rb, line 112
def self.pass *args
  Diplomat::Check.new.pass *args
end
register_script(*args) click to toggle source

@note This is sugar, see (register_script)

# File lib/diplomat/check.rb, line 97
def self.register_script *args
  Diplomat::Check.new.register_script *args
end
register_ttl(*args) click to toggle source

@note This is sugar, see (register_ttl)

# File lib/diplomat/check.rb, line 102
def self.register_ttl *args
  Diplomat::Check.new.register_ttl *args
end
warn(*args) click to toggle source

@note This is sugar, see (warn)

# File lib/diplomat/check.rb, line 117
def self.warn *args
  Diplomat::Check.new.warn *args
end

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"
  return 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 62
def deregister check_id
  ret = @conn.get "/v1/agent/check/deregister/#{check_id}"
  return true if 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 86
def fail check_id
  ret = @conn.get "/v1/agent/check/fail/#{check_id}"
  return true if 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 70
def pass check_id
  ret = @conn.get "/v1/agent/check/pass/#{check_id}"
  return true if 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 22
def register_script check_id, name, notes, script, interval
  json = JSON.generate(
  {
    "ID" => check_id,
    "Name" => name,
    "Notes" => notes,
    "Script" => script,
    "Interval" => interval
  }
  )

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

  ret = @conn.put do |req|
    req.url "/v1/agent/check/register"
    req.body = json
  end
  
  return true if 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 78
def warn check_id
  ret = @conn.get "/v1/agent/check/warn/#{check_id}"
  return true if ret.status == 200
end