lib/i2x/agent.rb in i2x-0.0.4 vs lib/i2x/agent.rb in i2x-0.0.5

- old
+ new

@@ -4,24 +4,22 @@ #require 'xmldetector' #require 'sqldetector' module I2X class Agent - attr_accessor :content - attr_accessor :identifier - attr_accessor :publisher - attr_accessor :payload - attr_accessor :templates + attr_accessor :content, :identifier, :publisher, :payload, :templates, :seeds, :cache, :selectors def initialize agent begin - identifier = agent[:identifier] - publisher = agent[:publisher] + @identifier = agent[:identifier] + @publisher = agent[:publisher] @payload = agent[:payload] - templates = agent[:template] + @cache = agent[:payload][:cache] + @seeds = agent[:seeds] + @selectors = agent[:payload][:selectors] rescue Exception => e - p '[i2x] unable to initialize agent. ' + e.to_str + p "[i2x] unable to initialize agent. #{e}" end end @@ -29,67 +27,66 @@ # => Perform the actual agent monitoring tasks. # def execute @checkup = {} - case publisher + case @publisher when 'sql' begin - @d = I2X::SQLDetector.new(identifier) + @d = I2X::SQLDetector.new(self) rescue Exception => e @response = {:status => 400, :error => e} - p '[i2x] error: ' + e.to_str + p "[i2x] error: #{e}" end when 'csv' begin - @d = I2X::CSVDetector.new(identifier) + @d = I2X::CSVDetector.new(self) rescue Exception => e @response = {:status => 400, :error => e} - p '[i2x] error: ' + e.to_str + p "[i2x] error: #{e}" end when 'xml' begin - @d = I2X::XMLDetector.new(identifier) + @d = I2X::XMLDetector.new(self) rescue Exception => e @response = {:status => 400, :error => e} - p '[i2x] error: ' + e.to_str + p "[i2x] error: #{e}" end when 'json' begin - @d = I2X::JSONDetector.new(identifier) + @d = I2X::JSONDetector.new(self) rescue Exception => e @response = {:status => 400, :error => e} - p '[i2x] error: ' + e.to_str + p "[i2x] error: #{e}" end end # Start checkup begin unless content.nil? then @d.content = content end - update_check_at Time.now @checkup = @d.checkup rescue Exception => e - p '[i2x] error: ' + e.to_str + p "[i2x] error: #{e}" end # Start detection begin @d.objects.each do |object| @d.detect object end rescue Exception => e - p '[i2x] error: ' + e.to_str + p "[i2x] error: #{e}" end begin if @checkup[:status] == 100 then process @checkup end rescue Exception => e - p '[i2x] error: ' + e.to_str + p "[i2x] error: #{e}" end response = {:status => @checkup[:status], :message => "[i2x][Checkup][execute] All OK."} end \ No newline at end of file