mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
xmpp input
This commit is contained in:
parent
e235d3c671
commit
4d7d2b5895
2 changed files with 50 additions and 29 deletions
|
@ -1,29 +0,0 @@
|
|||
require 'logstash/inputs/base'
|
||||
require 'logstash/namespace'
|
||||
|
||||
class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
|
||||
|
||||
config_name 'xmpp'
|
||||
config :jid, :validate => :string
|
||||
config :password, :validate => :string
|
||||
|
||||
public
|
||||
def register
|
||||
require 'xmpp4r-simple' # xmpp4r-simple gem
|
||||
end
|
||||
|
||||
def run(queue)
|
||||
# Setup the connection
|
||||
@im = Jabber::Simple.new("#{@jid}", "#{@password}")
|
||||
loop do
|
||||
# For all messages received, convert 'em to events
|
||||
@im.received_messages { |msg|
|
||||
e = to_event(msg.body, msg.from)
|
||||
if e
|
||||
queue << e
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
50
lib/logstash/inputs/xmpp.rb
Normal file
50
lib/logstash/inputs/xmpp.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
require "logstash/inputs/base"
|
||||
require "logstash/namespace"
|
||||
|
||||
class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
|
||||
|
||||
config_name "xmpp"
|
||||
|
||||
# user's id: foo@example.com
|
||||
config :jid, :validate => :string, :required => :true
|
||||
|
||||
# password
|
||||
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
|
||||
|
||||
public
|
||||
def register
|
||||
require 'xmpp4r'
|
||||
@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)
|
||||
end
|
||||
end # def register
|
||||
|
||||
def run(queue)
|
||||
if @room
|
||||
@muc.join("#{@room}")
|
||||
@muc.on_message { |time,from,body|
|
||||
e = to_event(body, from)
|
||||
if e
|
||||
queue << e
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
@cl.add_message_callback { |msg|
|
||||
e = to_event(msg.body, msg.from) unless msg.body == nil # to avoid msgs from presence updates etc.
|
||||
if e
|
||||
queue << e
|
||||
end
|
||||
}
|
||||
end # def run
|
||||
|
||||
end # def class LogStash:Inputs::Xmpp
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue