class Fluent::LineNotifyOutput

Public Instance Methods

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

  @erb = ERB.new(@message_template)
end
emit(tag, es, chain) click to toggle source
# File lib/fluent/plugin/out_line_notify.rb, line 31
def emit(tag, es, chain)
  es.each do |time, record|
    t = Templater.new
    t.tag = tag
    t.time = time
    t.record = record
    msg = t.result(@erb)

    begin
      resp = HTTParty.post(
        @api_url,
        headers: {
          'Authorization' => "Bearer #{@access_token}",
          'Content-Type' => 'application/x-www-form-urlencoded',
        },
        body: "message=#{CGI.escape(msg)}"
      )
      raise resp.message if resp.code != 200
    rescue
      $log.warn "raises exception: #{$!.class}, '#{$!.message}, #{t}'"
    end
  end

  chain.next
end