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, #initialize, method_missing, respond_to?, respond_to_missing?, #use_named_parameter

Constructor Details

This class inherits a constructor from Diplomat::RestClient

Instance Method Details

#checksOpenStruct

Get registered checks

Returns:

  • (OpenStruct)

    all data associated with the service



9
10
11
12
# File 'lib/diplomat/check.rb', line 9

def checks
  ret = @conn.get '/v1/agent/checks'
  JSON.parse(ret.body)
end

#deregister(check_id) ⇒ Integer

Deregister a check

Parameters:

  • check_id (String)

    the unique id of the check

Returns:

  • (Integer)

    Status code



52
53
54
55
# 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) ⇒ Integer

Warn a check

Parameters:

  • check_id (String)

    the unique id of the check

Returns:

  • (Integer)

    Status code



76
77
78
79
# 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) ⇒ Integer

Pass a check

Parameters:

  • check_id (String)

    the unique id of the check

Returns:

  • (Integer)

    Status code



60
61
62
63
# 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) ⇒ Integer

Register a check

Parameters:

  • check_id (String)

    the unique id of the check

  • name (String)

    the name

  • notes (String)

    notes about the check

  • script (String)

    command to be run for check

  • interval (String)

    frequency (with units) of the check execution

  • ttl (String)

    time (with units) to mark a check down

Returns:

  • (Integer)

    Status code



23
24
25
26
27
28
29
30
31
# 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) ⇒ Boolean

Register a TTL check

Parameters:

  • check_id (String)

    the unique id of the check

  • name (String)

    the name

  • notes (String)

    notes about the check

  • ttl (String)

    time (with units) to mark a check down

Returns:

  • (Boolean)

    Success



39
40
41
42
43
44
45
46
47
# 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) ⇒ Integer

Warn a check

Parameters:

  • check_id (String)

    the unique id of the check

Returns:

  • (Integer)

    Status code



68
69
70
71
# File 'lib/diplomat/check.rb', line 68

def warn(check_id)
  ret = @conn.get "/v1/agent/check/warn/#{check_id}"
  ret.status == 200
end