class Fluent::Plugin::GenHashValueFilter

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_genhashvalue_alt.rb, line 17
def initialize
  super
  require 'base64'
  require 'base91'
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_genhashvalue_alt.rb, line 23
def configure(conf)
  #$log.trace "configure #{conf}"
  super
  if !@use_entire_record
    if @keys.empty?
      raise Fluent::ConfigError, "When using record as hash seed, users must specify `keys`."
    end
  end
end
filter(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_genhashvalue_alt.rb, line 43
def filter(tag, time, record)
  s = ""
  s += tag + separator if inc_tag_as_key
  s += time.to_s + separator if inc_time_as_key

  if @use_entire_record
    record.each {|k,v| s += "|#{k}|#{v}"}
  else
    s += keys.map {|k| record[k]}.join(separator)
  end
  
  if base64_enc || base91_enc then
    record[set_key] = hash_enc(hash_type, s)
  else
    record[set_key] = hash_hex(hash_type, s)
  end
  record
end
hash_enc(type, str) click to toggle source
# File lib/fluent/plugin/filter_genhashvalue_alt.rb, line 75
def hash_enc(type, str)
  case type
  when 'md5'
    h = Digest::MD5.digest(str)
  when 'sha1'
    h = Digest::SHA1.digest(str)
  when 'sha256'
    h = Digest::SHA256.digest(str)
  when 'sha512'
    h = Digest::SHA512.digest(str)
  end
  if base64_enc then
    h = Base64::strict_encode64(h)
  elsif base91_enc then
    h = Base91::encode(h)
  end
end
hash_hex(type, str) click to toggle source
# File lib/fluent/plugin/filter_genhashvalue_alt.rb, line 62
def hash_hex(type, str)
  case type
  when 'md5'
    h = Digest::MD5.hexdigest(str)
  when 'sha1'
    h = Digest::SHA1.hexdigest(str)
  when 'sha256'
    h = Digest::SHA256.hexdigest(str)
  when 'sha512'
    h = Digest::SHA512.hexdigest(str)
  end
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_genhashvalue_alt.rb, line 38
def shutdown
  super
  # destroy
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_genhashvalue_alt.rb, line 33
def start
  super
  # init
end