Class: Fluent::Plugin::HTTPOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::HTTPOutput
- Defined in:
- lib/fluent/plugin/out_http.rb
Constant Summary collapse
- DEFAULT_BUFFER_TYPE =
"memory"
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #create_request(tag, time, record) ⇒ Object
- #format(tag, time, record) ⇒ Object
- #format_url(tag, time, record) ⇒ Object
- #formatted_to_msgpack_binary? ⇒ Boolean
-
#handle_record(tag, time, record) ⇒ Object
end send_request.
- #http_opts(uri) ⇒ Object
-
#initialize ⇒ HTTPOutput
constructor
A new instance of HTTPOutput.
- #multi_workers_ready? ⇒ Boolean
- #prefer_buffered_processing ⇒ Object
- #process(tag, es) ⇒ Object
- #send_request(req, uri) ⇒ Object
- #set_body(req, tag, time, record) ⇒ Object
- #set_header(req, tag, time, record) ⇒ Object
- #set_json_body(req, data) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ HTTPOutput
Returns a new instance of HTTPOutput.
13 14 15 |
# File 'lib/fluent/plugin/out_http.rb', line 13 def initialize super end |
Instance Method Details
#configure(conf) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fluent/plugin/out_http.rb', line 48 def configure(conf) compat_parameters_convert(conf, :buffer) super @ssl_verify_mode = if @ssl_no_verify OpenSSL::SSL::VERIFY_NONE else OpenSSL::SSL::VERIFY_PEER end @last_request_time = nil raise Fluent::ConfigError, "'tag' in chunk_keys is required." if !@chunk_key_tag && @buffered end |
#create_request(tag, time, record) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/fluent/plugin/out_http.rb', line 92 def create_request(tag, time, record) url = format_url(tag, time, record) uri = URI.parse(url) req = Net::HTTP.const_get(@http_method.to_s.capitalize).new(uri.path) set_body(req, tag, time, record) set_header(req, tag, time, record) return req, uri end |
#format(tag, time, record) ⇒ Object
149 150 151 |
# File 'lib/fluent/plugin/out_http.rb', line 149 def format(tag, time, record) [time, record].to_msgpack end |
#format_url(tag, time, record) ⇒ Object
70 71 72 |
# File 'lib/fluent/plugin/out_http.rb', line 70 def format_url(tag, time, record) @endpoint_url end |
#formatted_to_msgpack_binary? ⇒ Boolean
153 154 155 |
# File 'lib/fluent/plugin/out_http.rb', line 153 def formatted_to_msgpack_binary? true end |
#handle_record(tag, time, record) ⇒ Object
end send_request
140 141 142 143 |
# File 'lib/fluent/plugin/out_http.rb', line 140 def handle_record(tag, time, record) req, uri = create_request(tag, time, record) send_request(req, uri) end |
#http_opts(uri) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/fluent/plugin/out_http.rb', line 101 def http_opts(uri) opts = { :use_ssl => uri.scheme == 'https' } opts[:verify_mode] = @ssl_verify_mode if opts[:use_ssl] opts end |
#multi_workers_ready? ⇒ Boolean
157 158 159 |
# File 'lib/fluent/plugin/out_http.rb', line 157 def multi_workers_ready? true end |
#prefer_buffered_processing ⇒ Object
145 146 147 |
# File 'lib/fluent/plugin/out_http.rb', line 145 def prefer_buffered_processing @buffered end |
#process(tag, es) ⇒ Object
161 162 163 164 165 |
# File 'lib/fluent/plugin/out_http.rb', line 161 def process(tag, es) es.each do |time, record| handle_record(tag, time, record) end end |
#send_request(req, uri) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/fluent/plugin/out_http.rb', line 109 def send_request(req, uri) is_rate_limited = (@rate_limit_msec != 0 and not @last_request_time.nil?) if is_rate_limited and ((Time.now.to_f - @last_request_time) * 1000.0 < @rate_limit_msec) log.info('Dropped request due to rate limiting') return end res = nil begin if @authentication == :basic req.basic_auth(@username, @password) end @last_request_time = Time.now.to_f res = Net::HTTP.start(uri.host, uri.port, **http_opts(uri)) {|http| http.request(req) } rescue => e # rescue all StandardErrors # server didn't respond log.warn "Net::HTTP.#{req.method.capitalize} raises exception: #{e.class}, '#{e.}'" raise e if @raise_on_error else unless res and res.is_a?(Net::HTTPSuccess) res_summary = if res "#{res.code} #{res.} #{res.body}" else "res=nil" end log.warn "failed to #{req.method} #{uri} (#{res_summary})" end #end unless end # end begin end |
#set_body(req, tag, time, record) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/fluent/plugin/out_http.rb', line 74 def set_body(req, tag, time, record) if @serializer == :json set_json_body(req, record) else req.set_form_data(record) end req end |
#set_header(req, tag, time, record) ⇒ Object
83 84 85 |
# File 'lib/fluent/plugin/out_http.rb', line 83 def set_header(req, tag, time, record) req end |
#set_json_body(req, data) ⇒ Object
87 88 89 90 |
# File 'lib/fluent/plugin/out_http.rb', line 87 def set_json_body(req, data) req.body = Yajl.dump(data) req['Content-Type'] = 'application/json' end |
#shutdown ⇒ Object
66 67 68 |
# File 'lib/fluent/plugin/out_http.rb', line 66 def shutdown super end |
#start ⇒ Object
62 63 64 |
# File 'lib/fluent/plugin/out_http.rb', line 62 def start super end |
#write(chunk) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/fluent/plugin/out_http.rb', line 167 def write(chunk) tag = chunk..tag @endpoint_url = extract_placeholders(@endpoint_url, chunk.) chunk.msgpack_each do |time, record| handle_record(tag, time, record) end end |