fluent-plugin-reassemble 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjZiMWJhZjY4YWEyZTI0ZWY3ODc5OTQ2ZDg5Njk4YzMyNjk1MzFiNg==
4
+ MmM2MjgwYTFjM2U5ZWU1OGU1MmFiMTYyNzExY2UzYjA5MGRkZTBlOA==
5
5
  data.tar.gz: !binary |-
6
- MGQ0ZTFkZjNiNGYyNzkzMmI4MjU0Y2YyN2U0YjNiZmRjNWU2MjJhMQ==
6
+ MmI5ODI1MmE5MmI0ZWMwMzI4ZDNkNTdjNWFjMGJiYmUzOGM4NDY1NQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OTJmYmM0ZTIwZmYxNTg4NGJmMmQxOGRiNjBkZjkxNjNlMjU4ODhhNmJiZjRl
10
- MjFkM2YxMmM5NTI0ODllZGMyMmM4ZWI2MzMxYjYyY2ZkYzc5NmZhZmUyYjNl
11
- MWQyY2RmODAxNGY4MzdjODc2MWRmYzlmYjc1MDAzYzVkZTEyMDg=
9
+ ZDUyMjRhZDdlZDlmZDZkZTMxZDlkZGY0NDk0ZGQ0YjExY2ZiNWU4YzcxM2Nl
10
+ N2Y5NDVkM2QyMGYzMzE0ZTJmYzkxZDY4OGMxNDZkM2RhOWRlODYxYmZiNzA0
11
+ ODYwODhjMjJlOTkyYjY2YjZkMGEyZGEwMjE2YzIwNTkxMmJkZmM=
12
12
  data.tar.gz: !binary |-
13
- ODQ0NzE0YzA2N2IzZDFlMjZmZDYzNTg5MWUyYmIwYzRmNzZjNWZiNDI5MDRh
14
- MmE2YmVjYzE0MGI5YzFmMTExYjFmY2JiYzE4MTg5ODZhMTQzNTdlYzE1OGVh
15
- YzUxZjhlMmZiNGU4ZjI0NjA3OGM0OGIxY2Q5MDUxMDE1NmIxZjU=
13
+ NTkyYTQ4OGZmZWE1YmFkNDk5YmEwNDRiZTAzMWQ5NmQxMTBlNGMwNDc2ZDU3
14
+ ZGU3M2E2MmEyN2VjZDc5NzlmMjE0ODA2YjNjYzdkM2MwMTZhNzA2MmI2NDcx
15
+ NDQyOTk3ZDE3ZjFkZjI3ZWE0ZjdlNGE4MjUyYzljZDk5MDM0MWI=
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-plugin-reassemble"
4
- gem.version = "0.0.5"
4
+ gem.version = "0.0.6"
5
5
  gem.authors = ["moaikids"]
6
6
  gem.licenses = ["Apache License Version 2.0"]
7
7
  gem.summary = %q{Re-assemble a stream data for Fluentd}
@@ -6,6 +6,9 @@ module Fluent
6
6
  Fluent::Plugin.register_output('reassemble', self)
7
7
  config_param :output_tag, :string, :default => nil
8
8
  config_param :assemble, :string, :default => nil
9
+ config_param :expand_extract_key, :string, :default => nil
10
+ config_param :expand_replaced_key, :string, :default => nil
11
+ config_param :expand_operation, :string, :default => nil
9
12
  config_param :null_to_null, :bool, :default => false
10
13
  config_param :null_to_empty, :bool, :default => false
11
14
  config_param :datetime_format, :string, :default => '%Y/%m/%d %H:%M:%S'
@@ -50,24 +53,52 @@ module Fluent
50
53
  def emit(tag, es, chain)
51
54
  chain.next
52
55
  es.each {|time,record|
53
- json = {}
54
- @reassemble_conf.each { |conf|
55
- extract_key = conf[:extract]
56
- replaced_key = conf[:replace]
57
- operation = conf[:operation]
58
- val = convert(traverse(record, extract_key), operation)
59
- if !(val.nil?)
60
- json[replaced_key] = val
61
- elsif @null_to_null
62
- json[replaced_key] = nil
63
- elsif @null_to_empty
64
- json[replaced_key] = ""
56
+ if @expand_extract_key.nil?
57
+ json = reassemble(record)
58
+ Fluent::Engine.emit(@output_tag, time, json)
59
+ else
60
+ replaced_key = @expand_replaced_key
61
+ if @expand_replaced_key.nil? || @expand_replaced_key.empty?
62
+ replaced_key = @expand_extract_key
63
+ end
64
+ operation = @expand_operation
65
+ traversed = traverse(record, @expand_extract_key)
66
+ if traversed
67
+ traversed.each { |r|
68
+ json = reassemble(record)
69
+ val = convert(r, operation)
70
+ if !(val.nil?)
71
+ json[replaced_key] = val
72
+ elsif @null_to_null
73
+ json[replaced_key] = nil
74
+ elsif @null_to_empty
75
+ json[replaced_key] = ""
76
+ end
77
+ Fluent::Engine.emit(@output_tag, time, json)
78
+ }
65
79
  end
66
- }
67
- Fluent::Engine.emit(@output_tag, time, json)
80
+ end
68
81
  }
69
82
  end
70
83
 
84
+ def reassemble(record)
85
+ json = {}
86
+ @reassemble_conf.each { |conf|
87
+ extract_key = conf[:extract]
88
+ replaced_key = conf[:replace]
89
+ operation = conf[:operation]
90
+ val = convert(traverse(record, extract_key), operation)
91
+ if !(val.nil?)
92
+ json[replaced_key] = val
93
+ elsif @null_to_null
94
+ json[replaced_key] = nil
95
+ elsif @null_to_empty
96
+ json[replaced_key] = ""
97
+ end
98
+ }
99
+ return json
100
+ end
101
+
71
102
  def traverse(data, key)
72
103
  val = data
73
104
  key.split('.').each{ |k|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-reassemble
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - moaikids
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-13 00:00:00.000000000 Z
11
+ date: 2013-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake