#require 'detector' #require 'csvdetector' #require 'jsondetector' #require 'xmldetector' #require 'sqldetector' module I2X class Agent attr_accessor :content attr_accessor :identifier attr_accessor :publisher attr_accessor :payload attr_accessor :templates def initialize agent begin identifier = agent[:identifier] publisher = agent[:publisher] @payload = agent[:payload] templates = agent[:template] rescue Exception => e p '[i2x] unable to initialize agent. ' + e.to_str end end ## # => Perform the actual agent monitoring tasks. # def execute @checkup = {} case publisher when 'sql' begin @d = I2X::SQLDetector.new(identifier) rescue Exception => e @response = {:status => 400, :error => e} p '[i2x] error: ' + e.to_str end when 'csv' begin @d = I2X::CSVDetector.new(identifier) rescue Exception => e @response = {:status => 400, :error => e} p '[i2x] error: ' + e.to_str end when 'xml' begin @d = I2X::XMLDetector.new(identifier) rescue Exception => e @response = {:status => 400, :error => e} p '[i2x] error: ' + e.to_str end when 'json' begin @d = I2X::JSONDetector.new(identifier) rescue Exception => e @response = {:status => 400, :error => e} p '[i2x] error: ' + e.to_str 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 end # Start detection begin @d.objects.each do |object| @d.detect object end rescue Exception => e p '[i2x] error: ' + e.to_str end begin if @checkup[:status] == 100 then process @checkup end rescue Exception => e p '[i2x] error: ' + e.to_str end response = {:status => @checkup[:status], :message => "[i2x][Checkup][execute] All OK."} end ## # => Process agent checks. # def process checkup p checkup end end end