Sha256: 427fc3d63bf16c05933f2d94efebc54f5c7cda7fa28c9b7e438411ebaf9e6a9e

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

#require 'helper'
require 'mysql2'

module I2X

  ##
  # = SQLDetector
  #
  # Detec changes in SQL databases. MySQL support only.
  #
  class SQLDetector < Detector

    public
    ##
    # == Detect the changes
    #
    def detect object
      puts "Detecting SQL to #{object[:identifier]}"
      begin
        @client = Mysql2::Client.new(:host => object[:host], :username => object[:username] , :password => object[:password] , :database => object[:database])
        @client.query(@agent[:payload][:query]).each(:symbolize_keys => false) do |row|
          unless object[:cache].nil? then
            @cache = Cashier.verify row[object[:cache]], object, row, object[:seed]
          else
            @cache = Cashier.verify row["id"], object, row, object[:seed]
          end

          # The actual processing
          #
          if @cache[:status] == 100 then

            # add row data to payload from selectors (key => key, value => column name)
            payload = Hash.new
            JSON.parse(object[:selectors]).each do |selector|
              selector.each do |k,v|
                payload[k] = row[v]
              end
            end
            # add payload object to payloads list
            @payloads.push payload
          end
        end
      rescue Exception => e
        
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
i2x-0.0.6 lib/i2x/sqldetector.rb
i2x-0.0.5 lib/i2x/sqldetector.rb
i2x-0.0.4 lib/i2x/sqldetector.rb