fluent-plugin-json-transform 0.0.1 → 0.0.2

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: a43f517c612ec4d493e30ef71454a06bd7b94712
4
- data.tar.gz: dfd9b372ecaf792ab38aa347552c694742accd39
3
+ metadata.gz: 36c342eeda778ad22180e136d3f489a8dc88f396
4
+ data.tar.gz: 0c1459d3f96f5d0c47ce96283714b3f398509667
5
5
  SHA512:
6
- metadata.gz: 6ef573459997fa3c02a3eae42aa8f5c719a59cbfad06d34f16b20373c59a15e56d94faecc175c40c8a3e7849833a6a064ff1024f015c32fcc726e60ff14a7d90
7
- data.tar.gz: bf782fb72b29e33deec557b069cc9344be42abb8ea8949f09f0656c4010756ff81ff1d28fe78b30898d3ff89d07ee9ebf8c5c84dc96c02dfccd7813f9520e30a
6
+ metadata.gz: c62858b9bad3b81f81cfa5e99919f8fa89adc2393ceb3c226827c16244b02a68e69285936a31b86458e5567d5ae7a1ccadfafed7ba1ab5368f89a79e9f1afc27
7
+ data.tar.gz: c1fa5de9c667ce0fbe34cf0ae5f655953fe31c5b12cbffae813a0de0ce7960e4b9a6ab45e072cc3441a53de57ca2b41542273679c5b18a93f705fb1c15bd2339
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- *.gem
2
- .vagrant/
3
- Vagrantfile
4
- test.sh
1
+ *.gem
2
+ .vagrant/
3
+ Vagrantfile
4
+ test.sh
data/README.md CHANGED
@@ -1,90 +1,99 @@
1
- # JSON Transform parser plugin for Fluentd
2
-
3
- ##Overview
4
- This is a [parser plugin](http://docs.fluentd.org/articles/parser-plugin-overview) for fluentd. It is **INCOMPATIBLE WITH FLUENTD v0.10.45 AND BELOW.**
5
-
6
-
7
- It was created for the purpose of modifying [**good.js**](https://github.com/hapijs/good) logs
8
- before storing them in Elasticsearch. It may not be useful for any other purpose, but be creative.
9
-
10
- ##Installation
11
- ```bash
12
- git clone https://github.com/graysonc/fluent-plugin-json-transform
13
- cd fluent-plugin-json-transform && gem build fluent-plugin-json-transform.gemspec
14
- gem install fluent-plugin-json-transform
15
- ```
16
-
17
- ##Configuration
18
- ```
19
- <source>
20
- type [tail|tcp|uydp|syslog|http] # or a custom input type which accepts the "format" parameter
21
- format json_transform
22
- transform_script [nothing|flatten|custom]
23
- script_path "/home/grayson/transform_script.rb" # ignored if transform_script != custom
24
- </source>
25
- ```
26
-
27
- `transform_script`: `nothing` to do nothing, `flatten` to flatten JSON by concatenating nested keys (see below), or `custom`
28
-
29
- `script_path`: ignored if not using `custom` script. Point this to a Ruby script which implements the `JSONTransformer` class.
30
-
31
- ###Flatten script
32
- Flattens nested JSON by concatenating nested keys with '.'. Example:
33
-
34
- ```
35
- {
36
- "hello": {
37
- "world": true
38
- },
39
- "goodbye": {
40
- "for": {
41
- "now": true,
42
- "ever": false
43
- }
44
- }
45
- }
46
- ```
47
-
48
- Becomes
49
-
50
- ```
51
- {
52
- "hello.world": true,
53
- "goodbye.for.now": true,
54
- "goodbye.for.ever": false
55
- }
56
- ```
57
-
58
- ##Implementing JSONTransformer
59
-
60
- The `JSONTransformer` class should have an instance method `transform` which takes a Ruby hash and returns a Ruby hash:
61
-
62
- ```ruby
63
- # lib/transform/flatten.rb
64
- class JSONTransformer
65
- def transform(json)
66
- return flatten(json, "")
67
- end
68
-
69
- def flatten(json, prefix)
70
- json.keys.each do |key|
71
- if prefix.empty?
72
- full_path = key
73
- else
74
- full_path = [prefix, key].join('.')
75
- end
76
-
77
- if json[key].is_a?(Hash)
78
- value = json[key]
79
- json.delete key
80
- json.merge! flatten(value, full_path)
81
- else
82
- value = json[key]
83
- json.delete key
84
- json[full_path] = value
85
- end
86
- end
87
- return json
88
- end
89
- end
90
- ```
1
+ # JSON Transform parser plugin for Fluentd
2
+
3
+ ##Overview
4
+ This is a [parser plugin](http://docs.fluentd.org/articles/parser-plugin-overview) for fluentd. It is **INCOMPATIBLE WITH FLUENTD v0.10.45 AND BELOW.**
5
+
6
+
7
+ It was created for the purpose of modifying [**good.js**](https://github.com/hapijs/good) logs
8
+ before storing them in Elasticsearch. It may not be useful for any other purpose, but be creative.
9
+
10
+ ##Installation
11
+ ```bash
12
+ gem install fluent-plugin-json-transform
13
+ ```
14
+
15
+ ##Configuration
16
+ ```
17
+ <source>
18
+ type [tail|tcp|udp|syslog|http] # or a custom input type which accepts the "format" parameter
19
+ format json_transform
20
+ transform_script [nothing|flatten|custom]
21
+ script_path "/home/grayson/transform_script.rb" # ignored if transform_script != custom
22
+ </source>
23
+ ```
24
+
25
+ `transform_script`: `nothing` to do nothing, `flatten` to flatten JSON by concatenating nested keys (see below), or `custom`
26
+
27
+ `script_path`: ignored if not using `custom` script. Point this to a Ruby script which implements the `JSONTransformer` class.
28
+
29
+ ###Flatten script
30
+ Flattens nested JSON by concatenating nested keys with '.'. Example:
31
+
32
+ ```
33
+ {
34
+ "hello": {
35
+ "world": true
36
+ },
37
+ "goodbye": {
38
+ "for": {
39
+ "now": true,
40
+ "ever": false
41
+ }
42
+ }
43
+ }
44
+ ```
45
+
46
+ Becomes
47
+
48
+ ```
49
+ {
50
+ "hello.world": true,
51
+ "goodbye.for.now": true,
52
+ "goodbye.for.ever": false
53
+ }
54
+ ```
55
+
56
+ ###New Filter Option
57
+ Filtering is now supported, if you want to flatten your json after doing other parsing from the original source log.
58
+ ```
59
+ <filter pattern>
60
+ @type json_transform
61
+ transform_script [nothing|flatten|custom]
62
+ script_path "/home/grayson/transform_script.rb" # ignored if transform_script != custom
63
+ </filter>
64
+ ```
65
+
66
+
67
+ ##Implementing JSONTransformer
68
+
69
+ The `JSONTransformer` class should have an instance method `transform` which takes a Ruby hash and returns a Ruby hash:
70
+
71
+ ```ruby
72
+ # lib/transform/flatten.rb
73
+ class JSONTransformer
74
+ def transform(json)
75
+ return flatten(json, "")
76
+ end
77
+
78
+ def flatten(json, prefix)
79
+ json.keys.each do |key|
80
+ if prefix.empty?
81
+ full_path = key
82
+ else
83
+ full_path = [prefix, key].join('.')
84
+ end
85
+
86
+ if json[key].is_a?(Hash)
87
+ value = json[key]
88
+ json.delete key
89
+ json.merge! flatten(value, full_path)
90
+ else
91
+ value = json[key]
92
+ json.delete key
93
+ json[full_path] = value
94
+ end
95
+ end
96
+ return json
97
+ end
98
+ end
99
+ ```
@@ -1,20 +1,20 @@
1
- # coding: utf-8
2
- Gem::Specification.new do |spec|
3
- spec.name = "fluent-plugin-json-transform"
4
- spec.version = "0.0.1"
5
- spec.authors = ["Grayson Chao"]
6
- spec.email = ["grayson.chao@gmail.com"]
7
- spec.description = %q{Input parser plugin which allows arbitrary transformation of input JSON}
8
- spec.summary = %q{Input parser plugin which allows arbitrary transformation of input JSON}
9
- spec.homepage = "https://github.com/graysonc/fluent-plugin-json-transform"
10
- spec.license = "MIT"
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
- spec.add_development_dependency "rspec"
20
- end
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "fluent-plugin-json-transform"
4
+ spec.version = "0.0.2"
5
+ spec.authors = ["Grayson Chao","Matthew Jourard"]
6
+ spec.email = ["grayson.chao@gmail.com","mjourard@gmail.com"]
7
+ spec.description = %q{Input parser plugin which allows arbitrary transformation of input JSON}
8
+ spec.summary = %q{Input parser plugin which allows arbitrary transformation of input JSON}
9
+ spec.homepage = "https://github.com/mjourard/fluent-plugin-json-transform/"
10
+ spec.license = "MIT"
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
+ spec.add_development_dependency "rspec"
20
+ end
@@ -0,0 +1,29 @@
1
+ module Fluent
2
+ class JSONTransformFilter < Filter
3
+ Fluent::Plugin.register_filter('json_transform', self)
4
+
5
+ DEFAULTS = [ 'nothing', 'flatten' ]
6
+
7
+ include Configurable
8
+ config_param :transform_script, :string
9
+ config_param :script_path, :string
10
+
11
+ def configure(conf)
12
+ @transform_script = conf['transform_script']
13
+
14
+ if DEFAULTS.include?(@transform_script)
15
+ @transform_script = "#{__dir__}/../../transform/#{@transform_script}.rb"
16
+ elsif @transform_script == 'custom'
17
+ @transform_script = conf['script_path']
18
+ end
19
+
20
+ require @transform_script
21
+ @transformer = JSONTransformer.new
22
+ end
23
+
24
+ def filter(tag, time, record)
25
+ flattened = @transformer.transform(record)
26
+ return flattened
27
+ end
28
+ end
29
+ end
@@ -1,32 +1,37 @@
1
- module Fluent
2
- class TextParser
3
- class JSONTransformParser
4
- DEFAULTS = [ 'nothing', 'flatten' ]
5
-
6
- include Configurable
7
- config_param :transform_script, :string
8
- config_param :script_path, :string
9
-
10
- def configure(conf)
11
- @transform_script = conf['transform_script']
12
-
13
- if DEFAULTS.include?(@transform_script)
14
- @transform_script =
15
- "#{__dir__}/../../transform/#{@transform_script}.rb"
16
- elsif @transform_script == 'custom'
17
- @transform_script = conf['script_path']
18
- end
19
-
20
- require @transform_script
21
- @transformer = JSONTransformer.new
22
- end
23
-
24
- def call(text)
25
- raw_json = JSON.parse(text)
26
- return nil, @transformer.transform(raw_json)
27
- end
28
- end
29
- register_template("json_transform", Proc.new { JSONTransformParser.new })
30
- end
31
- end
32
-
1
+ module Fluent
2
+ class TextParser
3
+ class JSONTransformParser
4
+ DEFAULTS = [ 'nothing', 'flatten' ]
5
+
6
+ include Configurable
7
+ config_param :transform_script, :string
8
+ config_param :script_path, :string
9
+
10
+ def configure(conf)
11
+ @transform_script = conf['transform_script']
12
+
13
+ if DEFAULTS.include?(@transform_script)
14
+ @transform_script =
15
+ "#{__dir__}/../../transform/#{@transform_script}.rb"
16
+ elsif @transform_script == 'custom'
17
+ @transform_script = conf['script_path']
18
+ end
19
+
20
+ require @transform_script
21
+ @transformer = JSONTransformer.new
22
+ end
23
+
24
+ def call(text)
25
+ raw_json = JSON.parse(text)
26
+ return nil, @transformer.transform(raw_json)
27
+ end
28
+
29
+ def parse(text)
30
+ raw_json = JSON.parse(text)
31
+ return nil, @transformer.transform(raw_json)
32
+ end
33
+ end
34
+ register_template("json_transform", Proc.new { JSONTransformParser.new })
35
+ end
36
+ end
37
+
@@ -1,26 +1,26 @@
1
- class JSONTransformer
2
- def transform(json)
3
- return flatten(json, "")
4
- end
5
-
6
- def flatten(json, prefix)
7
- json.keys.each do |key|
8
- if prefix.empty?
9
- full_path = key
10
- else
11
- full_path = [prefix, key].join('.')
12
- end
13
-
14
- if json[key].is_a?(Hash)
15
- value = json[key]
16
- json.delete key
17
- json.merge! flatten(value, full_path)
18
- else
19
- value = json[key]
20
- json.delete key
21
- json[full_path] = value
22
- end
23
- end
24
- return json
25
- end
26
- end
1
+ class JSONTransformer
2
+ def transform(json)
3
+ return flatten(json, "")
4
+ end
5
+
6
+ def flatten(json, prefix)
7
+ json.keys.each do |key|
8
+ if prefix.empty?
9
+ full_path = key
10
+ else
11
+ full_path = [prefix, key].join('.')
12
+ end
13
+
14
+ if json[key].is_a?(Hash)
15
+ value = json[key]
16
+ json.delete key
17
+ json.merge! flatten(value, full_path)
18
+ else
19
+ value = json[key]
20
+ json.delete key
21
+ json[full_path] = value
22
+ end
23
+ end
24
+ return json
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
- class JSONTransformer
2
- def transform(json)
3
- return json
4
- end
5
- end
1
+ class JSONTransformer
2
+ def transform(json)
3
+ return json
4
+ end
5
+ end
metadata CHANGED
@@ -1,71 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-json-transform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson Chao
8
+ - Matthew Jourard
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-09-29 00:00:00.000000000 Z
12
+ date: 2016-07-27 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - ~>
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
20
  version: '1.3'
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - ~>
25
+ - - "~>"
25
26
  - !ruby/object:Gem::Version
26
27
  version: '1.3'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - '>='
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: '0'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - '>='
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rspec
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - '>='
46
+ - - ">="
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
49
  type: :development
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - '>='
53
+ - - ">="
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
55
56
  description: Input parser plugin which allows arbitrary transformation of input JSON
56
57
  email:
57
58
  - grayson.chao@gmail.com
59
+ - mjourard@gmail.com
58
60
  executables: []
59
61
  extensions: []
60
62
  extra_rdoc_files: []
61
63
  files:
62
- - .gitignore
64
+ - ".gitignore"
63
65
  - README.md
64
66
  - fluent-plugin-json-transform.gemspec
67
+ - lib/fluent/plugin/filter_json_transform.rb
65
68
  - lib/fluent/plugin/parser_json_transform.rb
66
69
  - lib/transform/flatten.rb
67
70
  - lib/transform/nothing.rb
68
- homepage: https://github.com/graysonc/fluent-plugin-json-transform
71
+ homepage: https://github.com/mjourard/fluent-plugin-json-transform/
69
72
  licenses:
70
73
  - MIT
71
74
  metadata: {}
@@ -75,17 +78,17 @@ require_paths:
75
78
  - lib
76
79
  required_ruby_version: !ruby/object:Gem::Requirement
77
80
  requirements:
78
- - - '>='
81
+ - - ">="
79
82
  - !ruby/object:Gem::Version
80
83
  version: '0'
81
84
  required_rubygems_version: !ruby/object:Gem::Requirement
82
85
  requirements:
83
- - - '>='
86
+ - - ">="
84
87
  - !ruby/object:Gem::Version
85
88
  version: '0'
86
89
  requirements: []
87
90
  rubyforge_project:
88
- rubygems_version: 2.0.14
91
+ rubygems_version: 2.5.1
89
92
  signing_key:
90
93
  specification_version: 4
91
94
  summary: Input parser plugin which allows arbitrary transformation of input JSON