Sha256: 2c1aea09bd96bc606b9f8a1dcfa96c8833ad6fac2fa797c9fc66f634dc59cebf

Contents?: true

Size: 758 Bytes

Versions: 1

Compression:

Stored size: 758 Bytes

Contents

module Fluent
  require 'fluent/mixin/config_placeholders'
  require 'slack-rtmapi'

  class SlackRTMInput < Fluent::Input
    Fluent::Plugin.register_input('slackrtm', self)

    config_param :tag, :string
    config_param :token, :string, :secret => true

    def start
      super
      @messages_thread = Thread.new do
        url = SlackRTM.get_url token: token
        client = SlackRTM::Client.new websocket_url: url
        client.on(:message) do |data|
          emit(data)
        end
        client.main_loop
      end
      @messages_thread.abort_on_exception = true
    end

    def shutdown
      Thread.kill(@messages_thread)
    end

    def emit(data)
      time = Time.now.to_i
      Fluent::Engine.emit(tag, time, data)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-slackrtm-0.2.4 lib/fluent/plugin/in_slackrtm.rb