Class: LogStash::Inputs::Xmpp

Inherits:
Base show all
Defined in:
lib/logstash/inputs/xmpp.rb

Overview

This input allows you to receive events over XMPP/Jabber.

This plugin can be used for accepting events from humans or applications XMPP, or you can use it for PubSub or general message passing for logstash to logstash.

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes inherited from Base

#params, #threadable

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize, #tag

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

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

Constructor Details

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

Instance Method Details

#registerObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/logstash/inputs/xmpp.rb', line 36

def register
  require 'xmpp4r' # xmpp4r gem
  Jabber::debug = true if @debug

  @client = Jabber::Client.new(Jabber::JID.new(@user))
  @client.connect(@host) # it is ok if host is nil
  @client.auth(@password.value)
  @client.send(Jabber::Presence.new.set_type(:available))

  # load the MUC Client if we are joining rooms.
  require 'xmpp4r/muc/helper/simplemucclient' if @rooms && !@rooms.empty?
end

#run(queue) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/logstash/inputs/xmpp.rb', line 50

def run(queue)
  if @rooms
    @rooms.each do |room| # handle muc messages in different rooms
      @muc = Jabber::MUC::SimpleMUCClient.new(@client)
      @muc.join(room)
      @muc.on_message do |time,from,body|
        @codec.decode(body) do |event|
          decorate(event)
          event["room"] = room
          event["from"] = from
          queue << event
        end
      end # @muc.on_message
    end # @rooms.each
  end # if @rooms

  @client.add_message_callback do |msg| # handle direct/private messages
    # accept normal msgs (skip presence updates, etc)
    if msg.body != nil
      @codec.decode(msg.body) do |event|
        decorate(event)
        # Maybe "from" should just be a hash: 
        # { "node" => ..., "domain" => ..., "resource" => ... }
        event["from"] = "#{msg.from.node}@#{msg.from.domain}/#{msg.from.resource}"
        queue << event
      end
    end
  end # @client.add_message_callback
  sleep
end