Class: Diplomat::Agent

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

Overview

Agent API endpoint methods

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 local agent checks

Returns:

  • (OpenStruct)

    all agent checks



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/diplomat/agent.rb', line 27

def checks
  url = ['/v1/agent/checks']

  # If the request fails, it's probably due to a bad path
  # so return a PathNotFound error.
  begin
    ret = @conn.get concat_url url
  rescue Faraday::ClientError
    raise Diplomat::PathNotFound
  end
  JSON.parse(ret.body).tap { |node| OpenStruct.new node }
end

#membersOpenStruct

Get cluster members (as seen by the agent)

Returns:

  • (OpenStruct)

    all members



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/diplomat/agent.rb', line 57

def members
  url = ['/v1/agent/members']

  # If the request fails, it's probably due to a bad path
  # so return a PathNotFound error.
  begin
    ret = @conn.get concat_url url
  rescue Faraday::ClientError
    raise Diplomat::PathNotFound
  end
  JSON.parse(ret.body).map { |node| OpenStruct.new node }
end

#selfOpenStruct

Get agent configuration

Returns:

  • (OpenStruct)

    all data associated with the node



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/diplomat/agent.rb', line 12

def self
  url = ['/v1/agent/self']

  # If the request fails, it's probably due to a bad path
  # so return a PathNotFound error.
  begin
    ret = @conn.get concat_url url
  rescue Faraday::ClientError
    raise Diplomat::PathNotFound
  end
  JSON.parse(ret.body).tap { |node| OpenStruct.new node }
end

#servicesOpenStruct

Get local agent services

Returns:

  • (OpenStruct)

    all agent services



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/diplomat/agent.rb', line 42

def services
  url = ['/v1/agent/services']

  # If the request fails, it's probably due to a bad path
  # so return a PathNotFound error.
  begin
    ret = @conn.get concat_url url
  rescue Faraday::ClientError
    raise Diplomat::PathNotFound
  end
  JSON.parse(ret.body).tap { |node| OpenStruct.new node }
end