lib/fluent/plugin/out_slack.rb in fluent-plugin-slack-0.6.0 vs lib/fluent/plugin/out_slack.rb in fluent-plugin-slack-0.6.1
- old
+ new
@@ -36,11 +36,11 @@
config_param :message_keys, default: nil do |val|
val.split(',')
end
# for test
- attr_reader :slack, :time_format, :localtime, :timef, :mrkdwn_in
+ attr_reader :slack, :time_format, :localtime, :timef, :mrkdwn_in, :post_message_opts
def initialize
super
require 'uri'
end
@@ -115,22 +115,26 @@
if @parse and !%w[none full].include?(@parse)
raise Fluent::ConfigError, "`parse` must be either of `none` or `full`"
end
- @post_message_opts = @auto_channels_create ? {auto_channels_create: true} : {}
+ @post_message_opts = {}
+ if @auto_channels_create
+ raise Fluent::ConfigError, "`token` parameter is required to use `auto_channels_create`" unless @token
+ @post_message_opts = {auto_channels_create: true}
+ end
end
def format(tag, time, record)
[tag, time, record].to_msgpack
end
def write(chunk)
begin
payloads = build_payloads(chunk)
payloads.each {|payload| @slack.post_message(payload, @post_message_opts) }
- rescue Net::OpenTimeout, Net::ReadTimeout => e
+ rescue Timeout::Error => e
log.warn "out_slack:", :error => e.to_s, :error_class => e.class.to_s
raise e # let Fluentd retry
rescue => e
log.error "out_slack:", :error => e.to_s, :error_class => e.class.to_s
log.warn_backtrace e.backtrace
@@ -170,9 +174,11 @@
@common_attachment[:mrkdwn_in] = @mrkdwn_in if @mrkdwn_in
@common_attachment
end
Field = Struct.new("Field", :title, :value)
+ # ruby 1.9.x does not provide #to_h
+ Field.send(:define_method, :to_h) { {title: title, value: value} }
def build_title_payloads(chunk)
ch_fields = {}
chunk.msgpack_each do |tag, time, record|
channel = build_channel(record)