Class: LogStash::Outputs::Juggernaut

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

Overview

Push messages to the juggernaut websockets server:

Wraps Websockets and supports other methods (including xhr longpolling) This is basically, just an extension of the redis output (Juggernaut pulls messages from redis). But it pushes messages to a particular channel and formats the messages in the way juggernaut expects.

Instance Method Summary collapse

Instance Method Details

#receive(event) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/logstash/outputs/juggernaut.rb', line 75

def receive(event)
  return unless output?(event)
  begin
    @redis ||= connect
    if @message_format
      formatted = event.sprintf(@message_format)
    else
      formatted = event.to_json
    end
    juggernaut_message = {
      "channels" => @channels.collect{ |x| event.sprintf(x) },
      "data" => event["message"]
    }

    @redis.publish 'juggernaut', LogStash::Json.dump(juggernaut_message)
  rescue => e
    @logger.warn("Failed to send event to redis", :event => event,
                 :identity => identity, :exception => e,
                 :backtrace => e.backtrace)
    raise e
  end
end

#registerObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/logstash/outputs/juggernaut.rb', line 43

def register
  require 'redis'

  if not @channels
    raise RuntimeError.new(
      "Must define the channels on which to publish the messages"
    )
  end
  # end TODO

  @redis = nil
end

#teardownObject



99
100
101
102
103
104
# File 'lib/logstash/outputs/juggernaut.rb', line 99

def teardown
  if @data_type == 'channel' and @redis
    @redis.quit
    @redis = nil
  end
end