Class: Fluent::LineNotifyOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_line_notify.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



25
26
27
28
29
# File 'lib/fluent/plugin/out_line_notify.rb', line 25

def configure(conf)
  super

  @erb = ERB.new(@message_template)
end

#emit(tag, es, chain) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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