class LogStash::Outputs::WebSocket

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.

Public Instance Methods

make_pubsub(topic) click to toggle source
# File lib/logstash/outputs/websocket.rb, line 21
def make_pubsub(topic)
    pubsub = Logstash::Outputs::WebSocket::Pubsub.new
    pubsub.logger = @logger
end
receive(event) click to toggle source
# File lib/logstash/outputs/websocket.rb, line 45
def receive(event)
  json = event.to_json
  topic = json.topic
  if @channels.has_key?(topic) 
    @channels[topic].publish(json)
  else
    pubsub = make_pubsub(topic) 
    @channels[topic] = pubsub
    pubsub.publish(json)
  end # if
end
register() click to toggle source
# File lib/logstash/outputs/websocket.rb, line 27
def register
  require "ftw"
  require "logstash/outputs/websocket/app"
  require "logstash/outputs/websocket/pubsub"
  @channels = {}
  @server = Thread.new(@channels) do |channels|
    begin
      Rack::Handler::FTW.run(LogStash::Outputs::WebSocket::App.new(channels, @logger),
                             :Host => @host, :Port => @port)
    rescue => e
      @logger.error("websocket server failed", :exception => e)
      sleep 1
      retry
    end
  end
end