fluent-plugin-fields-parser 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -17,6 +17,8 @@ Use RubyGems:
|
|
17
17
|
|
18
18
|
remove_tag_prefix raw
|
19
19
|
add_tag_prefix parsed
|
20
|
+
|
21
|
+
strict_key_value false
|
20
22
|
</match>
|
21
23
|
|
22
24
|
If following record is passed:
|
@@ -25,7 +27,7 @@ If following record is passed:
|
|
25
27
|
{"message": "Audit log user=Johny action='add-user' result=success" }
|
26
28
|
```
|
27
29
|
|
28
|
-
then you
|
30
|
+
then you will get a new record:
|
29
31
|
|
30
32
|
```
|
31
33
|
{
|
@@ -92,7 +94,7 @@ Configuration
|
|
92
94
|
|
93
95
|
For input like:
|
94
96
|
```
|
95
|
-
{ "message": "data black:54 white
|
97
|
+
{ "message": "data black:54 white:55 red:10"}
|
96
98
|
```
|
97
99
|
|
98
100
|
it returns:
|
@@ -114,6 +116,41 @@ You cat add and/or remove tag prefix using Configuration parameters
|
|
114
116
|
add_tag_prefix parsed
|
115
117
|
</match>
|
116
118
|
|
117
|
-
|
119
|
+
If it matched tag "raw.some.record", then it emits tag "parsed.some.record".
|
120
|
+
|
121
|
+
### Parameter strict_key_value
|
122
|
+
|
123
|
+
```
|
124
|
+
<match pattern>
|
125
|
+
type fields_parser
|
126
|
+
strict_key_value true
|
127
|
+
</match>
|
128
|
+
```
|
129
|
+
|
130
|
+
If `strict_key_value` is set to `true`, the parser will use the [ruby logfmt
|
131
|
+
parser](https://github.com/cyberdelia/logfmt-ruby) which will parse the log
|
132
|
+
message based on the popular [logfmt](https://brandur.org/logfmt) key/value
|
133
|
+
format. Do note that this parser will create Fixnum and Float type values
|
134
|
+
when it parses integer and float values.
|
118
135
|
|
136
|
+
All information provided in the log message must be in a strict key=value
|
137
|
+
format. For example, if following record is passed:
|
119
138
|
|
139
|
+
```
|
140
|
+
{"message": "msg=\"Audit log\" user=Johnny action=\"add-user\" result=success iVal=23 fVal=1.02 bVal=true" }
|
141
|
+
```
|
142
|
+
|
143
|
+
then you will get a new record:
|
144
|
+
|
145
|
+
```
|
146
|
+
{
|
147
|
+
"message": "msg=\"Audit log\" user=Johnny action=\"add-user\" result=success iVal=23 fVal=1.02 bVal=true",
|
148
|
+
"msg": "Audit log",
|
149
|
+
"user": "Johnny",
|
150
|
+
"action": "add-user",
|
151
|
+
"result": "success",
|
152
|
+
"iVal": 23,
|
153
|
+
"fVal": 1.02,
|
154
|
+
"bVal": "true"
|
155
|
+
}
|
156
|
+
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "logfmt"
|
2
|
+
|
1
3
|
module Fluent
|
2
4
|
class OutputFieldsParser < Fluent::Output
|
3
5
|
Fluent::Plugin.register_output('fields_parser', self)
|
@@ -8,6 +10,7 @@ module Fluent
|
|
8
10
|
config_param :fields_key, :string, :default => nil
|
9
11
|
config_param :pattern, :string,
|
10
12
|
:default => %{([a-zA-Z_]\\w*)=((['"]).*?(\\3)|[\\w.@$%/+-]*)}
|
13
|
+
config_param :strict_key_value, :bool, :default => false
|
11
14
|
|
12
15
|
def compiled_pattern
|
13
16
|
@compiled_pattern ||= Regexp.new(pattern)
|
@@ -39,15 +42,22 @@ module Fluent
|
|
39
42
|
source = record[parse_key].to_s
|
40
43
|
target = fields_key ? (record[fields_key] ||= {}) : record
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
if strict_key_value
|
46
|
+
# Use logfmt to parse it (key=value)
|
47
|
+
parsed = Logfmt.parse(source)
|
48
|
+
target.merge!(parsed)
|
49
|
+
else
|
50
|
+
source.scan(compiled_pattern) do |match|
|
51
|
+
(key, value, begining_quote, ending_quote) = match
|
52
|
+
next if key.nil?
|
53
|
+
next if target.has_key?(key)
|
54
|
+
value = value.to_s
|
55
|
+
from_pos = begining_quote.to_s.length
|
56
|
+
to_pos = value.length - ending_quote.to_s.length - 1
|
57
|
+
target[key] = value[from_pos..to_pos]
|
58
|
+
end
|
50
59
|
end
|
60
|
+
|
51
61
|
return record
|
52
62
|
end
|
53
63
|
end
|
data/test/out_fields_parser.rb
CHANGED
@@ -231,4 +231,40 @@ class FieldsParserOutputTest < Test::Unit::TestCase
|
|
231
231
|
emits[1][2]
|
232
232
|
)
|
233
233
|
end
|
234
|
+
|
235
|
+
def test_strict_key_value
|
236
|
+
d = create_driver("strict_key_value true")
|
237
|
+
|
238
|
+
orig_message = %{msg="Audit log" user=Johnny action="add-user" dontignore=don't-ignore-this result=success iVal=23 fVal=1.02 bVal=true}
|
239
|
+
d.run do
|
240
|
+
d.emit({'message' => orig_message})
|
241
|
+
d.emit({'message' => 'a'})
|
242
|
+
end
|
243
|
+
|
244
|
+
emits = d.emits
|
245
|
+
assert_equal 2, emits.size
|
246
|
+
assert_equal "orig.test.tag", emits[0][0]
|
247
|
+
assert_equal(
|
248
|
+
{
|
249
|
+
'message' => orig_message,
|
250
|
+
"msg"=>"Audit log",
|
251
|
+
'user' => "Johnny",
|
252
|
+
'action' => 'add-user',
|
253
|
+
'dontignore' => "don't-ignore-this",
|
254
|
+
'result' => 'success',
|
255
|
+
'iVal' => 23,
|
256
|
+
'fVal' => 1.02,
|
257
|
+
'bVal' => "true"
|
258
|
+
},
|
259
|
+
emits[0][2]
|
260
|
+
)
|
261
|
+
assert_equal(
|
262
|
+
{
|
263
|
+
'message' => 'a',
|
264
|
+
},
|
265
|
+
emits[1][2]
|
266
|
+
)
|
267
|
+
end
|
268
|
+
|
269
|
+
|
234
270
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-fields-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: logfmt
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rake
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,7 +70,7 @@ files:
|
|
54
70
|
- README.md
|
55
71
|
- Rakefile
|
56
72
|
- VERSION
|
57
|
-
- fluent-plugin-
|
73
|
+
- fluent-plugin-fields-parser.gemspec
|
58
74
|
- lib/fluent/plugin/out_fields_parser.rb
|
59
75
|
- test/out_fields_parser.rb
|
60
76
|
homepage: https://github.com/tomas-zemres/fluent-plugin-fields-parser
|