fluent-plugin-http 0.1.1 → 0.2.0
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/lib/fluent/plugin/out_http.rb +34 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6be21a1fe25c537139150f938f6dfdbef1fb7f5
|
4
|
+
data.tar.gz: 3b45cfa458337d855d26b09d0314f0458364d453
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cabba8b61a03f4750e180bd8c1acfb85af5fc6335e2229cc51ef6139c16b73aee531e0985e0aaa332b310ccf82478a7321e0b6eba7ca6e3c5ffab9a9b73f68dc
|
7
|
+
data.tar.gz: 0d262e0ae06054e832797f3bbeab5a6f109f23c41b8ab03d0ad12cd2459457d8290d18c36296ccbd6d5d9c1dc406cb07b23fed9d9a770a02e8ac5f48148c42e1
|
@@ -12,6 +12,9 @@ module Fluent
|
|
12
12
|
desc 'The URL to send event records to'
|
13
13
|
config_param :url, :string
|
14
14
|
|
15
|
+
desc 'The acceptable response status code'
|
16
|
+
config_param :accept_status_code, :array, default: ['200']
|
17
|
+
|
15
18
|
def initialize
|
16
19
|
require 'fluent/plugin/http/error'
|
17
20
|
|
@@ -25,14 +28,8 @@ module Fluent
|
|
25
28
|
def configure(conf)
|
26
29
|
super
|
27
30
|
|
28
|
-
@url =
|
29
|
-
|
30
|
-
unless @url.scheme == 'http' || @url.scheme == 'https'
|
31
|
-
raise Fluent::ConfigError,
|
32
|
-
"Unacceptable URL scheme, expected HTTP or HTTPs: #{@url}"
|
33
|
-
end
|
34
|
-
rescue URI::InvalidURIError => invalid_uri_error
|
35
|
-
raise Fluent::ConfigError, invalid_uri_error
|
31
|
+
@url = validate_url(url)
|
32
|
+
@accept_status_code = validate_accept_status_code(accept_status_code)
|
36
33
|
end
|
37
34
|
|
38
35
|
# Hook method that is called at the startup
|
@@ -64,8 +61,8 @@ module Fluent
|
|
64
61
|
[tag, time, record].to_msgpack
|
65
62
|
end
|
66
63
|
|
67
|
-
|
68
|
-
private_constant :
|
64
|
+
USER_AGENT = 'FluentPluginHTTP'
|
65
|
+
private_constant :USER_AGENT
|
69
66
|
|
70
67
|
# Sends the event records
|
71
68
|
#
|
@@ -76,10 +73,11 @@ module Fluent
|
|
76
73
|
chunk.msgpack_each do |_tag, _time, record|
|
77
74
|
post_record = Net::HTTP::Post.new(url)
|
78
75
|
post_record.set_form_data(record)
|
76
|
+
post_record['User-Agent'] = USER_AGENT
|
79
77
|
|
80
78
|
response = http.request(post_record)
|
81
79
|
|
82
|
-
unless response.code
|
80
|
+
unless accept_status_code.include?(response.code)
|
83
81
|
raise ResponseError.error(post_record, response)
|
84
82
|
end
|
85
83
|
end
|
@@ -88,5 +86,30 @@ module Fluent
|
|
88
86
|
private
|
89
87
|
|
90
88
|
attr_reader :http
|
89
|
+
|
90
|
+
def validate_url(test_url)
|
91
|
+
url = URI(test_url)
|
92
|
+
return url if url.scheme == 'http' || url.scheme == 'https'
|
93
|
+
|
94
|
+
raise Fluent::ConfigError,
|
95
|
+
"Unacceptable URL scheme, expected HTTP or HTTPs: #{test_url}"
|
96
|
+
rescue URI::InvalidURIError => invalid_uri_error
|
97
|
+
raise Fluent::ConfigError, invalid_uri_error
|
98
|
+
end
|
99
|
+
|
100
|
+
def validate_accept_status_code(status_codes)
|
101
|
+
if !status_codes.empty? && status_codes.all?(&method(:http_status_code?))
|
102
|
+
return status_codes
|
103
|
+
end
|
104
|
+
|
105
|
+
raise Fluent::ConfigError, "Invalid status codes: #{status_codes.inspect}"
|
106
|
+
end
|
107
|
+
|
108
|
+
HTTP_STATUS_CODE_RANGE = (100...600).freeze
|
109
|
+
private_constant :HTTP_STATUS_CODE_RANGE
|
110
|
+
|
111
|
+
def http_status_code?(code)
|
112
|
+
HTTP_STATUS_CODE_RANGE.cover?(code.to_i)
|
113
|
+
end
|
91
114
|
end
|
92
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|