fluent-plugin-json-nest2flat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 116db9905231f401d65f59f92619ee8e189c85cf
4
+ data.tar.gz: ef946f489f65f30e155c495acf791d537c9ccb3b
5
+ SHA512:
6
+ metadata.gz: b526ee7234f34eab9b92cdcc7a46b2ee66af6b579fe82d727dcb4fe54beb95613b6c55557df7be8fa55018cc9a5f543cc036330c83922e740bd85b16555cbc28
7
+ data.tar.gz: 5f02de95f8379300bffb267ab1ceaea7444693132df2a7287394589ad121fc5d2a9f92849f86445871a393caf45402cbb18368e7c3b1a88306d7732f71841d3b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-json-nest2flat.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Fluent::Plugin::Json::Nest2flat
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-json-nest2flat'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-json-nest2flat
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "fluent-plugin-json-nest2flat"
4
+ spec.version = "0.0.1"
5
+ spec.authors = ["FukuiRetu"]
6
+ spec.email = ["s0232101@gmail.com"]
7
+ spec.description = %q{Output filter plugin to convert to a flat structure the JSON that is nest}
8
+ spec.summary = %q{Output filter plugin to convert to a flat structure the JSON that is nest}
9
+ spec.homepage = "https://github.com/fukuiretu/fluent-plugin-json-nest2flat"
10
+ spec.license = "Apache"
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_development_dependency "bundler", "~> 1.3"
18
+ spec.add_development_dependency "rake"
19
+ end
@@ -0,0 +1,59 @@
1
+ module Fluent
2
+ class JsonNestToFlatOutput < Fluent::Output
3
+
4
+ Fluent::Plugin.register_output('json_nest2flat', self)
5
+
6
+ config_param :json_keys, :string, :default => nil
7
+
8
+ def configure(conf)
9
+ super
10
+
11
+ @json_keys = conf['json_keys']
12
+ if @json_keys.nil?
13
+ raise Fluent::ConfigError, "json_keys is undefined!"
14
+ end
15
+
16
+ @json_keys = @json_keys.split(",")
17
+ end
18
+
19
+ def emit(tag, es, chain)
20
+ es.each { |time, record|
21
+ chain.next
22
+
23
+ new_record = _convert_record(record);
24
+
25
+ Fluent::Engine.emit(tag, time, new_record)
26
+ }
27
+ end
28
+
29
+ # ネストされたJSONをフラットな構造に変換します。
30
+ # ネストされた元のJSONは削除し、フラットな構造にした値群に差し替えます。
31
+ # @param [Hash] old_record 元のレコード
32
+ # @return [Hash] ネストされたJSONをフラットな構造に変換したレコード
33
+ private
34
+ def _convert_record(old_record)
35
+ new_record = Hash.new([])
36
+ json_keys_exist_count = 0
37
+
38
+ old_record.each { |old_record_k, old_record_v|
39
+ if (@json_keys.include?(old_record_k))
40
+ json_data = old_record[old_record_k]
41
+ JSON.parse(json_data).each { |json_k, json_v|
42
+ new_record[json_k] = json_v
43
+ }
44
+
45
+ json_keys_exist_count += 1
46
+ else
47
+ new_record[old_record_k] = old_record_v
48
+ end
49
+ }
50
+
51
+ unless json_keys_exist_count > 0
52
+ $log.warn "json_keys is not found."
53
+ end
54
+
55
+ return new_record
56
+ end
57
+
58
+ end
59
+ end
File without changes
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-json-nest2flat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - FukuiRetu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Output filter plugin to convert to a flat structure the JSON that is
42
+ nest
43
+ email:
44
+ - s0232101@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - fluent-plugin-json-nest2flat.gemspec
54
+ - lib/fluent/plugin/out_json_nest2flat.rb
55
+ - test/plugin/test_out_json_nest2flat.rb
56
+ homepage: https://github.com/fukuiretu/fluent-plugin-json-nest2flat
57
+ licenses:
58
+ - Apache
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.0.3
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Output filter plugin to convert to a flat structure the JSON that is nest
80
+ test_files:
81
+ - test/plugin/test_out_json_nest2flat.rb