Class: Fluent::SlackboardOutput

Inherits:
BufferedOutput
  • Object
show all
Includes:
SetTagKeyMixin, SetTimeKeyMixin
Defined in:
lib/fluent/plugin/out_slackboard.rb

Instance Method Summary collapse

Constructor Details

#initializeSlackboardOutput

Returns a new instance of SlackboardOutput.



24
25
26
# File 'lib/fluent/plugin/out_slackboard.rb', line 24

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



28
29
30
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
56
57
# File 'lib/fluent/plugin/out_slackboard.rb', line 28

def configure(conf)
  super

  if @host == ""
    raise Fluent::ConfigError.new "`host` is empty"
  end

  if @port == ""
    raise Fluent::ConfigError.new "`port` is empty"
  end

  @uri = URI.parse "http://" + @host + ":" + @port + "/notify-directly"

  if @channel == ""
    raise Fluent::ConfigError.new "`channel` is empty"
  end
  @channel = '#' + @channel unless @channel.start_with? '#'

  if @fetch_key == ""
    raise Fluent::ConfigError.new "`fetch_key` is empty"
  end

  if @username == ""
    @username = "slackboard"
  end

  if @icon_emoji == ""
    @icon_emoji = ":clipboard:"
  end
end

#format(tag, time, record) ⇒ Object



59
60
61
# File 'lib/fluent/plugin/out_slackboard.rb', line 59

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

#write(chunk) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fluent/plugin/out_slackboard.rb', line 63

def write(chunk)
  begin
    payloads = build_payloads chunk
    payloads.each { |payload|
      req = Net::HTTP::Post.new @uri.path
      req.body = payload.to_json
      res = Net::HTTP.start(@uri.host, @uri.port) { |http|
        http.request req
      }
    }
  rescue Timeout::Error => e
    log.warn "out_slackboard:", :error => e.to_s, :error_class => e.class.to_s
    raise e
  rescue => e
    log.error "out_slackboard:", :error => e.to_s, :error_class => e.class.to_s
    log.warn_backtrace e.backtrace
  end
end