Class: ARII::Agent
- Inherits:
-
Object
- Object
- ARII::Agent
- Defined in:
- lib/arii/agent.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#content ⇒ Object
Returns the value of attribute content.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#seeds ⇒ Object
Returns the value of attribute seeds.
-
#selectors ⇒ Object
Returns the value of attribute selectors.
-
#templates ⇒ Object
Returns the value of attribute templates.
Instance Method Summary collapse
-
#execute ⇒ Object
> Perform the actual agent monitoring tasks.
-
#initialize(agent) ⇒ Agent
constructor
A new instance of Agent.
-
#process(checkup) ⇒ Object
> Process agent checks.
Constructor Details
#initialize(agent) ⇒ Agent
Returns a new instance of Agent.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/arii/agent.rb', line 7 def initialize agent begin @identifier = agent[:identifier] @publisher = agent[:publisher] @payload = agent[:payload] @cache = agent[:payload][:cache] @seeds = agent[:seeds] @selectors = agent[:payload][:selectors] ARII::Config.log.debug(self.class.name) { "Agent #{@identifier} initialized" } rescue Exception => e ARII::Config.log.error(self.class.name) { "Unable to initialize agent. #{e}" } end end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
5 6 7 |
# File 'lib/arii/agent.rb', line 5 def cache @cache end |
#content ⇒ Object
Returns the value of attribute content.
5 6 7 |
# File 'lib/arii/agent.rb', line 5 def content @content end |
#identifier ⇒ Object
Returns the value of attribute identifier.
5 6 7 |
# File 'lib/arii/agent.rb', line 5 def identifier @identifier end |
#payload ⇒ Object
Returns the value of attribute payload.
5 6 7 |
# File 'lib/arii/agent.rb', line 5 def payload @payload end |
#publisher ⇒ Object
Returns the value of attribute publisher.
5 6 7 |
# File 'lib/arii/agent.rb', line 5 def publisher @publisher end |
#seeds ⇒ Object
Returns the value of attribute seeds.
5 6 7 |
# File 'lib/arii/agent.rb', line 5 def seeds @seeds end |
#selectors ⇒ Object
Returns the value of attribute selectors.
5 6 7 |
# File 'lib/arii/agent.rb', line 5 def selectors @selectors end |
#templates ⇒ Object
Returns the value of attribute templates.
5 6 7 |
# File 'lib/arii/agent.rb', line 5 def templates @templates end |
Instance Method Details
#execute ⇒ Object
> Perform the actual agent monitoring tasks.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/arii/agent.rb', line 26 def execute @checkup = {} case @publisher when 'sql' begin @d = ARII::SQLDetector.new(self) rescue Exception => e @response = {:status => 400, :error => e} ARII::Config.log.error(self.class.name) { "#{e}" } end when 'csv' begin @d = ARII::CSVDetector.new(self) rescue Exception => e @response = {:status => 400, :error => e} ARII::Config.log.error(self.class.name) { "#{e}" } end when 'excel' begin @d = ARII::ExcelDetector.new(self) rescue Exception => e @response = {:status => 400, :error => e} ARII::Config.log.error(self.class.name) { "#{e}" } end when 'xml' begin @d = ARII::XMLDetector.new(self) rescue Exception => e @response = {:status => 400, :error => e} ARII::Config.log.error(self.class.name) { "#{e}" } end when 'json' begin @d = ARII::JSONDetector.new(self) rescue Exception => e @response = {:status => 400, :error => e} ARII::Config.log.error(self.class.name) { "#{e}" } end end # Start checkup begin unless content.nil? then @d.content = content end @checkup = @d.checkup rescue Exception => e ARII::Config.log.error(self.class.name) { "Checkup error: #{e}" } end # Start detection begin @d.objects.each do |object| @d.detect object end @checkup[:templates] = @d.templates.uniq rescue Exception => e ARII::Config.log.error(self.class.name) { "Detection error: #{e}\n\t#{e.backtrace}" } end begin if @checkup[:status] == 100 then process @checkup end rescue Exception => e ARII::Config.log.error(self.class.name) { "Process error: #{e}" } end response = {:status => @checkup[:status], :message => "[ARII][Checkup][execute] All OK."} end |
#process(checkup) ⇒ Object
> Process agent checks.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/arii/agent.rb', line 103 def process checkup begin checkup[:templates].each do |template| ARII::Config.log.info(self.class.name) { "Delivering to #{template} template." } checkup[:payload].each do |payload| ARII::Config.log.debug(self.class.name) { "Processing #{payload}." } response = RestClient::Request.execute(:method => 'post', :url => "#{ARII::Config.host}postman/deliver/#{template}.js", :payload => payload ,:verify_ssl => OpenSSL::SSL::VERIFY_NONE ) case response.code when 200 ARII::Config.log.debug(self.class.name) { "Delivered to #{template}." } else ARII::Config.log.warn(self.class.name) { "unable to deliver \"#{payload}\" to \"#{template}\"" } end end end rescue Exception => e ARII::Config.log.error(self.class.name) { "Processing error: #{e}" } end end |