Sha256: e5d7e2a3c0fc6b2ae036444d5cc8b8f526b0bb5f21aa0694af0092fee951d4d1

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 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"

  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

5 entries across 5 versions & 1 rubygems

Version Path
logstash-input-websocket-2.0.2 lib/logstash/inputs/websocket.rb
logstash-input-websocket-2.0.1 lib/logstash/inputs/websocket.rb
logstash-input-websocket-0.1.4 lib/logstash/inputs/websocket.rb
logstash-input-websocket-0.1.3 lib/logstash/inputs/websocket.rb
logstash-input-websocket-0.1.2 lib/logstash/inputs/websocket.rb