fluent-plugin-parse_request_body 0.0.1
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 +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +13 -0
- data/Appraisals +3 -0
- data/Gemfile +2 -0
- data/LICENSE +2 -0
- data/README.md +1 -0
- data/Rakefile +9 -0
- data/fluent-plugin-parse_request_body.gemspec +23 -0
- data/gemfiles/fluentd_0.14.gemfile +7 -0
- data/lib/fluent/plugin/filter_parse_request_body.rb +31 -0
- data/lib/fluent/plugin/out_parse_request_body.rb +47 -0
- data/lib/fluent/plugin/parse_request_body_extractor.rb +92 -0
- data/test/.DS_Store +0 -0
- data/test/plugin/test_filter_parse_request_body.rb +162 -0
- data/test/plugin/test_out_parse_request_body.rb +193 -0
- data/test/test_helper.rb +9 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e3d528441f6fd97325700bfddb162787bd74740b4c2daf677d1f8d136b7234da
|
4
|
+
data.tar.gz: e860534ad5a27a7784efd9482910eec6debd6d5c43af887af9c1b7f3de0c6def
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b7c36a29ac960ec14ba04eede5c73e13e908ea2eeed58417569178263aefbd3f53c6e4765689408acba2ec40ad4163b5fc312cbd95bc61c14105a6333d8a318
|
7
|
+
data.tar.gz: 7629939eb2b5439c1a4cc918a198c7d09f1ce650a448da7a10aa3659b41d6ed9ded782e66f3b384ba2cb6eed1bfbfeae6fc695c0fab2d795d2214aad4be3ec16
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# fluent-plugin-parse_request_body
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = 'fluent-plugin-parse_request_body'
|
3
|
+
gem.version = '0.0.1'
|
4
|
+
gem.authors = ['EkiSong']
|
5
|
+
gem.email = ['yifriday0614@gmail.com']
|
6
|
+
gem.homepage = 'https://github.com/yifriday/fluent-plugin-parse_request_body.git'
|
7
|
+
gem.description = %q{Fluentd plugin to parse request body.}
|
8
|
+
gem.summary = %q{Fluentd plugin to parse request body}
|
9
|
+
gem.license = 'MIT'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
|
16
|
+
if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
|
17
|
+
gem.add_development_dependency "test-unit", '~> 3'
|
18
|
+
end
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'appraisal'
|
22
|
+
gem.add_runtime_dependency 'fluentd', ['>= 0.14.8', '< 2']
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "fluent/plugin/filter"
|
2
|
+
require "fluent/plugin/parse_request_body_extractor"
|
3
|
+
|
4
|
+
module Fluent::Plugin
|
5
|
+
class ParseRequestBodyFilter < Fluent::Plugin::Filter
|
6
|
+
|
7
|
+
Fluent::Plugin.register_filter('parse_request_body', self)
|
8
|
+
|
9
|
+
desc "point a key whose value contains URL string."
|
10
|
+
config_param :key, :string
|
11
|
+
desc "If set, only the key/value whose key is included only will be added to the record."
|
12
|
+
config_param :only, :string, default: nil
|
13
|
+
desc "If set, the key/value whose key is included except will NOT be added to the record."
|
14
|
+
config_param :except, :string, default: nil
|
15
|
+
desc "If set to true, the original key url will be discarded from the record."
|
16
|
+
config_param :discard_key, :bool, default: false
|
17
|
+
desc "Prefix of fields."
|
18
|
+
config_param :add_field_prefix, :string, default: nil
|
19
|
+
desc "If set to true, permit blank key."
|
20
|
+
config_param :permit_blank_key, :bool, default: false
|
21
|
+
|
22
|
+
def configure(conf)
|
23
|
+
super
|
24
|
+
@extractor = Fluent::Plugin::ParseRequestBodyExtractor.new(self, conf)
|
25
|
+
end
|
26
|
+
|
27
|
+
def filter(tag, time, record)
|
28
|
+
@extractor.add_query_params_field(record)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "fluent/plugin/output"
|
2
|
+
require "fluent/plugin/parse_request_body_extractor"
|
3
|
+
|
4
|
+
module Fluent::Plugin
|
5
|
+
class ParseRequestBodyOutput < Fluent::Plugin::Output
|
6
|
+
include Fluent::HandleTagNameMixin
|
7
|
+
|
8
|
+
Fluent::Plugin.register_output('parse_request_body', self)
|
9
|
+
|
10
|
+
helpers :event_emitter
|
11
|
+
|
12
|
+
desc "point a key whose value contains URL string."
|
13
|
+
config_param :key, :string
|
14
|
+
desc "If set, only the key/value whose key is included only will be added to the record."
|
15
|
+
config_param :only, :string, default: nil
|
16
|
+
desc "If set, the key/value whose key is included except will NOT be added to the record."
|
17
|
+
config_param :except, :string, default: nil
|
18
|
+
desc "If set to true, the original key url will be discarded from the record."
|
19
|
+
config_param :discard_key, :bool, default: false
|
20
|
+
desc "Prefix of fields."
|
21
|
+
config_param :add_field_prefix, :string, default: nil
|
22
|
+
desc "If set to true, permit blank key."
|
23
|
+
config_param :permit_blank_key, :bool, default: false
|
24
|
+
|
25
|
+
def configure(conf)
|
26
|
+
super
|
27
|
+
@extractor = Fluent::Plugin::ParseRequestBodyExtractor.new(self, conf)
|
28
|
+
end
|
29
|
+
|
30
|
+
def multi_workers_ready?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def filter_record(tag, time, record)
|
35
|
+
record = @extractor.add_query_params_field(record)
|
36
|
+
super(tag, time, record)
|
37
|
+
end
|
38
|
+
|
39
|
+
def process(tag, es)
|
40
|
+
es.each do |time, record|
|
41
|
+
t = tag.dup
|
42
|
+
filter_record(t, time, record)
|
43
|
+
router.emit(t, time, record)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'cgi/util'
|
3
|
+
require 'webrick'
|
4
|
+
|
5
|
+
module Fluent::Plugin
|
6
|
+
class ParseRequestBodyExtractor
|
7
|
+
|
8
|
+
attr_reader :log
|
9
|
+
|
10
|
+
def initialize(plugin, conf)
|
11
|
+
@log = plugin.log
|
12
|
+
|
13
|
+
if plugin.is_a?(Fluent::Plugin::Output)
|
14
|
+
unless have_tag_option?(plugin)
|
15
|
+
raise Fluent::ConfigError, "out_parse_request_body: At least one of remove_tag_prefix/remove_tag_suffix/add_tag_prefix/add_tag_suffix is required to be set."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
@key = plugin.key
|
20
|
+
@only = plugin.only
|
21
|
+
@except = plugin.except
|
22
|
+
@discard_key = plugin.discard_key
|
23
|
+
@add_field_prefix = plugin.add_field_prefix
|
24
|
+
@permit_blank_key = plugin.permit_blank_key
|
25
|
+
|
26
|
+
if @only
|
27
|
+
@include_keys = @only.split(/\s*,\s*/).inject({}) do |hash, i|
|
28
|
+
hash[i] = true
|
29
|
+
hash
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if @except
|
34
|
+
@exclude_keys = @except.split(/\s*,\s*/).inject({}) do |hash, i|
|
35
|
+
hash[i] = true
|
36
|
+
hash
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_query_params_field(record)
|
42
|
+
return record unless record[@key]
|
43
|
+
add_query_params(record[@key], record)
|
44
|
+
record.delete(@key) if @discard_key
|
45
|
+
record
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def have_tag_option?(plugin)
|
51
|
+
plugin.remove_tag_prefix ||
|
52
|
+
plugin.remove_tag_suffix ||
|
53
|
+
plugin.add_tag_prefix ||
|
54
|
+
plugin.add_tag_suffix
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_field_key(field_key)
|
58
|
+
if add_field_prefix?
|
59
|
+
"#{@add_field_prefix}#{field_key}"
|
60
|
+
else
|
61
|
+
field_key
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_field_prefix?
|
66
|
+
!!@add_field_prefix
|
67
|
+
end
|
68
|
+
|
69
|
+
def permit_blank_key?
|
70
|
+
@permit_blank_key
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_query_params(body, record)
|
74
|
+
return if body.nil?
|
75
|
+
body.split('&').each do |pair|
|
76
|
+
key, value = pair.split('=', 2).map { |i| CGI.unescape(i) }
|
77
|
+
next if (key.nil? || key.empty?) && (!permit_blank_key? || value.nil? || value.empty?)
|
78
|
+
key ||= ''
|
79
|
+
value ||= ''
|
80
|
+
|
81
|
+
key = create_field_key(key)
|
82
|
+
if @only
|
83
|
+
record[key] = value if @include_keys.has_key?(key)
|
84
|
+
elsif @except
|
85
|
+
record[key] = value if !@exclude_keys.has_key?(key)
|
86
|
+
else
|
87
|
+
record[key] = value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/test/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fluent/plugin/filter_parse_request_body'
|
3
|
+
|
4
|
+
class ParseRequestBodyFilterTest < Test::Unit::TestCase
|
5
|
+
URL = 'http://example.com:80'
|
6
|
+
BODY_ONLY = {
|
7
|
+
'uid' => 123456,
|
8
|
+
'sid' => '123456fjkjafkjadk',
|
9
|
+
'location' => '134.234,144.333'
|
10
|
+
}
|
11
|
+
|
12
|
+
def setup
|
13
|
+
Fluent::Test.setup
|
14
|
+
@time = Fluent::Engine.now
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_driver(conf)
|
18
|
+
Fluent::Test::Driver::Filter.new(
|
19
|
+
Fluent::Plugin::ParseRequestBodyFilter
|
20
|
+
).configure(conf)
|
21
|
+
end
|
22
|
+
|
23
|
+
def filter(config, messages)
|
24
|
+
d = create_driver(config)
|
25
|
+
d.run(default_tag: "test") {
|
26
|
+
messages.each {|message|
|
27
|
+
d.feed(@time, message)
|
28
|
+
}
|
29
|
+
}
|
30
|
+
d.filtered_records
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_configure
|
34
|
+
d = create_driver(%[
|
35
|
+
key request_body
|
36
|
+
only uid, sid
|
37
|
+
])
|
38
|
+
|
39
|
+
assert_equal 'request_body', d.instance.key
|
40
|
+
assert_equal 'uid, sid', d.instance.only
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_filter
|
44
|
+
config = %[
|
45
|
+
key request_body
|
46
|
+
]
|
47
|
+
|
48
|
+
record = {
|
49
|
+
'request_body' => BODY_ONLY,
|
50
|
+
}
|
51
|
+
expected = {
|
52
|
+
'request_body' => BODY_ONLY,
|
53
|
+
'location' => '134.234,144.333'
|
54
|
+
}
|
55
|
+
filtered = filter(config, [record])
|
56
|
+
assert_equal(expected, filtered[0])
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_filter_with_field_prefix
|
60
|
+
config = %[
|
61
|
+
key request_body
|
62
|
+
add_field_prefix query_
|
63
|
+
]
|
64
|
+
|
65
|
+
record = {
|
66
|
+
'request_body' => BODY_ONLY,
|
67
|
+
}
|
68
|
+
expected = {
|
69
|
+
'request_body' => BODY_ONLY,
|
70
|
+
'query_uid' => 123456,
|
71
|
+
'query_sid' => '123456fjkjafkjadk',
|
72
|
+
'query_location' => '134.234,144.333'
|
73
|
+
}
|
74
|
+
filtered = filter(config, [record])
|
75
|
+
assert_equal(expected, filtered[0])
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_filter_with_only
|
79
|
+
config = %[
|
80
|
+
key request_body
|
81
|
+
only uid, sid
|
82
|
+
]
|
83
|
+
|
84
|
+
record = { 'request_body' => BODY_ONLY }
|
85
|
+
expected = {
|
86
|
+
'request_body' => BODY_ONLY,
|
87
|
+
'uid' => 123456,
|
88
|
+
'sid' => '123456fjkjafkjadk',
|
89
|
+
}
|
90
|
+
filtered = filter(config, [record])
|
91
|
+
assert_equal(expected, filtered[0])
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_filter_with_except
|
95
|
+
config = %[
|
96
|
+
key request_body
|
97
|
+
except uid
|
98
|
+
]
|
99
|
+
|
100
|
+
record = { 'request_body' => BODY_ONLY }
|
101
|
+
expected = {
|
102
|
+
'sid' => '123456fjkjafkjadk',
|
103
|
+
'location' => '134.234,144.333',
|
104
|
+
}
|
105
|
+
filtered = filter(config, [record])
|
106
|
+
assert_equal(expected, filtered[0])
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_filter_with_discard
|
110
|
+
config = %[
|
111
|
+
key url
|
112
|
+
discard_key true
|
113
|
+
]
|
114
|
+
|
115
|
+
record = { 'request_body' => BODY_ONLY }
|
116
|
+
expected = {
|
117
|
+
'uid' => 123456,
|
118
|
+
'sid' => '123456fjkjafkjadk',
|
119
|
+
'location' => '134.234,144.333'
|
120
|
+
}
|
121
|
+
filtered = filter(config, [record])
|
122
|
+
assert_equal(expected, filtered[0])
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_filter_multi_records
|
126
|
+
config = %[
|
127
|
+
key request_body
|
128
|
+
only uid, sid
|
129
|
+
]
|
130
|
+
records = [
|
131
|
+
{ 'request_body' => BODY_ONLY },
|
132
|
+
{ 'request_body' => BODY_ONLY },
|
133
|
+
{ 'request_body' => BODY_ONLY }
|
134
|
+
]
|
135
|
+
expected = [
|
136
|
+
{ 'request_body' => BODY_ONLY, 'uid' => 123456, 'sid' => '123456fjkjafkjadk' },
|
137
|
+
{ 'request_body' => BODY_ONLY, 'uid' => 123456, 'sid' => '123456fjkjafkjadk' },
|
138
|
+
{ 'request_body' => BODY_ONLY, 'uid' => 123456, 'sid' => '123456fjkjafkjadk' }
|
139
|
+
]
|
140
|
+
filtered = filter(config, records)
|
141
|
+
assert_equal(expected, filtered)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_emit_without_match_key
|
145
|
+
config = %[
|
146
|
+
key no_such_key
|
147
|
+
only uid, sid
|
148
|
+
]
|
149
|
+
record = { 'request_body' => BODY_ONLY }
|
150
|
+
filtered = filter(config, [record])
|
151
|
+
assert_equal(record, filtered[0])
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_emit_with_invalid_url
|
155
|
+
config = %[
|
156
|
+
key request_body
|
157
|
+
]
|
158
|
+
record = { 'request_body' => BODY_ONLY }
|
159
|
+
filtered = filter(config, [record])
|
160
|
+
assert_equal([record], filtered)
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fluent/plugin/out_parse_request_body'
|
3
|
+
|
4
|
+
class ParseRequestBodyOutputTest < Test::Unit::TestCase
|
5
|
+
URL = 'http://example.com:80'
|
6
|
+
BODY_ONLY = {
|
7
|
+
'uid' => 123456,
|
8
|
+
'sid' => '123456fjkjafkjadk',
|
9
|
+
'location' => '134.234,144.333'
|
10
|
+
}
|
11
|
+
|
12
|
+
def setup
|
13
|
+
Fluent::Test.setup
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_driver(conf)
|
17
|
+
Fluent::Test::Driver::Output.new(
|
18
|
+
Fluent::Plugin::ParseRequestBodyOutput
|
19
|
+
).configure(conf)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_configure
|
23
|
+
d = create_driver(%[
|
24
|
+
key request_body
|
25
|
+
add_tag_prefix extracted.
|
26
|
+
only uid, sid
|
27
|
+
])
|
28
|
+
|
29
|
+
assert_equal 'request_body', d.instance.key
|
30
|
+
assert_equal 'extracted.', d.instance.add_tag_prefix
|
31
|
+
assert_equal 'uid, sid', d.instance.only
|
32
|
+
|
33
|
+
# when mandatory keys not set
|
34
|
+
assert_raise(Fluent::ConfigError) do
|
35
|
+
create_driver(%[
|
36
|
+
key uid
|
37
|
+
])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_filter_record
|
42
|
+
d = create_driver(%[
|
43
|
+
key request_body
|
44
|
+
add_tag_prefix extracted.
|
45
|
+
])
|
46
|
+
|
47
|
+
record = {
|
48
|
+
'request_body' => BODY_ONLY,
|
49
|
+
}
|
50
|
+
d.instance.filter_record('test', Time.now, record)
|
51
|
+
|
52
|
+
assert_equal BODY_ONLY, record['request_body']
|
53
|
+
assert_equal 123456, record['uid']
|
54
|
+
assert_equal '123456fjkjafkjadk', record['sid']
|
55
|
+
assert_equal '134.234,144.333', record['location']
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_filter_record_with_field_prefix
|
59
|
+
d = create_driver(%[
|
60
|
+
key request_body
|
61
|
+
add_field_prefix query_
|
62
|
+
add_tag_prefix extracted.
|
63
|
+
])
|
64
|
+
|
65
|
+
record = {
|
66
|
+
'request_body' => BODY_ONLY,
|
67
|
+
}
|
68
|
+
d.instance.filter_record('test', Time.now, record)
|
69
|
+
|
70
|
+
assert_equal BODY_ONLY, record['request_body']
|
71
|
+
assert_nil record['uid']
|
72
|
+
assert_nil record['sid']
|
73
|
+
assert_nil record['location']
|
74
|
+
assert_equal 123456, record['query_uid']
|
75
|
+
assert_equal '123456fjkjafkjadk', record['query_sid']
|
76
|
+
assert_equal '134.234,144.333', record['query_location']
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_filter_record_with_only
|
80
|
+
d = create_driver(%[
|
81
|
+
key request_body
|
82
|
+
add_tag_prefix extracted.
|
83
|
+
only uid, sid
|
84
|
+
])
|
85
|
+
|
86
|
+
record = { 'request_body' => BODY_ONLY }
|
87
|
+
d.instance.filter_record('test', Time.now, record)
|
88
|
+
|
89
|
+
assert_equal BODY_ONLY, record['request_body']
|
90
|
+
assert_equal 123456, record['uid']
|
91
|
+
assert_equal '123456fjkjafkjadk', record['sid']
|
92
|
+
assert_nil record['location']
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_filter_record_with_except
|
96
|
+
d = create_driver(%[
|
97
|
+
key request_body
|
98
|
+
add_tag_prefix extracted.
|
99
|
+
except baz, モリス
|
100
|
+
])
|
101
|
+
|
102
|
+
record = { 'request_body' => BODY_ONLY }
|
103
|
+
d.instance.filter_record('test', Time.now, record)
|
104
|
+
|
105
|
+
assert_equal BODY_ONLY, record['request_body']
|
106
|
+
assert_equal 123456, record['uid']
|
107
|
+
assert_nil record['sid']
|
108
|
+
assert_nil record['location']
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_filter_record_with_discard
|
112
|
+
d = create_driver(%[
|
113
|
+
key request_body
|
114
|
+
add_tag_prefix extracted.
|
115
|
+
discard_key true
|
116
|
+
])
|
117
|
+
|
118
|
+
record = { 'request_body' => BODY_ONLY }
|
119
|
+
d.instance.filter_record('test', Time.now, record)
|
120
|
+
|
121
|
+
assert_nil record['nil']
|
122
|
+
assert_nil record['request_body']
|
123
|
+
assert_equal 123456, record['uid']
|
124
|
+
assert_equal '123456fjkjafkjadk', record['sid']
|
125
|
+
assert_equal '134.234,144.333', record['location']
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_emit
|
129
|
+
d = create_driver(%[
|
130
|
+
key request_body
|
131
|
+
add_tag_prefix extracted.
|
132
|
+
only uid, sid
|
133
|
+
])
|
134
|
+
d.run(default_tag: "test") { d.feed('request_body' => BODY_ONLY) }
|
135
|
+
events = d.events
|
136
|
+
|
137
|
+
assert_equal 1, events.count
|
138
|
+
assert_equal 'extracted.test', events[0][0]
|
139
|
+
assert_equal BODY_ONLY, events[0][2]['request_body']
|
140
|
+
assert_equal 123456, events[0][2]['uid']
|
141
|
+
assert_equal '123456fjkjafkjadk', events[0][2]['sid']
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_emit_multi
|
145
|
+
d = create_driver(%[
|
146
|
+
key request_body
|
147
|
+
add_tag_prefix extracted.
|
148
|
+
only uid, sid
|
149
|
+
])
|
150
|
+
d.run(default_tag: "test") do
|
151
|
+
d.feed('request_body' => BODY_ONLY)
|
152
|
+
d.feed('request_body' => BODY_ONLY)
|
153
|
+
d.feed('request_body' => BODY_ONLY)
|
154
|
+
end
|
155
|
+
events = d.events
|
156
|
+
|
157
|
+
assert_equal 3, events.count
|
158
|
+
|
159
|
+
events.each do |e|
|
160
|
+
assert_equal 'extracted.test', e[0]
|
161
|
+
assert_equal BODY_ONLY, e[2]['request_body']
|
162
|
+
assert_equal 123456, e[2]['uid']
|
163
|
+
assert_equal '123456fjkjafkjadk', e[2]['sid']
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_emit_without_match_key
|
168
|
+
d = create_driver(%[
|
169
|
+
key no_such_key
|
170
|
+
add_tag_prefix extracted.
|
171
|
+
only uid, sid
|
172
|
+
])
|
173
|
+
d.run(default_tag: "test") { d.feed('request_body' => BODY_ONLY) }
|
174
|
+
events = d.events
|
175
|
+
|
176
|
+
assert_equal 1, events.count
|
177
|
+
assert_equal 'extracted.test', events[0][0]
|
178
|
+
assert_equal BODY_ONLY, events[0][2]['request_body']
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_emit_with_invalid_url
|
182
|
+
d = create_driver(%[
|
183
|
+
key request_body
|
184
|
+
add_tag_prefix extracted.
|
185
|
+
])
|
186
|
+
d.run(default_tag: "test") { d.feed('request_body' => 'invalid url') }
|
187
|
+
events = d.events
|
188
|
+
|
189
|
+
assert_equal 1, events.count
|
190
|
+
assert_equal 'extracted.test', events[0][0]
|
191
|
+
assert_equal 'invalid url', events[0][2]['request_body']
|
192
|
+
end
|
193
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-parse_request_body
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- EkiSong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fluentd
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.14.8
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '2'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 0.14.8
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2'
|
61
|
+
description: Fluentd plugin to parse request body.
|
62
|
+
email:
|
63
|
+
- yifriday0614@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- ".travis.yml"
|
70
|
+
- Appraisals
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- fluent-plugin-parse_request_body.gemspec
|
76
|
+
- gemfiles/fluentd_0.14.gemfile
|
77
|
+
- lib/fluent/plugin/filter_parse_request_body.rb
|
78
|
+
- lib/fluent/plugin/out_parse_request_body.rb
|
79
|
+
- lib/fluent/plugin/parse_request_body_extractor.rb
|
80
|
+
- test/.DS_Store
|
81
|
+
- test/plugin/test_filter_parse_request_body.rb
|
82
|
+
- test/plugin/test_out_parse_request_body.rb
|
83
|
+
- test/test_helper.rb
|
84
|
+
homepage: https://github.com/yifriday/fluent-plugin-parse_request_body.git
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.7.7
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Fluentd plugin to parse request body
|
108
|
+
test_files:
|
109
|
+
- test/.DS_Store
|
110
|
+
- test/plugin/test_filter_parse_request_body.rb
|
111
|
+
- test/plugin/test_out_parse_request_body.rb
|
112
|
+
- test/test_helper.rb
|