mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
support for multiple rooms.
This commit is contained in:
parent
b3024c9367
commit
98d54b4d2f
1 changed files with 18 additions and 16 deletions
|
@ -12,33 +12,35 @@ class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
|
|||
config :pass, :validate => :string, :required => :true
|
||||
|
||||
# if muc/multi-user-chat required, pass the name of the room: room@conference.domain/nick
|
||||
config :room, :validate => :string
|
||||
|
||||
config :rooms, :validate => :array
|
||||
|
||||
public
|
||||
def register
|
||||
require 'xmpp4r'
|
||||
require 'xmpp4r' # xmpp4r gem
|
||||
@cl = Jabber::Client.new(Jabber::JID.new("#{@jid}"))
|
||||
@cl.connect
|
||||
@cl.auth("#{@pass}")
|
||||
@cl.send(Jabber::Presence.new.set_type(:available))
|
||||
if @room
|
||||
require 'xmpp4r/muc/helper/simplemucclient'
|
||||
@muc = Jabber::MUC::SimpleMUCClient.new(@cl)
|
||||
@muc.join("#{@room}")
|
||||
if @rooms
|
||||
require 'xmpp4r/muc/helper/simplemucclient' # xmpp4r muc helper
|
||||
end
|
||||
end # def register
|
||||
|
||||
def run(queue)
|
||||
if @room
|
||||
@muc.on_message { |time,from,body|
|
||||
e = to_event(body, from)
|
||||
if e
|
||||
queue << e
|
||||
end
|
||||
}
|
||||
end
|
||||
if @rooms
|
||||
@rooms.each do |room| # handle muc messages in different rooms
|
||||
@muc = Jabber::MUC::SimpleMUCClient.new(@cl)
|
||||
@muc.join("#{room}")
|
||||
@muc.on_message { |time,from,body|
|
||||
e = to_event(body, "#{room}/#{from}")
|
||||
if e
|
||||
queue << e
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@cl.add_message_callback { |msg|
|
||||
@cl.add_message_callback { |msg| # handle direct/private messages
|
||||
e = to_event(msg.body, msg.from) unless msg.body == nil # to avoid msgs from presence updates etc.
|
||||
if e
|
||||
queue << e
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue