mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
- Add websocket support (not yet tested)
This commit is contained in:
parent
e79ae10abe
commit
0043302675
1 changed files with 35 additions and 0 deletions
35
lib/outputs/websocket.rb
Normal file
35
lib/outputs/websocket.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require "logstash/namespace"
|
||||
require "logstash/event"
|
||||
require "uri"
|
||||
require "em-websocket" # rubygem 'em-websocket'
|
||||
|
||||
class LogStash::Outputs::Websocket
|
||||
def initialize(url, config={}, &block)
|
||||
@url = url
|
||||
@url = URI.parse(url) if url.is_a? String
|
||||
@config = config
|
||||
end
|
||||
|
||||
def register
|
||||
puts "register"
|
||||
@channel = EventMachine::Channel.new
|
||||
host = (@url.host or "0.0.0.0")
|
||||
port = (@url.port or 3000)
|
||||
EventMachine::WebSocket.start(:host => host, :port => port) do |ws|
|
||||
ws.onopen do
|
||||
puts "Open"
|
||||
sid = @channel.subscribe do |msg|
|
||||
puts "Sending: #{msg}"
|
||||
ws.send msg
|
||||
end
|
||||
ws.onclose do
|
||||
@channel.unsubscribe(sid)
|
||||
end # ws.onclose
|
||||
end # ws.onopen
|
||||
end
|
||||
end # def register
|
||||
|
||||
def receive(event)
|
||||
@channel.push event.to_json
|
||||
end # def event
|
||||
end # class LogStash::Outputs::Websocket
|
Loading…
Add table
Add a link
Reference in a new issue