fluent-plugin-json-transform_ex 0.1.0 → 0.1.3

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 700d72367418f0f7cf2630152aff119cb796e17fcf6aedd25462b73d76893853
4
- data.tar.gz: 4f95f6f62c7a7de3d7004f3b1c2a86c556edf2bf2210c5a9c9e67fd7986eceb6
3
+ metadata.gz: 0b34e98f0fd1c9b05630f8b19f2a2acc2fca65ca6fd383da99ec3498aebd0217
4
+ data.tar.gz: a47b0d218b4066692f2633761c5c676901ffe00653c2ad448381cdb8f3905672
5
5
  SHA512:
6
- metadata.gz: 943274519c5c26f54c57419e2be56b61d9483eae83c821e66dea683a32f9edda3d40b61cdbc068442ec1a5349e17855ea04b62322ad528f6de83970857769903
7
- data.tar.gz: 5fcc73c15e2cd92a964639e876d91c9e9e479e74b657d527b5f424695cf8fda40f05a0a9c2ae856cbd062d6cad9eafe28ec2ac2bd2fe8a95992cebf48702089e
6
+ metadata.gz: 3a7de248500408965e503f462f6ac829a460238d947aaca9a7441f9fc2214a870c21cc5a4229b378e82cf7719327a52b18e49b62620faf988bf90a7c3280bb96
7
+ data.tar.gz: ab2f10af69c219d255cfd1ba40eb6659941d182e79dc5d1c5e9890c6b0ea2309efdd99be7bef8dcc5e002a2cb1cbf4932b6d87c60846e434a07edcbebd6effb5
data/README.md CHANGED
@@ -3,13 +3,18 @@
3
3
  ## Overview
4
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
5
 
6
+ It was forker from [fluent-plugin-json-transform](https://github.com/mjourard/fluent-plugin-json-transform) plugin and has the following fixes:
7
+ - Fixing issue when you can't use the same filter plugin multiple times with different scripts.
6
8
 
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
+ **Explanation:** there was a sctrict rule that script class should be named as `JSONTransformer`. And when you defined a more than 1 script with different logic, anyway those classes should be named as `JSONTransformer`. As a result you have several scripts with different logic but with the same name.
10
+
11
+ **Fix:** define new parameter called `class_name` where you can define a custom class name and this is allow you to have a lot of scripts with different class names.
12
+
13
+ - Adding `params` section with key-value pairs which can be passed to user script for usage.
9
14
 
10
15
  ## Installation
11
16
  ```bash
12
- gem install fluent-plugin-json-transform_ex --version 0.0.1
17
+ gem install fluent-plugin-json-transform_ex --version 0.1.0
13
18
  ```
14
19
 
15
20
  ## Configuration
@@ -20,6 +25,10 @@ gem install fluent-plugin-json-transform_ex --version 0.0.1
20
25
  transform_script [nothing|flatten|custom]
21
26
  script_path "/home/grayson/transform_script.rb" # ignored if transform_script != custom
22
27
  class_name "CustomJSONTransformer" # [optional] default value is "JSONTransformer", ignored if transform_script != custom
28
+ <params> # any parameters which will be passed to "transform" method of class_name class
29
+ key1 value1
30
+ key2 value2
31
+ </params>
23
32
  </source>
24
33
  ```
25
34
 
@@ -64,6 +73,10 @@ If you want to flatten your json after doing other parsing from the original sou
64
73
  transform_script [nothing|flatten|custom]
65
74
  script_path "/home/grayson/transform_script.rb" # ignored if transform_script != custom
66
75
  class_name "CustomJSONTransformer" # [optional] default value is "JSONTransformer", ignored if transform_script != custom
76
+ <params> # any parameters which will be passed to "transform" method of class_name class
77
+ key1 value1
78
+ key2 value2
79
+ </params>
67
80
  </filter>
68
81
  ```
69
82
 
@@ -75,7 +88,7 @@ The transformer class should have an instance method `transform` which takes a R
75
88
  ```ruby
76
89
  # lib/transform/flatten.rb
77
90
  class JSONTransformer # or any class name defined in class_name parameter
78
- def transform(json)
91
+ def transform(json, params = {}) # params - [optional] passed parameters from config
79
92
  return flatten(json, "")
80
93
  end
81
94
 
@@ -100,4 +113,4 @@ class JSONTransformer # or any class name defined in class_name parameter
100
113
  return json
101
114
  end
102
115
  end
103
- ```
116
+ ```
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "fluent-plugin-json-transform_ex"
4
- spec.version = "0.1.0"
4
+ spec.version = "0.1.3"
5
5
  spec.authors = ["Grayson Chao", "Yevhen Fabizhevskyi"]
6
6
  spec.email = ["grayson.chao@gmail.com", "fabasoad@gmail.com"]
7
7
  spec.description = %q{Input parser plugin which allows arbitrary transformation of input JSON}
@@ -13,6 +13,18 @@ module Fluent
13
13
  def configure(conf)
14
14
  @transform_script = conf['transform_script']
15
15
 
16
+ @params = {}
17
+ $log.info("Searching for 'params'...")
18
+ conf.elements.each do |element|
19
+ if element.name == 'params'
20
+ element.to_hash.each do |key, value|
21
+ @params[key] = value
22
+ end
23
+ $log.info("'params' section found: #{@params}") if @params.length > 0
24
+ end
25
+ end
26
+ $log.info("'params' is not found or passed nothing") if @params.empty?
27
+
16
28
  if DEFAULTS.include?(@transform_script)
17
29
  @transform_script = "#{__dir__}/../../transform/#{@transform_script}.rb"
18
30
  className = DEFAULT_CLASS_NAME
@@ -24,13 +36,15 @@ module Fluent
24
36
  require @transform_script
25
37
  begin
26
38
  @transformer = Object.const_get(className).new
39
+ $log.debug("#{className} class is loaded.")
27
40
  rescue NameError
28
41
  @transformer = Object.const_get(DEFAULT_CLASS_NAME).new
42
+ $log.debug("#{DEFAULT_CLASS_NAME} class is loaded.")
29
43
  end
30
44
  end
31
45
 
32
46
  def filter(tag, time, record)
33
- return @transformer.transform(record)
47
+ return @transformer.transform(record, @params)
34
48
  end
35
49
  end
36
50
  end
@@ -12,6 +12,18 @@ module Fluent
12
12
  def configure(conf)
13
13
  @transform_script = conf['transform_script']
14
14
 
15
+ @params = {}
16
+ $log.info("Searching for 'params'...")
17
+ conf.elements.each do |element|
18
+ if element.name == 'params'
19
+ element.to_hash.each do |key, value|
20
+ @params[key] = value
21
+ end
22
+ $log.info("'params' section found: #{@params}") if @params.length > 0
23
+ end
24
+ end
25
+ $log.info("'params' is not found or passed nothing") if @params.empty?
26
+
15
27
  if DEFAULTS.include?(@transform_script)
16
28
  @transform_script = "#{__dir__}/../../transform/#{@transform_script}.rb"
17
29
  className = DEFAULT_CLASS_NAME
@@ -30,12 +42,12 @@ module Fluent
30
42
 
31
43
  def call(text)
32
44
  raw_json = JSON.parse(text)
33
- return nil, @transformer.transform(raw_json)
45
+ return nil, @transformer.transform(raw_json, @params)
34
46
  end
35
47
 
36
48
  def parse(text)
37
49
  raw_json = JSON.parse(text)
38
- return nil, @transformer.transform(raw_json)
50
+ return nil, @transformer.transform(raw_json, @params)
39
51
  end
40
52
  end
41
53
  register_template("json_transform_ex", Proc.new { JSONTransformParser.new })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-json-transform_ex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson Chao
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-07-27 00:00:00.000000000 Z
12
+ date: 2018-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler