fluent-plugin-http 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3ff8a75bb999e8eb4e1880f79bad4d04313c9627
4
+ data.tar.gz: 4853f237fd8ea659fbf11bc4c7f5eba9950d86cc
5
+ SHA512:
6
+ metadata.gz: 1dd4afae7e9c857b78290fc4bc348bb05515d27334ec2ed30a03f12cb43d19272e9e7b5bb9b3a91c6b304240b670798eb20b92dbfe65b0594bd0a07a914d2e35
7
+ data.tar.gz: 586c01adbcff6879b71345a6a8888e70398afabb176a273e3f4afb13c71db1d50a408c5cfcee2cbbf90a49bdab30fdfcc8436b4b2bcaa58fcfe00e634df7e2ff
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ module Fluent
3
+ class HTTPOutput
4
+ # Unsuccessful response error
5
+ ResponseError = Class.new(StandardError) do
6
+ def self.error(request, response)
7
+ new "Failed to POST event record to #{request.uri} because of " \
8
+ "unsuccessful response code: #{response.code.inspect} " \
9
+ "#{response.body.inspect}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+ require 'fluent/output'
3
+ require 'uri'
4
+ require 'net/http'
5
+
6
+ # Fluentd
7
+ module Fluent
8
+ # The out_http buffered output plugin sends event records via HTTP.
9
+ class HTTPOutput < BufferedOutput
10
+ Fluent::Plugin.register_output('http', self)
11
+
12
+ desc 'The URL to send event records to'
13
+ config_param :url, :string
14
+
15
+ def initialize
16
+ require 'fluent/plugin/http/error'
17
+
18
+ super
19
+ end
20
+
21
+ # Configures the plugin
22
+ #
23
+ # @param conf [Hash] the plugin configuration
24
+ # @return void
25
+ def configure(conf)
26
+ super
27
+
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
36
+ end
37
+
38
+ # Hook method that is called at the startup
39
+ #
40
+ # @return void
41
+ def start
42
+ super
43
+
44
+ is_https = url.scheme == 'https'
45
+ @http = Net::HTTP.start(url.host, url.port, use_ssl: is_https)
46
+ end
47
+
48
+ # Hook method that is called at the shutdown
49
+ #
50
+ # @return void
51
+ def shutdown
52
+ super
53
+
54
+ http.finish
55
+ end
56
+
57
+ # Serializes the event
58
+ #
59
+ # @param tag [#to_msgpack] the event tag
60
+ # @param time [#to_msgpack] the event timestamp
61
+ # @param record [#to_msgpack] the event record
62
+ # @return [String] serialized event
63
+ def format(tag, time, record)
64
+ [tag, time, record].to_msgpack
65
+ end
66
+
67
+ SUCCESSFUL_RESPONSE_CODE_PREFIX = '2'
68
+ private_constant :SUCCESSFUL_RESPONSE_CODE_PREFIX
69
+
70
+ # Sends the event records
71
+ #
72
+ # @param chunk [#msgpack_each] buffer chunk that includes multiple
73
+ # formatted events
74
+ # @return void
75
+ def write(chunk)
76
+ chunk.msgpack_each do |_tag, _time, record|
77
+ post_record = Net::HTTP::Post.new(url)
78
+ post_record.set_form_data(record)
79
+
80
+ response = http.request(post_record)
81
+
82
+ unless response.code.start_with?(SUCCESSFUL_RESPONSE_CODE_PREFIX)
83
+ raise ResponseError.error(post_record, response)
84
+ end
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ attr_reader :http
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.45'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.45'
111
+ description:
112
+ email:
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - lib/fluent/plugin/http/error.rb
118
+ - lib/fluent/plugin/out_http.rb
119
+ homepage:
120
+ licenses:
121
+ - Apache-2.0
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.6.6
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Fluentd output plugin that sends event records via HTTP
143
+ test_files: []