fluent-plugin-genhashvalue 0.01 → 0.02

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdcaa249274d5ec5a4df17abf0a55a432de82797
4
- data.tar.gz: e50485809f439650007b750bb7f567c7cd1478e0
3
+ metadata.gz: 39b054050c539c94a3af3c8a6e0a4c9d2911aa17
4
+ data.tar.gz: 150593ad625bab83c2ed32acfa18a410d3784e7e
5
5
  SHA512:
6
- metadata.gz: 0ec5b90ea971c3d9c1c30c6bf8c7d875f7086044b5deadd8cb1aafcf4bb14e54911d7395d7739e5d30add21bbe8be1afe8d9ca046983aecbf9073b2f545f0bda
7
- data.tar.gz: 4e74579bff93e8abe2b51d079c83010d614a9d84fd369d6fdefdef3965b863264fe3c5c84b530da558051125a564c0cfb461161a3d53776b38272fac23d774bc
6
+ metadata.gz: 4308fe366ffc3dfb085565ebfd6e0d93e488c6f455283c16a49ad675c1e240f9d0fc54ed1e973097a324db90daa3eeafbca0185478c074da98ca614ae47e9396
7
+ data.tar.gz: de42f82045376c92d6710055b826ee945bcff6a889efb80bf6f8ae6641b4ea925d7de1ba8de6b35782e7c0a5d9eac4f03af1244b92f1e61f73c1915077f4beac
data/README.md CHANGED
@@ -29,7 +29,7 @@ Example:
29
29
  type genhashvalue
30
30
 
31
31
  keys type,descr
32
- hash_type md5
32
+ hash_type md5 # md5/sha1/sha256/sha512
33
33
  base64_enc true
34
34
  set_key _hash
35
35
  separator _
@@ -38,6 +38,19 @@ Example:
38
38
  </filter>
39
39
 
40
40
 
41
+ Input:
42
+
43
+ root@112133c12ee3:~/fluentd# echo '{"type":"log","descr":"description..."}' | ./bin/fluent-cat foo.test
44
+ root@112133c12ee3:~/fluentd# echo '{"type":"log","descr":"description..."}' | ./bin/fluent-cat foo.test
45
+ root@112133c12ee3:~/fluentd# echo '{"type":"log","descr":"description..."}' | ./bin/fluent-cat foo.test
46
+
47
+ Filterd:
48
+
49
+ 2016-10-23 15:06:05 +0000 foo.test: {"type":"log","descr":"description...","_hash":"/B3pc4NBk6Z9Ph89k+ZL4Q=="}
50
+ 2016-10-23 15:06:22 +0000 foo.test: {"type":"log","descr":"description...","_hash":"IgB25wc3M0QJfk0KteYygQ=="}
51
+ 2016-10-23 15:06:37 +0000 foo.test: {"type":"log","descr":"description...","_hash":"vvDF6eWyX5Sc01AVw8P6Cw=="}
52
+
53
+
41
54
  ## Development
42
55
 
43
56
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-genhashvalue"
7
- spec.version = "0.01"
7
+ spec.version = "0.02"
8
8
  spec.authors = ["m.takemi"]
9
9
  spec.email = ["m.takemi@gmail.com"]
10
10
 
@@ -15,12 +15,12 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- #if spec.respond_to?(:metadata)
19
- #spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
- #else
21
- #raise "RubyGems 2.0 or newer is required to protect against " \
22
- #"public gem pushes."
23
- #end
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ # end
24
24
 
25
25
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
26
  f.match(%r{^(test|spec|features)/})
@@ -0,0 +1,76 @@
1
+ require 'fluent/filter'
2
+
3
+ module Fluent
4
+ class GenHashValueFilter < Filter
5
+ Fluent::Plugin.register_filter('genhashvalue', self)
6
+
7
+ config_param :keys, :array
8
+ config_param :set_key, :string, :default => '_hash'
9
+ config_param :inc_time_as_key, :bool, :default => true
10
+ config_param :inc_tag_as_key, :bool, :default => true
11
+ config_param :separator, :string, :default => '_'
12
+ config_param :hash_type, :string, :default => 'sha256'
13
+ config_param :base64_enc, :bool, :default => false
14
+
15
+ def initialize
16
+ super
17
+ require 'base64'
18
+ end
19
+
20
+ def configure(conf)
21
+ #$log.trace "configure #{conf}"
22
+ super
23
+ end
24
+
25
+ def start
26
+ super
27
+ # init
28
+ end
29
+
30
+ def shutdown
31
+ super
32
+ # destroy
33
+ end
34
+
35
+ def filter(tag, time, record)
36
+ s = ""
37
+ s += tag + separator if inc_tag_as_key
38
+ s += time.to_s + separator if inc_time_as_key
39
+
40
+ s += keys.map {|k| record[k]}.join(separator)
41
+ if base64_enc then
42
+ record[set_key] = hash_b64(hash_type, s)
43
+ else
44
+ record[set_key] = hash_hex(hash_type, s)
45
+ end
46
+ record
47
+ end
48
+
49
+ def hash_hex(type, str)
50
+ case type
51
+ when 'md5'
52
+ h = Digest::MD5.hexdigest(str)
53
+ when 'sha1'
54
+ h = Digest::SHA1.hexdigest(str)
55
+ when 'sha256'
56
+ h = Digest::SHA256.hexdigest(str)
57
+ when 'sha512'
58
+ h = Digest::SHA512.hexdigest(str)
59
+ end
60
+ end
61
+
62
+ def hash_b64(type, str)
63
+ case type
64
+ when 'md5'
65
+ h = Digest::MD5.digest(str)
66
+ when 'sha1'
67
+ h = Digest::SHA1.digest(str)
68
+ when 'sha256'
69
+ h = Digest::SHA256.digest(str)
70
+ when 'sha512'
71
+ h = Digest::SHA512.digest(str)
72
+ end
73
+ h = Base64::strict_encode64(h)
74
+ end
75
+ end
76
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-genhashvalue
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.01'
4
+ version: '0.02'
5
5
  platform: ruby
6
6
  authors:
7
7
  - m.takemi
@@ -82,7 +82,7 @@ files:
82
82
  - README.md
83
83
  - Rakefile
84
84
  - fluent-plugin-genhashvalue.gemspec
85
- - lib/fluent/plugin/out_genhashvalue.rb
85
+ - lib/fluent/plugin/filter_genhashvalue.rb
86
86
  homepage: https://qos.dev7.net/~masafumi.
87
87
  licenses:
88
88
  - MIT
@@ -1,68 +0,0 @@
1
- class Fluent::GenHashValueFilter < Fluent::Plugin::Filter
2
- Fluent::Plugin.register_filter('genhashvalue', self)
3
-
4
- config_param :keys, :array
5
- config_param :set_key, :string, :default => '_hash'
6
- config_param :separator, :string, :default => '_'
7
- config_param :hash_type, :string, :default => 'sha256'
8
- config_param :base64_enc, :bool, :default => true
9
-
10
- def initialize
11
- super
12
- require 'base64'
13
- end
14
-
15
- def configure(conf)
16
- #$log.trace "configure #{conf}"
17
- super
18
- p @keys
19
- end
20
-
21
- def start
22
- super
23
- # init
24
- end
25
-
26
- def shutdown
27
- super
28
- # destroy
29
- end
30
-
31
- def filter(tag, time, record)
32
- s = keys.map {|k| record[k]}.join(separator)
33
- if base64_enc then
34
- record[set_key] = hash_b64(hash_type, s)
35
- else
36
- record[set_key] = hash_hex(hash_type, s)
37
- end
38
- record
39
- end
40
-
41
- def hash_hex(type, str)
42
- case type
43
- when 'md5'
44
- h = Digest::MD5.hexdigest(str)
45
- when 'sha1'
46
- h = Digest::SHA1.hexdigest(str)
47
- when 'sha256'
48
- h = Digest::SHA256.hexdigest(str)
49
- when 'sha512'
50
- h = Digest::SHA512.hexdigest(str)
51
- end
52
- end
53
-
54
- def hash_b64(type, str)
55
- case type
56
- when 'md5'
57
- h = Digest::MD5.digest(str)
58
- when 'sha1'
59
- h = Digest::SHA1.digest(str)
60
- when 'sha256'
61
- h = Digest::SHA256.digest(str)
62
- when 'sha512'
63
- h = Digest::SHA512.digest(str)
64
- end
65
- h = Base64::strict_encode64(h)
66
- end
67
- end
68
-