fluent-plugin-parser 0.1.1 → 0.1.2
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.
- data/README.md +9 -0
- data/fluent-plugin-parser.gemspec +1 -1
- data/lib/fluent/plugin/fixed_parser.rb +2 -0
- data/lib/fluent/plugin/out_parser.rb +11 -5
- data/test/plugin/test_out_parser.rb +70 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -43,6 +43,15 @@ If you want original attribute-data pair in re-emitted message, specify 'reserve
|
|
43
43
|
reserve_data yes
|
44
44
|
</match>
|
45
45
|
|
46
|
+
Format 'json' is also supported:
|
47
|
+
|
48
|
+
<match raw.sales.*>
|
49
|
+
type parser
|
50
|
+
tag sales
|
51
|
+
format json
|
52
|
+
key_name sales
|
53
|
+
</match>
|
54
|
+
|
46
55
|
### DeparserOutput
|
47
56
|
|
48
57
|
To build CSV from field 'store','item','num', as field 'csv', without raw data:
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = "fluent-plugin-parser"
|
4
|
-
gem.version = "0.1.
|
4
|
+
gem.version = "0.1.2"
|
5
5
|
gem.authors = ["TAGOMORI Satoshi"]
|
6
6
|
gem.email = ["tagomoris@gmail.com"]
|
7
7
|
gem.description = %q{fluentd plugin to parse single field, or to combine log structure into single field}
|
@@ -58,11 +58,15 @@ class Fluent::ParserOutput < Fluent::Output
|
|
58
58
|
t,values = if value
|
59
59
|
@parser.parse(value)
|
60
60
|
else
|
61
|
-
[nil,
|
61
|
+
[nil, nil]
|
62
62
|
end
|
63
63
|
t ||= time
|
64
|
-
|
65
|
-
|
64
|
+
r = if values
|
65
|
+
record.merge(values)
|
66
|
+
else
|
67
|
+
record
|
68
|
+
end
|
69
|
+
Fluent::Engine.emit(tag, t, r)
|
66
70
|
}
|
67
71
|
else
|
68
72
|
es.each {|time,record|
|
@@ -70,10 +74,12 @@ class Fluent::ParserOutput < Fluent::Output
|
|
70
74
|
t,values = if value
|
71
75
|
@parser.parse(value)
|
72
76
|
else
|
73
|
-
[nil,
|
77
|
+
[nil, nil]
|
74
78
|
end
|
75
79
|
t ||= time
|
76
|
-
|
80
|
+
if values
|
81
|
+
Fluent::Engine.emit(tag, t, values)
|
82
|
+
end
|
77
83
|
}
|
78
84
|
end
|
79
85
|
chain.next
|
@@ -118,5 +118,75 @@ class ParserOutputTest < Test::Unit::TestCase
|
|
118
118
|
assert_equal '3', second[2]['x']
|
119
119
|
assert_equal '4', second[2]['y']
|
120
120
|
assert_equal '20120402182100', second[2]['t']
|
121
|
+
|
122
|
+
d3 = create_driver(%[
|
123
|
+
tag parsed
|
124
|
+
key_name data
|
125
|
+
format /^(?<x>[0-9])(?<y>[0-9]) (?<t>.+)$/
|
126
|
+
], 'test.in')
|
127
|
+
time = Time.parse("2012-04-02 18:20:59").to_i
|
128
|
+
d3.run do
|
129
|
+
d3.emit({'data' => '12 20120402182059'}, time)
|
130
|
+
d3.emit({'data' => '34 20120402182100'}, time)
|
131
|
+
d3.emit({'data' => 'xy 20120402182101'}, time)
|
132
|
+
end
|
133
|
+
emits = d3.emits
|
134
|
+
assert_equal 2, emits.length
|
135
|
+
|
136
|
+
d3x = create_driver(%[
|
137
|
+
tag parsed
|
138
|
+
key_name data
|
139
|
+
format /^(?<x>\d)(?<y>\d) (?<t>.+)$/
|
140
|
+
reserve_data yes
|
141
|
+
], 'test.in')
|
142
|
+
time = Time.parse("2012-04-02 18:20:59").to_i
|
143
|
+
d3x.run do
|
144
|
+
d3x.emit({'data' => '12 20120402182059'}, time)
|
145
|
+
d3x.emit({'data' => '34 20120402182100'}, time)
|
146
|
+
d3x.emit({'data' => 'xy 20120402182101'}, time)
|
147
|
+
end
|
148
|
+
emits = d3x.emits
|
149
|
+
assert_equal 3, emits.length
|
150
|
+
|
151
|
+
d4 = create_driver(%[
|
152
|
+
tag parsed
|
153
|
+
key_name data
|
154
|
+
format json
|
155
|
+
], 'test.in')
|
156
|
+
time = Time.parse("2012-04-02 18:20:59").to_i
|
157
|
+
d4.run do
|
158
|
+
d4.emit({'data' => '{"xxx":"first","yyy":"second"}', 'xxx' => 'x', 'yyy' => 'y'}, time)
|
159
|
+
d4.emit({'data' => 'foobar', 'xxx' => 'x', 'yyy' => 'y'}, time)
|
160
|
+
end
|
161
|
+
emits = d4.emits
|
162
|
+
assert_equal 1, emits.length
|
163
|
+
|
164
|
+
d4x = create_driver(%[
|
165
|
+
tag parsed
|
166
|
+
key_name data
|
167
|
+
format json
|
168
|
+
reserve_data yes
|
169
|
+
], 'test.in')
|
170
|
+
time = Time.parse("2012-04-02 18:20:59").to_i
|
171
|
+
d4x.run do
|
172
|
+
d4x.emit({'data' => '{"xxx":"first","yyy":"second"}', 'xxx' => 'x', 'yyy' => 'y'}, time)
|
173
|
+
d4x.emit({'data' => 'foobar', 'xxx' => 'x', 'yyy' => 'y'}, time)
|
174
|
+
end
|
175
|
+
emits = d4x.emits
|
176
|
+
assert_equal 2, emits.length
|
177
|
+
|
178
|
+
first = emits[0]
|
179
|
+
assert_equal 'parsed', first[0]
|
180
|
+
assert_equal time, first[1]
|
181
|
+
assert_equal '{"xxx":"first","yyy":"second"}', first[2]['data']
|
182
|
+
assert_equal 'first', first[2]['xxx']
|
183
|
+
assert_equal 'second', first[2]['yyy']
|
184
|
+
|
185
|
+
second = emits[1]
|
186
|
+
assert_equal 'parsed', second[0]
|
187
|
+
assert_equal time, second[1]
|
188
|
+
assert_equal 'foobar', second[2]['data']
|
189
|
+
assert_equal 'x', second[2]['xxx']
|
190
|
+
assert_equal 'y', second[2]['yyy']
|
121
191
|
end
|
122
192
|
end
|