Class: LogStash::Inputs::Xmpp

Inherits:
Base
  • Object
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Xmpp

Returns a new instance of Xmpp.



35
36
37
38
39
# File 'lib/logstash/inputs/xmpp.rb', line 35

def initialize(config)
  super
  @client = Jabber::Client.new(Jabber::JID.new(@user))
  @muc_clients = []
end

Instance Attribute Details

#clientObject (readonly)

and for testing access



42
43
44
# File 'lib/logstash/inputs/xmpp.rb', line 42

def client
  @client
end

#muc_clientsObject (readonly)

and for testing access



42
43
44
# File 'lib/logstash/inputs/xmpp.rb', line 42

def muc_clients
  @muc_clients
end

Instance Method Details

#registerObject



44
45
46
47
48
49
# File 'lib/logstash/inputs/xmpp.rb', line 44

def register
  Jabber::debug = true if @logger.debug?
  client.connect(@host) # it is ok if host is nil
  client.auth(@password.value)
  client.send(Jabber::Presence.new.set_type(:available))
end

#run(queue) ⇒ Object



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
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/logstash/inputs/xmpp.rb', line 52

def run(queue)
  if using_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.set("room", room)
          event.set("from", from)
          queue << event
        end
      end # @muc.on_message
      # we need to hold a reference to the muc
      # otherwise it will be GC'd
      muc_clients.push(muc)
    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.set("from", "#{msg.from.node}@#{msg.from.domain}/#{msg.from.resource}")
        queue << event
      end
    end
  end # @client.add_message_callback

  # [GUY] the two clients: muc and client maintain their own threads
  # and will call the blocks in those threads so this one should sleep
  # this is how the xmpp4r examples do it (not saying it is correct)
  Stud.stoppable_sleep(Float::INFINITY) { stop? }

  client.close
end