Sha256: a35de61c0b7a563bcd8398f5409a47c420a8af0251dce94da7d6ea4d7f9bce07

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Fluent
  class SqlFingerprintFilter < Filter
    Plugin.register_filter('sql_fingerprint', self)

    def initialize
      super
      require "open3"
    end

    config_param :fingerprint_tool_path, :string
    config_param :target_key, :string, :default => 'sql'
    config_param :added_key, :string, :default => 'fingerprint'

    def configure(conf)
      super
    end

    def start
      super
    end

    def shutdown
      super
    end

    def filter(tag, time, record)
      sql = hash_get(record, @target_key)
      if !sql.nil? && !sql.empty?
        record[@added_key] = fingerprint(sql)
      end
      record
    end

    def fingerprint(sql)
      unless sql.empty?
        o, s = Open3.capture2(@fingerprint_tool_path, :stdin_data => sql)
        if s.success?
          o.chomp!
          sql = o unless o.empty? 
        end
      end
      sql
    end

    def hash_get(hash, key)
      return hash[key.to_sym] if hash.key?(key.to_sym)
      return hash[key] if hash.key?(key)
      nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-sql_fingerprint-0.0.1 lib/fluent/plugin/filter_sql_fingerprint.rb