fluent-plugin-http 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fluent/plugin/out_http.rb +34 -11
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ff8a75bb999e8eb4e1880f79bad4d04313c9627
4
- data.tar.gz: 4853f237fd8ea659fbf11bc4c7f5eba9950d86cc
3
+ metadata.gz: e6be21a1fe25c537139150f938f6dfdbef1fb7f5
4
+ data.tar.gz: 3b45cfa458337d855d26b09d0314f0458364d453
5
5
  SHA512:
6
- metadata.gz: 1dd4afae7e9c857b78290fc4bc348bb05515d27334ec2ed30a03f12cb43d19272e9e7b5bb9b3a91c6b304240b670798eb20b92dbfe65b0594bd0a07a914d2e35
7
- data.tar.gz: 586c01adbcff6879b71345a6a8888e70398afabb176a273e3f4afb13c71db1d50a408c5cfcee2cbbf90a49bdab30fdfcc8436b4b2bcaa58fcfe00e634df7e2ff
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 = URI(conf.fetch('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
- SUCCESSFUL_RESPONSE_CODE_PREFIX = '2'
68
- private_constant :SUCCESSFUL_RESPONSE_CODE_PREFIX
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.start_with?(SUCCESSFUL_RESPONSE_CODE_PREFIX)
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.1.1
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-06 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd