fluent-plugin-parser 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/README.md +16 -0
- data/fluent-plugin-parser.gemspec +2 -1
- data/lib/fluent/plugin/out_parser.rb +16 -35
- data/test/plugin/test_out_parser.rb +78 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d94615d4d0da1036e495a635ee91d1165281053d
|
4
|
+
data.tar.gz: e076017291eaa10cec2dbe7676e1d45b7e953bcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61820d91940e4322f7715ba8949dc6ca3e9cf558c4d2f21fecf14da57cc1f0211e35550c51ae6b81a97f9c80e2116d8bff881fa0c55133514d6c1e274f828f91
|
7
|
+
data.tar.gz: 514f354cd2d3674815fd213135bb0b843f2f79d23e69bee0f4826aae1f9528df3df31b5296721b5472bffd2a9086ac4be70420a58e55b0b1f7c04ffd1ce85369
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -91,6 +91,22 @@ To store parsed values with specified key name prefix, use `inject_key_prefix` o
|
|
91
91
|
# input string of 'sales': {"user":1,"num":2}
|
92
92
|
# output data: {"sales":"{\"user\":1,\"num\":2}","sales.user":1, "sales.num":2}
|
93
93
|
|
94
|
+
To store parsed values as a hash value in a field, use `hash_value_field` option:
|
95
|
+
|
96
|
+
<match raw.sales.*>
|
97
|
+
type parser
|
98
|
+
tag sales
|
99
|
+
format json
|
100
|
+
key_name sales
|
101
|
+
hash_value_field parsed
|
102
|
+
</match>
|
103
|
+
# input string of 'sales': {"user":1,"num":2}
|
104
|
+
# output data: {"parsed":{"user":1, "num":2}}
|
105
|
+
|
106
|
+
Other options (ex: `reserve_data`, `inject_key_prefix`) are available with `hash_value_field`.
|
107
|
+
|
108
|
+
# output data: {"sales":"{\"user\":1,\"num\":2}", "parsed":{"sales.user":1, "sales.num":2}}
|
109
|
+
|
94
110
|
### DeparserOutput
|
95
111
|
|
96
112
|
To build CSV from field 'store','item','num', as field 'csv', without raw data:
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = "fluent-plugin-parser"
|
4
|
-
gem.version = "0.
|
4
|
+
gem.version = "0.3.0"
|
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}
|
8
8
|
gem.summary = %q{plugin to parse/combine fluentd log messages}
|
9
9
|
gem.homepage = "https://github.com/tagomoris/fluent-plugin-parser"
|
10
|
+
gem.license = "APLv2"
|
10
11
|
|
11
12
|
gem.files = `git ls-files`.split($\)
|
12
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -10,6 +10,7 @@ class Fluent::ParserOutput < Fluent::Output
|
|
10
10
|
config_param :reserve_data, :bool, :default => false
|
11
11
|
config_param :inject_key_prefix, :string, :default => nil
|
12
12
|
config_param :replace_invalid_sequence, :bool, :default => false
|
13
|
+
config_param :hash_value_field, :string, :default => nil
|
13
14
|
|
14
15
|
def initialize
|
15
16
|
super
|
@@ -54,43 +55,23 @@ class Fluent::ParserOutput < Fluent::Output
|
|
54
55
|
end
|
55
56
|
tag
|
56
57
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
record.merge(values)
|
71
|
-
else
|
72
|
-
record
|
73
|
-
end
|
58
|
+
es.each do |time,record|
|
59
|
+
raw_value = record[@key_name]
|
60
|
+
t,values = raw_value ? parse(raw_value) : [nil, nil]
|
61
|
+
t ||= time
|
62
|
+
|
63
|
+
if values && @inject_key_prefix
|
64
|
+
values = Hash[values.map{|k,v| [ @inject_key_prefix + k, v ]}]
|
65
|
+
end
|
66
|
+
r = @hash_value_field ? {@hash_value_field => values} : values
|
67
|
+
if @reserve_data
|
68
|
+
r = r ? record.merge(r) : record
|
69
|
+
end
|
70
|
+
if r
|
74
71
|
Fluent::Engine.emit(tag, t, r)
|
75
|
-
|
76
|
-
else
|
77
|
-
es.each {|time,record|
|
78
|
-
value = record[@key_name]
|
79
|
-
t,values = if value
|
80
|
-
parsed = parse(value)
|
81
|
-
if @inject_key_prefix
|
82
|
-
parsed = Hash[parsed.map{|k,v| [ @inject_key_prefix + k, v ]}]
|
83
|
-
end
|
84
|
-
parsed
|
85
|
-
else
|
86
|
-
[nil, nil]
|
87
|
-
end
|
88
|
-
t ||= time
|
89
|
-
if values
|
90
|
-
Fluent::Engine.emit(tag, t, values)
|
91
|
-
end
|
92
|
-
}
|
72
|
+
end
|
93
73
|
end
|
74
|
+
|
94
75
|
chain.next
|
95
76
|
end
|
96
77
|
|
@@ -364,6 +364,84 @@ class ParserOutputTest < Test::Unit::TestCase
|
|
364
364
|
assert_equal 5, first[2].keys.size
|
365
365
|
end
|
366
366
|
|
367
|
+
CONFIG_HASH_VALUE_FIELD = %[
|
368
|
+
remove_prefix foo.baz
|
369
|
+
add_prefix foo.bar
|
370
|
+
format json
|
371
|
+
key_name data
|
372
|
+
hash_value_field parsed
|
373
|
+
]
|
374
|
+
CONFIG_HASH_VALUE_FIELD_RESERVE_DATA = %[
|
375
|
+
remove_prefix foo.baz
|
376
|
+
add_prefix foo.bar
|
377
|
+
format json
|
378
|
+
key_name data
|
379
|
+
reserve_data yes
|
380
|
+
hash_value_field parsed
|
381
|
+
]
|
382
|
+
CONFIG_HASH_VALUE_FIELD_WITH_INJECT_KEY_PREFIX = %[
|
383
|
+
remove_prefix foo.baz
|
384
|
+
add_prefix foo.bar
|
385
|
+
format json
|
386
|
+
key_name data
|
387
|
+
hash_value_field parsed
|
388
|
+
inject_key_prefix data.
|
389
|
+
]
|
390
|
+
def test_inject_hash_value_field
|
391
|
+
original = {'data' => '{"xxx":"first","yyy":"second"}', 'xxx' => 'x', 'yyy' => 'y'}
|
392
|
+
|
393
|
+
d = create_driver(CONFIG_HASH_VALUE_FIELD, 'foo.baz.test')
|
394
|
+
time = Time.parse("2012-04-02 18:20:59").to_i
|
395
|
+
d.run do
|
396
|
+
d.emit(original, time)
|
397
|
+
end
|
398
|
+
emits = d.emits
|
399
|
+
assert_equal 1, emits.length
|
400
|
+
|
401
|
+
first = emits[0]
|
402
|
+
assert_equal 'foo.bar.test', first[0]
|
403
|
+
assert_equal time, first[1]
|
404
|
+
|
405
|
+
record = first[2]
|
406
|
+
assert_equal 1, record.keys.size
|
407
|
+
assert_equal({"xxx"=>"first","yyy"=>"second"}, record['parsed'])
|
408
|
+
|
409
|
+
d = create_driver(CONFIG_HASH_VALUE_FIELD_RESERVE_DATA, 'foo.baz.test')
|
410
|
+
time = Time.parse("2012-04-02 18:20:59").to_i
|
411
|
+
d.run do
|
412
|
+
d.emit(original, time)
|
413
|
+
end
|
414
|
+
emits = d.emits
|
415
|
+
assert_equal 1, emits.length
|
416
|
+
|
417
|
+
first = emits[0]
|
418
|
+
assert_equal 'foo.bar.test', first[0]
|
419
|
+
assert_equal time, first[1]
|
420
|
+
|
421
|
+
record = first[2]
|
422
|
+
assert_equal 4, record.keys.size
|
423
|
+
assert_equal original['data'], record['data']
|
424
|
+
assert_equal original['xxx'], record['xxx']
|
425
|
+
assert_equal original['yyy'], record['yyy']
|
426
|
+
assert_equal({"xxx"=>"first","yyy"=>"second"}, record['parsed'])
|
427
|
+
|
428
|
+
d = create_driver(CONFIG_HASH_VALUE_FIELD_WITH_INJECT_KEY_PREFIX, 'foo.baz.test')
|
429
|
+
time = Time.parse("2012-04-02 18:20:59").to_i
|
430
|
+
d.run do
|
431
|
+
d.emit(original, time)
|
432
|
+
end
|
433
|
+
emits = d.emits
|
434
|
+
assert_equal 1, emits.length
|
435
|
+
|
436
|
+
first = emits[0]
|
437
|
+
assert_equal 'foo.bar.test', first[0]
|
438
|
+
assert_equal time, first[1]
|
439
|
+
|
440
|
+
record = first[2]
|
441
|
+
assert_equal 1, record.keys.size
|
442
|
+
assert_equal({"data.xxx"=>"first","data.yyy"=>"second"}, record['parsed'])
|
443
|
+
end
|
444
|
+
|
367
445
|
#TODO: apache2
|
368
446
|
# REGEXP = /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/
|
369
447
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAGOMORI Satoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- .gitignore
|
50
|
+
- .travis.yml
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|
@@ -59,7 +60,8 @@ files:
|
|
59
60
|
- test/plugin/test_deparser.rb
|
60
61
|
- test/plugin/test_out_parser.rb
|
61
62
|
homepage: https://github.com/tagomoris/fluent-plugin-parser
|
62
|
-
licenses:
|
63
|
+
licenses:
|
64
|
+
- APLv2
|
63
65
|
metadata: {}
|
64
66
|
post_install_message:
|
65
67
|
rdoc_options: []
|
@@ -77,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
79
|
version: '0'
|
78
80
|
requirements: []
|
79
81
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.0.
|
82
|
+
rubygems_version: 2.0.3
|
81
83
|
signing_key:
|
82
84
|
specification_version: 4
|
83
85
|
summary: plugin to parse/combine fluentd log messages
|