Class: Fluent::SlackOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::SlackOutput
- Includes:
- SetTagKeyMixin, SetTimeKeyMixin
- Defined in:
- lib/fluent/plugin/out_slack.rb
Defined Under Namespace
Classes: Field
Instance Attribute Summary collapse
-
#localtime ⇒ Object
readonly
for test.
-
#mrkdwn_in ⇒ Object
readonly
for test.
-
#post_message_opts ⇒ Object
readonly
for test.
-
#slack ⇒ Object
readonly
for test.
-
#time_format ⇒ Object
readonly
for test.
-
#timef ⇒ Object
readonly
for test.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #desc(description) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ SlackOutput
constructor
A new instance of SlackOutput.
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ SlackOutput
Returns a new instance of SlackOutput.
118 119 120 121 |
# File 'lib/fluent/plugin/out_slack.rb', line 118 def initialize super require 'uri' end |
Instance Attribute Details
#localtime ⇒ Object (readonly)
for test
116 117 118 |
# File 'lib/fluent/plugin/out_slack.rb', line 116 def localtime @localtime end |
#mrkdwn_in ⇒ Object (readonly)
for test
116 117 118 |
# File 'lib/fluent/plugin/out_slack.rb', line 116 def mrkdwn_in @mrkdwn_in end |
#post_message_opts ⇒ Object (readonly)
for test
116 117 118 |
# File 'lib/fluent/plugin/out_slack.rb', line 116 def @post_message_opts end |
#slack ⇒ Object (readonly)
for test
116 117 118 |
# File 'lib/fluent/plugin/out_slack.rb', line 116 def slack @slack end |
#time_format ⇒ Object (readonly)
for test
116 117 118 |
# File 'lib/fluent/plugin/out_slack.rb', line 116 def time_format @time_format end |
#timef ⇒ Object (readonly)
for test
116 117 118 |
# File 'lib/fluent/plugin/out_slack.rb', line 116 def timef @timef end |
Instance Method Details
#configure(conf) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/fluent/plugin/out_slack.rb', line 123 def configure(conf) conf['time_format'] ||= '%H:%M:%S' # old version compatiblity conf['localtime'] ||= true unless conf['utc'] super @channel = URI.unescape(@channel) # old version compatibility @channel = '#' + @channel unless @channel.start_with?('#') if @webhook_url if @webhook_url.empty? raise Fluent::ConfigError.new("`webhook_url` is an empty string") end @slack = Fluent::SlackClient::IncomingWebhook.new(@webhook_url) elsif @slackbot_url if @slackbot_url.empty? raise Fluent::ConfigError.new("`slackbot_url` is an empty string") end if @username or @color or @icon_emoji or @icon_url log.warn "out_slack: `username`, `color`, `icon_emoji`, `icon_url` parameters are not available for Slackbot Remote Control" end @slack = Fluent::SlackClient::Slackbot.new(@slackbot_url) elsif @token if @token.empty? raise Fluent::ConfigError.new("`token` is an empty string") end @slack = Fluent::SlackClient::WebApi.new else raise Fluent::ConfigError.new("One of `webhook_url` or `slackbot_url`, or `token` is required") end @slack.log = log @slack.debug_dev = log.out if log.level <= Fluent::Log::LEVEL_TRACE if @https_proxy @slack.https_proxy = @https_proxy end @message ||= '%s' @message_keys ||= %w[message] begin @message % (['1'] * @message_keys.length) rescue ArgumentError raise Fluent::ConfigError, "string specifier '%s' for `message` and `message_keys` specification mismatch" end if @title and @title_keys begin @title % (['1'] * @title_keys.length) rescue ArgumentError raise Fluent::ConfigError, "string specifier '%s' for `title` and `title_keys` specification mismatch" end end if @channel_keys begin @channel % (['1'] * @channel_keys.length) rescue ArgumentError raise Fluent::ConfigError, "string specifier '%s' for `channel` and `channel_keys` specification mismatch" end end if @icon_emoji and @icon_url raise Fluent::ConfigError, "either of `icon_emoji` or `icon_url` can be specified" end if @mrkdwn # Enable markdown for attachments. See https://api.slack.com/docs/formatting @mrkdwn_in = %w[text fields] end if @parse and !%w[none full].include?(@parse) raise Fluent::ConfigError, "`parse` must be either of `none` or `full`" end @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 |
#desc(description) ⇒ Object
11 12 |
# File 'lib/fluent/plugin/out_slack.rb', line 11 def desc(description) end |
#format(tag, time, record) ⇒ Object
202 203 204 |
# File 'lib/fluent/plugin/out_slack.rb', line 202 def format(tag, time, record) [tag, time, record].to_msgpack end |
#write(chunk) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/fluent/plugin/out_slack.rb', line 206 def write(chunk) begin payloads = build_payloads(chunk) payloads.each {|payload| @slack.(payload, @post_message_opts) } 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 # discard. @todo: add more retriable errors end end |