class Fluent::SlackboardOutput
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_slackboard.rb, line 24 def initialize super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# 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)
click to toggle source
# File lib/fluent/plugin/out_slackboard.rb, line 59 def format(tag, time, record) [tag, time, record].to_msgpack end
write(chunk)
click to toggle source
# 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
Private Instance Methods
build_payloads(chunk)
click to toggle source
# File lib/fluent/plugin/out_slackboard.rb, line 84 def build_payloads(chunk) payloads = [] chunk.msgpack_each do |tag, time, record| payload = {} payload["payload"] = { :channel => @channel, :username => @username, :icon_emoji => @icon_emoji, :text => record[@fetch_key], :parse => @parse, } payload["sync"] = @sync payloads << payload end payloads end