Class: Triglav::Agent::ApiClient
- Inherits:
-
Object
- Object
- Triglav::Agent::ApiClient
- Defined in:
- lib/triglav/agent/api_client.rb
Overview
This Triglav client connects to triglav API with $setting.triglav.url, and authenticates with $setting.triglav.credential, and stores the token into $setting.token_file.
Re-authenticate automatically if token is expired
require 'triglav/agent/api_client'
api_client = Triglav::Agent::ApiClient.new
resources = api_client.list_resources(uri_prefix)
resources.each do |resource|
events = get_events(resource) # implement this!
api_client.(events)
end
Defined Under Namespace
Classes: AuthenticationError, ConnectionError, Error
Instance Method Summary collapse
- #authorized? ⇒ Boolean
-
#initialize(opts = {}) ⇒ ApiClient
constructor
Initialize TriglavClient.
-
#list_aggregated_resources(uri_prefix) ⇒ Array of TriglavClient::ResourceEachResponse
List resources required to be monitored.
-
#send_messages(events) ⇒ Object
Send messages.
Constructor Details
#initialize(opts = {}) ⇒ ApiClient
Initialize TriglavClient
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/triglav/agent/api_client.rb', line 31 def initialize(opts = {}) @opts = opts || {} config = TriglavClient::Configuration.new do |config| uri = URI.parse(triglav_url) config.scheme = uri.scheme config.host = "#{uri.host}:#{uri.port}" config.timeout = timeout if timeout config.debugging = debugging if debugging end @api_client = TriglavClient::ApiClient.new(config) initialize_current_token authenticate end |
Instance Method Details
#authorized? ⇒ Boolean
66 67 68 |
# File 'lib/triglav/agent/api_client.rb', line 66 def @current_token.has_key?(:access_token) end |
#list_aggregated_resources(uri_prefix) ⇒ Array of TriglavClient::ResourceEachResponse
List resources required to be monitored
50 51 52 53 54 |
# File 'lib/triglav/agent/api_client.rb', line 50 def list_aggregated_resources(uri_prefix) $logger.debug { "ApiClient#list_aggregated_resources(#{uri_prefix.inspect})" } resources_api = TriglavClient::ResourcesApi.new(@api_client) handle_error { resources_api.list_aggregated_resources(uri_prefix) } end |
#send_messages(events) ⇒ Object
Send messages
60 61 62 63 64 |
# File 'lib/triglav/agent/api_client.rb', line 60 def (events) $logger.debug { "ApiClient#send_messages(#{events.inspect})" } = TriglavClient::MessagesApi.new(@api_client) handle_error { .(events) } end |