- Add 'server' config option so I can connect to google talk.

- Add 'debug' config option for easier xmpp debugging
This commit is contained in:
Jordan Sissel 2011-08-15 01:55:05 -07:00
parent 1df6c16043
commit dc290ef5fd

View file

@ -14,12 +14,22 @@ class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
# if muc/multi-user-chat required, pass the name of the room: room@conference.domain/nick
config :rooms, :validate => :array
# The server to connect to. This is optional. If you omit this setting, the
# host on the JID is used. (foo.com for user@foo.com)
config :server, :validate => :string
# Set to true to enable greater debugging in XMPP. Useful for debugging
# network/authentication erros.
config :debug, :validate => :boolean, :default => false
public
def register
require 'xmpp4r' # xmpp4r gem
@cl = Jabber::Client.new(Jabber::JID.new("#{@jid}"))
@cl.connect
@cl.auth("#{@pass}")
Jabber::debug = true if @debug
@cl = Jabber::Client.new(Jabber::JID.new(@jid))
@cl.connect(@server) # ok if @server is nill
@cl.auth(@pass)
@cl.send(Jabber::Presence.new.set_type(:available))
if @rooms
require 'xmpp4r/muc/helper/simplemucclient' # xmpp4r muc helper
@ -30,7 +40,7 @@ class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
if @rooms
@rooms.each do |room| # handle muc messages in different rooms
@muc = Jabber::MUC::SimpleMUCClient.new(@cl)
@muc.join("#{room}")
@muc.join(room)
@muc.on_message { |time,from,body|
e = to_event(body, "#{room}/#{from}")
if e
@ -41,7 +51,9 @@ class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
end
@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.
source = "xmpp://#{msg.from.node}@#{msg.from.domain}/#{msg.from.resource}"
# accept normal msgs (skip presence updates, etc)
e = to_event(msg.body, source) unless msg.body == nil
if e
queue << e
end