Class: Fluent::GenHashValueFilter

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

Instance Method Summary collapse

Constructor Details

#initializeGenHashValueFilter

Returns a new instance of GenHashValueFilter.



10
11
12
13
# File 'lib/fluent/plugin/out_genhashvalue.rb', line 10

def initialize
  super
  require 'base64'
end

Instance Method Details

#configure(conf) ⇒ Object



15
16
17
18
19
# File 'lib/fluent/plugin/out_genhashvalue.rb', line 15

def configure(conf)
  #$log.trace "configure #{conf}"
  super
  p @keys
end

#filter(tag, time, record) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/fluent/plugin/out_genhashvalue.rb', line 31

def filter(tag, time, record)
  s = keys.map {|k| record[k]}.join(separator)
  if base64_enc then
    record[set_key] = hash_b64(hash_type, s)
  else
    record[set_key] = hash_hex(hash_type, s)
  end
  record
end

#hash_b64(type, str) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fluent/plugin/out_genhashvalue.rb', line 54

def hash_b64(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
  h = Base64::strict_encode64(h)
end

#hash_hex(type, str) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fluent/plugin/out_genhashvalue.rb', line 41

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



26
27
28
29
# File 'lib/fluent/plugin/out_genhashvalue.rb', line 26

def shutdown
  super
  # destroy
end

#startObject



21
22
23
24
# File 'lib/fluent/plugin/out_genhashvalue.rb', line 21

def start
  super
  # init
end