Class: ARII::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/arii/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, log) ⇒ Client

> Load configuration properties from client/script code



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/arii/client.rb', line 9

def initialize config, log
  begin
    @config = config
    ARII::Config.set_access_token config[:server][:access_token]
    ARII::Config.set_host config[:server][:host]
    ARII::Config.set_log log

    ARII::Config.log.info(self.class.name) { 'Configuration loaded successfully.' }
  rescue Exception => e
    ARII::Config.log.error(self.class.name) { "Failed to load configuration: #{e}" }
  end

end

Instance Method Details

#processObject

> Start processing agents from configuration properties.



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

def process
  ARII::Config.log.info(self.class.name) { 'Starting agent processing.' }
  begin
    @config[:agents].each do |agent|
      a = ARII::Agent.new agent
      a.execute
    end
  rescue Exception => e
    ARII::Config.log.error(self.class.name) { "Failed agent processing: #{e}" }
  end
end

#validateObject

> Validate API key.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/arii/client.rb', line 26

def validate
  begin
    ARII::Config.log.info(self.class.name) { 'Launching validation.' }

    out = RestClient::Request.execute(:method => 'post', :url => "#{ARII::Config.host}fluxcapacitor/validate_key.json", :payload => {:access_token => ARII::Config.access_token} ,:verify_ssl => OpenSSL::SSL::VERIFY_NONE )

    response = {:status => 100, :response => out.to_str}
  rescue Exception => e
    ARII::Config.log.error(self.class.name) { "Failed validation: #{e}" }
  end
  response
end