logstash-input-xmpp 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/logstash/inputs/xmpp.rb +39 -17
- data/logstash-input-xmpp.gemspec +3 -3
- data/spec/inputs/xmpp_spec.rb +73 -0
- data/spec/support/xmpp4r_mocks.rb +43 -0
- metadata +25 -31
- data/.gitignore +0 -4
- data/Rakefile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f7654171e6cb3907cc0d57643ce7d24f83c1e4a
|
4
|
+
data.tar.gz: 49aecec1d1f379eef0f10dadcb13f19190c8bf3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 926b87b06f2a7e0daedb56829ebeff1f9d260ea02c8377674ebbd559bff69d6e0fddfd32a05c146303c87a00f555562a0068552110f26b5c87c6184f8ef6365f
|
7
|
+
data.tar.gz: 3cb7146b33eb75210e7f0050e1a643c274fde15a832d9e6631bafb78ed3b40486ad2f2fbbaad49083f623fb61793d0d5d75ff0bee1b66b1d0f080b42367d5fe2
|
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Logstash Plugin
|
2
2
|
|
3
|
-
This is a plugin for [Logstash](https://github.com/
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
4
|
|
5
5
|
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
6
6
|
|
7
7
|
## Documentation
|
8
8
|
|
9
|
-
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.
|
9
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
10
10
|
|
11
11
|
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
12
|
-
- For more asciidoc formatting tips, see the excellent reference here https://github.com/
|
12
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
13
13
|
|
14
14
|
## Need Help?
|
15
15
|
|
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
|
|
83
83
|
|
84
84
|
It is more important to the community that you are able to contribute.
|
85
85
|
|
86
|
-
For more information about contributing, see the [CONTRIBUTING](https://github.com/
|
86
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
data/lib/logstash/inputs/xmpp.rb
CHANGED
@@ -2,13 +2,17 @@
|
|
2
2
|
require "logstash/inputs/base"
|
3
3
|
require "logstash/namespace"
|
4
4
|
|
5
|
+
require 'xmpp4r' # xmpp4r gem
|
6
|
+
# load the MUC Client anyway, its mocked in testing
|
7
|
+
require 'xmpp4r/muc/helper/simplemucclient'
|
8
|
+
|
5
9
|
# This input allows you to receive events over XMPP/Jabber.
|
6
10
|
#
|
7
11
|
# This plugin can be used for accepting events from humans or applications
|
8
12
|
# XMPP, or you can use it for PubSub or general message passing for logstash to
|
9
13
|
# logstash.
|
10
14
|
class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
|
11
|
-
|
15
|
+
|
12
16
|
config_name "xmpp"
|
13
17
|
|
14
18
|
default :codec, "plain"
|
@@ -32,26 +36,30 @@ class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
|
|
32
36
|
config :debug, :validate => :boolean, :default => false, :deprecated => "Use the logstash --debug flag for this instead."
|
33
37
|
|
34
38
|
public
|
35
|
-
def register
|
36
|
-
require 'xmpp4r' # xmpp4r gem
|
37
|
-
Jabber::debug = true if @debug || @logger.debug?
|
38
39
|
|
40
|
+
def initialize(config)
|
41
|
+
super
|
39
42
|
@client = Jabber::Client.new(Jabber::JID.new(@user))
|
40
|
-
@
|
41
|
-
|
42
|
-
|
43
|
+
@muc_clients = []
|
44
|
+
end
|
45
|
+
|
46
|
+
# and for testing access
|
47
|
+
attr_reader :client, :muc_clients
|
43
48
|
|
44
|
-
|
45
|
-
|
49
|
+
def register
|
50
|
+
Jabber::debug = true if @debug || @logger.debug?
|
51
|
+
client.connect(@host) # it is ok if host is nil
|
52
|
+
client.auth(@password.value)
|
53
|
+
client.send(Jabber::Presence.new.set_type(:available))
|
46
54
|
end # def register
|
47
55
|
|
48
|
-
|
56
|
+
|
49
57
|
def run(queue)
|
50
|
-
if
|
58
|
+
if using_rooms?
|
51
59
|
@rooms.each do |room| # handle muc messages in different rooms
|
52
|
-
|
53
|
-
|
54
|
-
|
60
|
+
muc = Jabber::MUC::SimpleMUCClient.new(client)
|
61
|
+
muc.join(room)
|
62
|
+
muc.on_message do |time, from, body|
|
55
63
|
@codec.decode(body) do |event|
|
56
64
|
decorate(event)
|
57
65
|
event["room"] = room
|
@@ -59,22 +67,36 @@ class LogStash::Inputs::Xmpp < LogStash::Inputs::Base
|
|
59
67
|
queue << event
|
60
68
|
end
|
61
69
|
end # @muc.on_message
|
70
|
+
# we need to hold a reference to the muc
|
71
|
+
# otherwise it will be GC'd
|
72
|
+
muc_clients.push(muc)
|
62
73
|
end # @rooms.each
|
63
74
|
end # if @rooms
|
64
75
|
|
65
|
-
|
76
|
+
client.add_message_callback do |msg| # handle direct/private messages
|
66
77
|
# accept normal msgs (skip presence updates, etc)
|
67
78
|
if msg.body != nil
|
68
79
|
@codec.decode(msg.body) do |event|
|
69
80
|
decorate(event)
|
70
|
-
# Maybe "from" should just be a hash:
|
81
|
+
# Maybe "from" should just be a hash:
|
71
82
|
# { "node" => ..., "domain" => ..., "resource" => ... }
|
72
83
|
event["from"] = "#{msg.from.node}@#{msg.from.domain}/#{msg.from.resource}"
|
73
84
|
queue << event
|
74
85
|
end
|
75
86
|
end
|
76
87
|
end # @client.add_message_callback
|
77
|
-
|
88
|
+
|
89
|
+
# [GUY] the two clients: muc and client maintain their own threads
|
90
|
+
# and will call the blocks in those threads so this one should sleep
|
91
|
+
# this is how the xmpp4r examples do it (not saying it is correct)
|
92
|
+
Stud.stoppable_sleep(Float::INFINITY) { stop? }
|
93
|
+
|
94
|
+
client.close
|
78
95
|
end # def run
|
79
96
|
|
97
|
+
private
|
98
|
+
|
99
|
+
def using_rooms?
|
100
|
+
@rooms && !@rooms.empty?
|
101
|
+
end
|
80
102
|
end # class LogStash::Inputs::Xmpp
|
data/logstash-input-xmpp.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-xmpp'
|
4
|
-
s.version = '
|
4
|
+
s.version = '2.0.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "This input allows you to receive events over XMPP/Jabber."
|
7
7
|
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.require_paths = ["lib"]
|
12
12
|
|
13
13
|
# Files
|
14
|
-
s.files =
|
14
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
15
15
|
|
16
16
|
# Tests
|
17
17
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
|
21
21
|
|
22
22
|
# Gem dependencies
|
23
|
-
s.add_runtime_dependency "logstash-core",
|
23
|
+
s.add_runtime_dependency "logstash-core", "~> 2.0.0.snapshot"
|
24
24
|
|
25
25
|
s.add_runtime_dependency 'logstash-codec-plain'
|
26
26
|
s.add_runtime_dependency 'xmpp4r', ['0.5']
|
data/spec/inputs/xmpp_spec.rb
CHANGED
@@ -1 +1,74 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require 'logstash/inputs/xmpp'
|
4
|
+
require 'support/xmpp4r_mocks.rb'
|
5
|
+
|
6
|
+
describe LogStash::Inputs::Xmpp do
|
7
|
+
let(:rooms) { ['logstash', 'kibana'] }
|
8
|
+
let(:config) do
|
9
|
+
{
|
10
|
+
'user' => 'foo@domain.org/chat',
|
11
|
+
'password' => 'bAr',
|
12
|
+
'rooms' => rooms
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
allow(Jabber::Client).to receive(:new) do |jid|
|
18
|
+
Jabber::ClientMock.new(jid)
|
19
|
+
end
|
20
|
+
|
21
|
+
allow(Jabber::MUC::SimpleMUCClient).to receive(:new) do |client|
|
22
|
+
Jabber::MucClientMock.new(client)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when running' do
|
27
|
+
let(:queue) { [] }
|
28
|
+
let(:msg) { 'Hello Logstash'}
|
29
|
+
let(:inject_block) do
|
30
|
+
-> { subject.client.inject_message(Jabber::MessageMock.new(msg)) }
|
31
|
+
end
|
32
|
+
|
33
|
+
subject { LogStash::Inputs::Xmpp.new(config) }
|
34
|
+
|
35
|
+
before do
|
36
|
+
subject.register
|
37
|
+
plugin_thread = Thread.new(subject, queue) { |subj, que| subj.run(que) }
|
38
|
+
sleep 0.01 until plugin_thread.status == 'sleep'
|
39
|
+
inject_block.call
|
40
|
+
subject.stop
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when using Client" do
|
44
|
+
it 'pushes normal events into a queue' do
|
45
|
+
event = queue.first
|
46
|
+
expect(event['message']).to eq(msg)
|
47
|
+
expect(event['from']).to eq('bar@domain.org/chat')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when using Rooms" do
|
52
|
+
let(:inject_block) do
|
53
|
+
-> do
|
54
|
+
subject.muc_clients.each do |muc|
|
55
|
+
muc.inject_message('now', 'bar', 'Hello Foo')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'pushes room events into a queue' do
|
61
|
+
rooms.each do |room|
|
62
|
+
event = queue.shift
|
63
|
+
expect(event['message']).to eq('Hello Foo')
|
64
|
+
expect(event['from']).to eq('bar')
|
65
|
+
expect(event['room']).to eq(room)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when shutting down' do
|
72
|
+
it_behaves_like "an interruptible input plugin"
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Jabber
|
3
|
+
class ClientMock
|
4
|
+
def initialize(jid)
|
5
|
+
@jid = jid
|
6
|
+
@message_block = ->(msg) { puts "!ERROR! ----> Should not see #{msg}"}
|
7
|
+
end
|
8
|
+
def connect(*) true; end
|
9
|
+
def auth(*) true; end
|
10
|
+
def send(*) true; end
|
11
|
+
def close(*) true; end
|
12
|
+
def add_presence_callback(*) true; end
|
13
|
+
def add_message_callback(*args, &block)
|
14
|
+
@message_block = block
|
15
|
+
end
|
16
|
+
def inject_message(msg)
|
17
|
+
@message_block.call(msg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class MucClientMock
|
22
|
+
def initialize(client)
|
23
|
+
@message_block = ->(time, from, body) { puts "!!!!! ----> Should not see #{time}, #{from}, #{body}"}
|
24
|
+
end
|
25
|
+
def join(rm)
|
26
|
+
end
|
27
|
+
def on_message(&block)
|
28
|
+
@message_block = block
|
29
|
+
end
|
30
|
+
def inject_message(time, from, body)
|
31
|
+
@message_block.call(time, from, body)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class MessageMock
|
36
|
+
From = Struct.new(:node, :domain, :resource)
|
37
|
+
attr_reader :body, :from
|
38
|
+
def initialize(str)
|
39
|
+
@body = str
|
40
|
+
@from = From.new('bar','domain.org','chat')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,94 +1,87 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-xmpp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: logstash-core
|
15
|
-
version_requirements: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.4.0
|
20
|
-
- - <
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.0.0
|
23
14
|
requirement: !ruby/object:Gem::Requirement
|
24
15
|
requirements:
|
25
|
-
- -
|
16
|
+
- - ~>
|
26
17
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: 2.0.0
|
18
|
+
version: 2.0.0.snapshot
|
19
|
+
name: logstash-core
|
31
20
|
prerelease: false
|
32
21
|
type: :runtime
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: logstash-codec-plain
|
35
22
|
version_requirements: !ruby/object:Gem::Requirement
|
36
23
|
requirements:
|
37
|
-
- -
|
24
|
+
- - ~>
|
38
25
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
26
|
+
version: 2.0.0.snapshot
|
27
|
+
- !ruby/object:Gem::Dependency
|
40
28
|
requirement: !ruby/object:Gem::Requirement
|
41
29
|
requirements:
|
42
30
|
- - '>='
|
43
31
|
- !ruby/object:Gem::Version
|
44
32
|
version: '0'
|
33
|
+
name: logstash-codec-plain
|
45
34
|
prerelease: false
|
46
35
|
type: :runtime
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: xmpp4r
|
49
36
|
version_requirements: !ruby/object:Gem::Requirement
|
50
37
|
requirements:
|
51
|
-
- - '
|
38
|
+
- - '>='
|
52
39
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
54
42
|
requirement: !ruby/object:Gem::Requirement
|
55
43
|
requirements:
|
56
44
|
- - '='
|
57
45
|
- !ruby/object:Gem::Version
|
58
46
|
version: '0.5'
|
47
|
+
name: xmpp4r
|
59
48
|
prerelease: false
|
60
49
|
type: :runtime
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: logstash-devutils
|
63
50
|
version_requirements: !ruby/object:Gem::Requirement
|
64
51
|
requirements:
|
65
|
-
- - '
|
52
|
+
- - '='
|
66
53
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
54
|
+
version: '0.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
68
56
|
requirement: !ruby/object:Gem::Requirement
|
69
57
|
requirements:
|
70
58
|
- - '>='
|
71
59
|
- !ruby/object:Gem::Version
|
72
60
|
version: '0'
|
61
|
+
name: logstash-devutils
|
73
62
|
prerelease: false
|
74
63
|
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
75
69
|
description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
|
76
70
|
email: info@elastic.co
|
77
71
|
executables: []
|
78
72
|
extensions: []
|
79
73
|
extra_rdoc_files: []
|
80
74
|
files:
|
81
|
-
- .gitignore
|
82
75
|
- CHANGELOG.md
|
83
76
|
- CONTRIBUTORS
|
84
77
|
- Gemfile
|
85
78
|
- LICENSE
|
86
79
|
- NOTICE.TXT
|
87
80
|
- README.md
|
88
|
-
- Rakefile
|
89
81
|
- lib/logstash/inputs/xmpp.rb
|
90
82
|
- logstash-input-xmpp.gemspec
|
91
83
|
- spec/inputs/xmpp_spec.rb
|
84
|
+
- spec/support/xmpp4r_mocks.rb
|
92
85
|
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
93
86
|
licenses:
|
94
87
|
- Apache License (2.0)
|
@@ -111,9 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
104
|
version: '0'
|
112
105
|
requirements: []
|
113
106
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.4.8
|
115
108
|
signing_key:
|
116
109
|
specification_version: 4
|
117
110
|
summary: This input allows you to receive events over XMPP/Jabber.
|
118
111
|
test_files:
|
119
112
|
- spec/inputs/xmpp_spec.rb
|
113
|
+
- spec/support/xmpp4r_mocks.rb
|
data/.gitignore
DELETED