fluent-plugin-json-nest2flat 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +39 -2
- data/fluent-plugin-json-nest2flat.gemspec +1 -1
- data/lib/fluent/plugin/out_json_nest2flat.rb +27 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad7d5150b74d88a5f4435944d95a818b6800eb59
|
4
|
+
data.tar.gz: 1628f1bac6bed1b7a9247f00c3d8338f47151690
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a42af76cb7d2ed1c3c005e7a0b7a5deec88d97a95e665e0dd68f00f0cf6a50075440f8d868d447ce2e4438f6b3cdea0c981f6e6510a3e3c3f4f6864b5f2f0457
|
7
|
+
data.tar.gz: 187e26e1006348451d931ff07ae6db04644843fd2eae70c53eacc0cfcb5cd66e4ccf0ff62a3451279e2c727259e6eec1885298e11222981e402e54ce7b378480
|
data/README.md
CHANGED
@@ -10,21 +10,53 @@ ex. {"hoge":1, "foo":2, "data":{"name":"taro", "age":18, "height":175}} -> ex. {
|
|
10
10
|
# Configuration
|
11
11
|
ex1.
|
12
12
|
|
13
|
-
<match
|
13
|
+
<match example>
|
14
14
|
type json_nest2flat
|
15
15
|
tag json_nest2flat.finished
|
16
16
|
json_keys data1,data2,data3
|
17
17
|
</match>
|
18
18
|
|
19
|
+
in
|
20
|
+
|
21
|
+
example: {"name":"taro","age":"17","data1":{"a":"b"},"data2":{"c":"d"},"data3":{"e":"f"}}
|
22
|
+
|
23
|
+
out
|
24
|
+
|
25
|
+
json_nest2flat.finished: {"name":"taro","age":"17","a":"b","c":"d","e":"f"}
|
19
26
|
|
20
27
|
ex2.
|
21
28
|
|
22
|
-
<match
|
29
|
+
<match example>
|
23
30
|
type json_nest2flat
|
24
31
|
add_tag_prefix json_nest2flat
|
25
32
|
json_keys data1,data2,data3
|
26
33
|
</match>
|
27
34
|
|
35
|
+
in
|
36
|
+
|
37
|
+
example: {"name":"taro","age":"17","data1":{"a":"b"},"data2":{"c":"d"},"data3":{"e":"f"}}
|
38
|
+
|
39
|
+
out
|
40
|
+
|
41
|
+
json_nest2flat.example: {"name":"taro","age":"17","a":"b","c":"d","e":"f"}
|
42
|
+
|
43
|
+
ex3.
|
44
|
+
|
45
|
+
<match example>
|
46
|
+
type json_nest2flat
|
47
|
+
add_tag_prefix json_nest2flat
|
48
|
+
json_keys data1
|
49
|
+
ignore_item_keys {"data1":["b","c","d"]}
|
50
|
+
</match>
|
51
|
+
|
52
|
+
in
|
53
|
+
|
54
|
+
example: {"name":"taro","age":"17","data1":{"a":"b","b":"c","c":"d","d":"e","e":"f"}}
|
55
|
+
|
56
|
+
out
|
57
|
+
|
58
|
+
json_nest2flat.example: {"name":"taro","age":"17","a":"b","e":"f"}
|
59
|
+
|
28
60
|
# Parameters
|
29
61
|
* tag
|
30
62
|
|
@@ -38,6 +70,11 @@ ex2.
|
|
38
70
|
|
39
71
|
It is the key that you want to convert to a flat structure from JSON nested. It is more than one can be specified in a comma-separated.
|
40
72
|
|
73
|
+
* ignore_item_keys
|
74
|
+
|
75
|
+
You specify the item that you want to ignore the key that is specified in the "json_keys". The format is JSON format. Please refer to the section of "Configuration" example of setting.
|
76
|
+
|
77
|
+
|
41
78
|
# TODO
|
42
79
|
|
43
80
|
Currently, nested structure of two or more layers will be unexpected.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = "fluent-plugin-json-nest2flat"
|
4
|
-
spec.version = "0.0.
|
4
|
+
spec.version = "0.0.4"
|
5
5
|
spec.authors = ["Fukui ReTu"]
|
6
6
|
spec.email = ["s0232101@gmail.com"]
|
7
7
|
spec.description = %q{Output filter plugin to convert to a flat structure the JSON that is nest}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Fluent
|
2
2
|
class JsonNestToFlatOutput < Fluent::Output
|
3
|
-
|
4
3
|
Fluent::Plugin.register_output('json_nest2flat', self)
|
5
4
|
|
6
5
|
config_param :tag, :string, :default => nil
|
7
6
|
config_param :add_tag_prefix, :string, :default => nil
|
8
7
|
config_param :json_keys, :string, :default => nil
|
8
|
+
config_param :ignore_item_keys, :string, :default => nil
|
9
9
|
|
10
10
|
def configure(conf)
|
11
11
|
super
|
@@ -27,13 +27,28 @@ module Fluent
|
|
27
27
|
end
|
28
28
|
|
29
29
|
@json_keys = @json_keys.split(",")
|
30
|
+
|
31
|
+
@ignore_item_keys = conf['ignore_item_keys']
|
32
|
+
|
33
|
+
if !@ignore_item_keys.nil?
|
34
|
+
begin
|
35
|
+
@ignore_item_keys = JSON.parse(@ignore_item_keys)
|
36
|
+
rescue => e
|
37
|
+
raise Fluent::ConfigError, "ignore_item_keys is illegal! ignore_item_keys=#{@ignore_item_keys}"
|
38
|
+
end
|
39
|
+
end
|
30
40
|
end
|
31
41
|
|
32
42
|
def emit(tag, es, chain)
|
33
43
|
es.each { |time, record|
|
34
44
|
chain.next
|
35
45
|
|
36
|
-
new_record =
|
46
|
+
new_record = nil
|
47
|
+
begin
|
48
|
+
new_record = _convert_record(record);
|
49
|
+
rescue => e
|
50
|
+
$log.error "json_data is parse error.", :error=>e.to_s
|
51
|
+
end
|
37
52
|
|
38
53
|
if @enabled_tag
|
39
54
|
Fluent::Engine.emit(@tag, time, new_record)
|
@@ -49,16 +64,23 @@ module Fluent
|
|
49
64
|
# @return [Hash] ネストされたJSONをフラットな構造に変換したレコード
|
50
65
|
private
|
51
66
|
def _convert_record(old_record)
|
52
|
-
new_record =
|
67
|
+
new_record = {}
|
53
68
|
json_keys_exist_count = 0
|
54
69
|
|
55
70
|
old_record.each { |old_record_k, old_record_v|
|
56
|
-
if
|
71
|
+
if @json_keys.include?(old_record_k)
|
57
72
|
json_data = old_record[old_record_k]
|
58
73
|
JSON.parse(json_data).each { |json_k, json_v|
|
74
|
+
if @ignore_item_keys.include?(old_record_k)
|
75
|
+
# 無視するキーに該当
|
76
|
+
ignore_items = @ignore_item_keys[old_record_k]
|
77
|
+
if ignore_items.include?(json_k)
|
78
|
+
# 無視するアイテムに該当するのでハッシュに含まない
|
79
|
+
next
|
80
|
+
end
|
81
|
+
end
|
59
82
|
new_record[json_k] = json_v
|
60
83
|
}
|
61
|
-
|
62
84
|
json_keys_exist_count += 1
|
63
85
|
else
|
64
86
|
new_record[old_record_k] = old_record_v
|
@@ -71,6 +93,5 @@ module Fluent
|
|
71
93
|
|
72
94
|
return new_record
|
73
95
|
end
|
74
|
-
|
75
96
|
end
|
76
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-json-nest2flat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fukui ReTu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|