class Fluent::HatoOutput

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_hato.rb, line 16
def configure(conf)
  super

  if @api_key.nil?
    raise Fluent::ConfigError(
      '[out_hato] missing mandatory parameter: `api_key`'
    )
  end

  if @host.nil?
    raise Fluent::ConfigError(
      '[out_hato] missing mandatory parameter: `host`'
    )
  end

  @api_endpoint = '%s://%s:%s/notify' % [
    @scheme,
    @host,
    @port,
  ]
end
emit(tag, es, chain) click to toggle source
# File lib/fluent/plugin/out_hato.rb, line 38
def emit(tag, es, chain)
  es.each do |time, record|
    message = message_format % message_keys.split(/\s*,\s*/).map do |key|
      record[key].to_s
    end
    send_message(tag, message)
  end
end

Private Instance Methods

send_message(tag, message) click to toggle source
# File lib/fluent/plugin/out_hato.rb, line 49
def send_message(tag, message)
  begin
    res = send_request(tag, message)
    res.value
  rescue => e
    $log.warn("[out_hato] failed to send a message tagged with #{tag} to #{scheme}://#{@host}:#{port} for the reason '#{e.message}'")
  end
end
send_request(tag, message) click to toggle source
# File lib/fluent/plugin/out_hato.rb, line 58
def send_request(tag, message)
  http = Net::HTTP.new(URI(@api_endpoint).host, URI(@api_endpoint).port)
  req  = Net::HTTP::Post.new(URI(@api_endpoint).path)

  req.form_data = {
    'tag'     => tag,
    'message' => message,
    'api_key' => @api_key,
  }

  http.request(req)
end