Class: Fluent::Plugin::GenHashValueFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_genhashvalue_alt.rb

Instance Method Summary collapse

Constructor Details

#initializeGenHashValueFilter

Returns a new instance of GenHashValueFilter.



17
18
19
20
21
# File 'lib/fluent/plugin/filter_genhashvalue_alt.rb', line 17

def initialize
  super
  require 'base64'
  require 'base91'
end

Instance Method Details

#configure(conf) ⇒ Object



23
24
25
26
27
28
29
30
31
# 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) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# 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

#shutdownObject



38
39
40
41
# File 'lib/fluent/plugin/filter_genhashvalue_alt.rb', line 38

def shutdown
  super
  # destroy
end

#startObject



33
34
35
36
# File 'lib/fluent/plugin/filter_genhashvalue_alt.rb', line 33

def start
  super
  # init
end