Class: Fluent::Plugin::GenHashValueFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::Plugin::GenHashValueFilter
- Includes:
- MurmurHash3::V128
- Defined in:
- lib/fluent/plugin/filter_genhashvalue.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #filter(tag, time, record) ⇒ Object
- #hash_enc(type, str) ⇒ Object
- #hash_hex(type, str) ⇒ Object
-
#initialize ⇒ GenHashValueFilter
constructor
A new instance of GenHashValueFilter.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ GenHashValueFilter
Returns a new instance of GenHashValueFilter.
19 20 21 22 23 |
# File 'lib/fluent/plugin/filter_genhashvalue.rb', line 19 def initialize super require 'base64' require 'base91' end |
Instance Method Details
#configure(conf) ⇒ Object
25 26 27 28 |
# File 'lib/fluent/plugin/filter_genhashvalue.rb', line 25 def configure(conf) #$log.trace "configure #{conf}" super end |
#filter(tag, time, record) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fluent/plugin/filter_genhashvalue.rb', line 40 def filter(tag, time, record) s = "" s += tag + separator if inc_tag_as_key s += time.to_s + separator if inc_time_as_key s += keys.map {|k| record[k]}.join(separator) 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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fluent/plugin/filter_genhashvalue.rb', line 69 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) when 'mur128' h = MurmurHash3::V128.str_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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fluent/plugin/filter_genhashvalue.rb', line 54 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) when 'mur128' h = MurmurHash3::V128.str_hexdigest(str) end end |
#shutdown ⇒ Object
35 36 37 38 |
# File 'lib/fluent/plugin/filter_genhashvalue.rb', line 35 def shutdown super # destroy end |
#start ⇒ Object
30 31 32 33 |
# File 'lib/fluent/plugin/filter_genhashvalue.rb', line 30 def start super # init end |