Class: LogStash::Outputs::WebSocket

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/websocket.rb

Overview

This output runs a websocket server and publishes any messages to all connected websocket clients.

You can connect to it with ws://<host>:<port>/

If no clients are connected, any messages received are ignored.

Instance Method Summary collapse

Instance Method Details

#receive(event) ⇒ Object



41
42
43
44
# File 'lib/logstash/outputs/websocket.rb', line 41

def receive(event)

  @pubsub.publish(event.to_json)
end

#registerObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/logstash/outputs/websocket.rb', line 22

def register
  require "ftw"
  require "logstash/outputs/websocket/app"
  require "logstash/outputs/websocket/pubsub"
  @pubsub = LogStash::Outputs::WebSocket::Pubsub.new
  @pubsub.logger = @logger
  @server = Thread.new(@pubsub) do |pubsub|
    begin
      Rack::Handler::FTW.run(LogStash::Outputs::WebSocket::App.new(pubsub, @logger),
                             :Host => @host, :Port => @port)
    rescue => e
      @logger.error("websocket server failed", :exception => e)
      sleep 1
      retry
    end
  end
end