Class: Fluent::HTTPOutput

Inherits:
ObjectBufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_http.rb,
lib/fluent/plugin/http/error.rb

Overview

The out_http buffered output plugin sends event records via HTTP.

Constant Summary collapse

ResponseError =

Unsuccessful response error

Class.new(StandardError) do
  def self.error(request, response)
    new "Failed to POST event records to #{request.uri} because of " \
        "unsuccessful response code: #{response.code.inspect} " \
        "#{response.body.inspect}"
  end
end

Instance Method Summary collapse

Constructor Details

#initializeHTTPOutput

Returns a new instance of HTTPOutput.



32
33
34
35
36
# File 'lib/fluent/plugin/out_http.rb', line 32

def initialize
  require 'fluent/plugin/http/error'

  super
end

Instance Method Details

#configure(conf) ⇒ Object

Configures the plugin

Parameters:

  • conf (Hash)

    the plugin configuration

Returns:

  • void



42
43
44
45
46
47
48
49
50
51
# File 'lib/fluent/plugin/out_http.rb', line 42

def configure(conf)
  super

  @url = validate_url(url)
  @accept_status_code = validate_accept_status_code(accept_status_code)
  @authorization_token = validate_authorization_token(authorization_token)
  @keep_alive_timeout = validate_keep_alive_timeout(keep_alive_timeout)
  @username = validate_username(username)
  @password = validate_password(password)
end

#format(tag, time, record) ⇒ String

Serializes the event

Parameters:

  • tag (#to_msgpack)

    the event tag

  • time (#to_msgpack)

    the event timestamp

  • record (#to_msgpack)

    the event record

Returns:

  • (String)

    serialized event



68
69
70
# File 'lib/fluent/plugin/out_http.rb', line 68

def format(tag, time, record)
  [tag, time, record].to_msgpack
end

#shutdownObject

Hook method that is called at the shutdown

Returns:

  • void



56
57
58
59
60
# File 'lib/fluent/plugin/out_http.rb', line 56

def shutdown
  super

  disconnect
end

#write(chunk) ⇒ Object

Sends the event records

Parameters:

  • chunk (#msgpack_each)

    buffer chunk that includes multiple formatted events

Returns:

  • void



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fluent/plugin/out_http.rb', line 77

def write(chunk)
  return if chunk.empty?

  records = []

  chunk.msgpack_each do |tag_time_record|
    records << (_record = tag_time_record.last)
  end

  post_records = post_records_request(records)
  response = connect.request(post_records)

  return if accept_status_code.include?(response.code)

  raise ResponseError.error(post_records, response)
end