Sha256: cc012faddf216ebf56ad25c543327cbb3b514ea108b7b40fe05e0c42284241b8

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8
require "logstash/inputs/base"
require "logstash/namespace"
require "socket"


# Read events over the websocket protocol.
class LogStash::Inputs::Websocket < LogStash::Inputs::Base
  config_name "websocket"
  milestone 1

  default :codec, "json"

  # The url to connect to or serve from
  config :url, :validate => :string, :default => "0.0.0.0"

  # Operate as a client or a server.
  #
  # Client mode causes this plugin to connect as a websocket client
  # to the URL given. It expects to receive events as websocket messages.
  #
  # (NOT IMPLEMENTED YET) Server mode causes this plugin to listen on
  # the given URL for websocket clients. It expects to receive events
  # as websocket messages from these clients.
  config :mode, :validate => [ "server", "client" ], :default => "client"

  def register
    require "ftw"
  end # def register

  public
  def run(output_queue)
    # TODO(sissel): Implement server mode.
    agent = FTW::Agent.new
    begin
      websocket = agent.websocket!(@url)
      websocket.each do |payload|
        @codec.decode(payload) do |event|
          decorate(event)
          output_queue << event
        end
      end
    rescue => e
      @logger.warn("websocket input client threw exception, restarting",
                   :exception => e)
      sleep(1)
      retry
    end # begin
  end # def run

end # class LogStash::Inputs::Websocket

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logstash-input-websocket-0.1.1 lib/logstash/inputs/websocket.rb
logstash-input-websocket-0.1.0 lib/logstash/inputs/websocket.rb