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.

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Outputs::Base

Instance Method Details

#receive(event) ⇒ Object



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

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', juggernaut_message.to_json
  rescue => e
    @logger.warn("Failed to send event to redis", :event => event,
                 :identity => identity, :exception => e,
                 :backtrace => e.backtrace)
    raise e
  end
end

#registerObject



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

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



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

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