fluent-plugin-out-http 1.1.1 → 1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +1 -0
- data/fluent-plugin-out-http.gemspec +1 -1
- data/lib/fluent/plugin/out_http.rb +26 -2
- data/test/plugin/test_out_http.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6816aa0fc629f6b264dce12602cdd716577350c2e65c05c6cb1d97c51b95f34
|
4
|
+
data.tar.gz: 3db9d8d0c757b307f53abb6fcc4e84d7dd3f4c84232409fc075c225821a38300
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16c16745835465635955c5d86d52c5c0be5d3c887002db36e74206f12059b514be37ed99003ef8c86f508f316984cad27f9c71a826511d089c977fce5ef0b7d8
|
7
|
+
data.tar.gz: 2322d4d8ffc7a79abcb3905fd36486e1f939ed0b36a425876faf43e9fd9d8bd1ca7b0bb2eb0a8d5d6f71859fb94003fcd9a18c7647e64c5a76d69e624afd85e2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -19,6 +19,7 @@ A generic [fluentd][1] output plugin for sending logs to an HTTP endpoint.
|
|
19
19
|
buffered true # default: false. Switch non-buffered/buffered mode
|
20
20
|
cacert_file /etc/ssl/endpoint1.cert # default: ''
|
21
21
|
token tokent # default: ''
|
22
|
+
custom_headers {"token":"arbitrary"} # default: nil
|
22
23
|
</match>
|
23
24
|
|
24
25
|
## Usage notes
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "fluent-plugin-out-http"
|
5
|
-
gem.version = "1.1.
|
5
|
+
gem.version = "1.1.2"
|
6
6
|
gem.authors = ["Marica Odagaki"]
|
7
7
|
gem.email = ["ento.entotto@gmail.com"]
|
8
8
|
gem.summary = %q{A generic Fluentd output plugin to send logs to an HTTP endpoint}
|
@@ -36,6 +36,9 @@ class Fluent::Plugin::HTTPOutput < Fluent::Plugin::Output
|
|
36
36
|
# ca file to use for https request
|
37
37
|
config_param :cacert_file, :string, :default => ''
|
38
38
|
|
39
|
+
# custom headers
|
40
|
+
config_param :custom_headers, :hash, :default => nil
|
41
|
+
|
39
42
|
# 'none' | 'basic' | 'jwt' | 'bearer'
|
40
43
|
config_param :authentication, :enum, list: [:none, :basic, :jwt, :bearer], :default => :none
|
41
44
|
config_param :username, :string, :default => ''
|
@@ -88,7 +91,14 @@ class Fluent::Plugin::HTTPOutput < Fluent::Plugin::Output
|
|
88
91
|
end
|
89
92
|
|
90
93
|
def set_header(req, tag, time, record)
|
91
|
-
|
94
|
+
if @custom_headers
|
95
|
+
@custom_headers.each do |k,v|
|
96
|
+
req[k] = v
|
97
|
+
end
|
98
|
+
req
|
99
|
+
else
|
100
|
+
req
|
101
|
+
end
|
92
102
|
end
|
93
103
|
|
94
104
|
def set_json_body(req, data)
|
@@ -119,6 +129,10 @@ class Fluent::Plugin::HTTPOutput < Fluent::Plugin::Output
|
|
119
129
|
opts
|
120
130
|
end
|
121
131
|
|
132
|
+
def proxies
|
133
|
+
ENV['HTTPS_PROXY'] || ENV['HTTP_PROXY'] || ENV['http_proxy'] || ENV['https_proxy']
|
134
|
+
end
|
135
|
+
|
122
136
|
def send_request(req, uri)
|
123
137
|
is_rate_limited = (@rate_limit_msec != 0 and not @last_request_time.nil?)
|
124
138
|
if is_rate_limited and ((Time.now.to_f - @last_request_time) * 1000.0 < @rate_limit_msec)
|
@@ -137,7 +151,17 @@ class Fluent::Plugin::HTTPOutput < Fluent::Plugin::Output
|
|
137
151
|
req['authorization'] = "jwt #{@token}"
|
138
152
|
end
|
139
153
|
@last_request_time = Time.now.to_f
|
140
|
-
|
154
|
+
|
155
|
+
if proxy = proxies
|
156
|
+
proxy_uri = URI.parse(proxy)
|
157
|
+
|
158
|
+
res = Net::HTTP.start(uri.host, uri.port,
|
159
|
+
proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password,
|
160
|
+
**http_opts(uri)) {|http| http.request(req) }
|
161
|
+
else
|
162
|
+
res = Net::HTTP.start(uri.host, uri.port, **http_opts(uri)) {|http| http.request(req) }
|
163
|
+
end
|
164
|
+
|
141
165
|
rescue => e # rescue all StandardErrors
|
142
166
|
# server didn't respond
|
143
167
|
log.warn "Net::HTTP.#{req.method.capitalize} raises exception: #{e.class}, '#{e.message}'"
|
@@ -56,6 +56,7 @@ class HTTPOutputTestBase < Test::Unit::TestCase
|
|
56
56
|
@prohibited = 0
|
57
57
|
@requests = 0
|
58
58
|
@auth = false
|
59
|
+
@headers = {}
|
59
60
|
@dummy_server_thread = Thread.new do
|
60
61
|
srv = WEBrick::HTTPServer.new(self.class.server_config)
|
61
62
|
begin
|
@@ -67,6 +68,9 @@ class HTTPOutputTestBase < Test::Unit::TestCase
|
|
67
68
|
res.body = 'request method mismatch'
|
68
69
|
next
|
69
70
|
end
|
71
|
+
req.each do |key, value|
|
72
|
+
@headers[key] = value
|
73
|
+
end
|
70
74
|
if @auth and req.header['authorization'][0] == 'Basic YWxpY2U6c2VjcmV0IQ==' # pattern of user='alice' passwd='secret!'
|
71
75
|
# ok, authorized
|
72
76
|
# pattern of bear #{Base64.encode64('secret token!')}
|
@@ -280,6 +284,34 @@ class HTTPOutputTest < HTTPOutputTestBase
|
|
280
284
|
assert_equal 2, @posts.size
|
281
285
|
end
|
282
286
|
|
287
|
+
def test_emit_form_with_custom_headers
|
288
|
+
d = create_driver CONFIG + %[custom_headers {"key":"custom","token":"arbitrary"}]
|
289
|
+
d.run(default_tag: 'test.metrics') do
|
290
|
+
d.feed({ 'field1' => 50, 'field2' => 20, 'field3' => 10, 'otherfield' => 1, 'binary' => "\xe3\x81\x82".force_encoding("ascii-8bit") })
|
291
|
+
end
|
292
|
+
|
293
|
+
assert_true @headers.has_key?("key")
|
294
|
+
assert_equal "custom", @headers["key"]
|
295
|
+
assert_true @headers.has_key?("token")
|
296
|
+
assert_equal "arbitrary", @headers["token"]
|
297
|
+
|
298
|
+
assert_equal 1, @posts.size
|
299
|
+
record = @posts[0]
|
300
|
+
|
301
|
+
assert_equal '50', record[:form]['field1']
|
302
|
+
assert_equal '20', record[:form]['field2']
|
303
|
+
assert_equal '10', record[:form]['field3']
|
304
|
+
assert_equal '1', record[:form]['otherfield']
|
305
|
+
assert_equal URI.encode_www_form_component("あ").upcase, record[:form]['binary'].upcase
|
306
|
+
assert_nil record[:auth]
|
307
|
+
|
308
|
+
d.run(default_tag: 'test.metrics') do
|
309
|
+
d.feed({ 'field1' => 50, 'field2' => 20, 'field3' => 10, 'otherfield' => 1 })
|
310
|
+
end
|
311
|
+
|
312
|
+
assert_equal 2, @posts.size
|
313
|
+
end
|
314
|
+
|
283
315
|
class BufferedEmitTest < self
|
284
316
|
def test_emit_form
|
285
317
|
d = create_driver CONFIG + %[buffered true]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-out-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marica Odagaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yajl-ruby
|