Class: LogStash::Outputs::Websocket
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::Websocket
show all
- Defined in:
- lib/logstash/outputs/websocket.rb
Instance Attribute Summary
Attributes inherited from Base
#logger
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#receive(event) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/logstash/outputs/websocket.rb', line 29
def receive(event)
if @subscribers > 0
@logger.info("Sending event to websocket.")
@channel.push event.to_json
end
end
|
#register ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/logstash/outputs/websocket.rb', line 7
def register
@channel = EventMachine::Channel.new
@subscribers = 0
@url.host = (@url.host or "0.0.0.0")
@url.port = (@url.port or 3232)
@logger.info("Registering websocket on #{@url}")
EventMachine::WebSocket.start(:host => @url.host, :port => @url.port) do |ws|
ws.onopen do
@subscribers += 1
@logger.info("New #{self.class.name} connection")
sid = @channel.subscribe do |msg|
ws.send msg
end
ws.onclose do
@channel.unsubscribe(sid)
@subscribers -= 1
end end end
end
|