Class: Fluent::BufferedSlackOutput
- Inherits:
-
TimeSlicedOutput
- Object
- TimeSlicedOutput
- Fluent::BufferedSlackOutput
- Defined in:
- lib/fluent/plugin/out_buffered_slack.rb
Instance Attribute Summary collapse
-
#slack ⇒ Object
readonly
Returns the value of attribute slack.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ BufferedSlackOutput
constructor
A new instance of BufferedSlackOutput.
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ BufferedSlackOutput
Returns a new instance of BufferedSlackOutput.
43 44 45 46 47 48 |
# File 'lib/fluent/plugin/out_buffered_slack.rb', line 43 def initialize super require 'active_support/time' require 'uri' require 'net/http' end |
Instance Attribute Details
#slack ⇒ Object (readonly)
Returns the value of attribute slack.
13 14 15 |
# File 'lib/fluent/plugin/out_buffered_slack.rb', line 13 def slack @slack end |
Instance Method Details
#configure(conf) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fluent/plugin/out_buffered_slack.rb', line 50 def configure(conf) super @channel = URI.unescape(conf['channel']) @username = conf['username'] || 'fluentd' @color = conf['color'] || 'good' @icon_emoji = conf['icon_emoji'] || ':question:' @timezone = conf['timezone'] || 'UTC' @team = conf['team'] @api_key = conf['api_key'] end |
#format(tag, time, record) ⇒ Object
15 16 17 |
# File 'lib/fluent/plugin/out_buffered_slack.rb', line 15 def format(tag, time, record) [tag, time, record].to_msgpack end |
#write(chunk) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fluent/plugin/out_buffered_slack.rb', line 19 def write(chunk) = {} chunk.msgpack_each do |tag, time, record| [tag] = '' if [tag].nil? [tag] << "[#{Time.at(time).in_time_zone(@timezone).strftime("%H:%M:%S")}] #{record['message']}\n" end begin payload = { channel: @channel, username: @username, icon_emoji: @icon_emoji, attachments: [{ fallback: .keys.join(','), color: @color, fields: .map{|k,v| {title: k, value: v} } }]} post_request( payload: payload.to_json ) rescue => e $log.error("Slack Error: #{e.backtrace[0]} / #{e.message}") end end |