logstash-integration-rabbitmq 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +2 -0
  3. data/CONTRIBUTORS +26 -0
  4. data/Gemfile +11 -0
  5. data/LICENSE +13 -0
  6. data/NOTICE.TXT +5 -0
  7. data/README.md +98 -0
  8. data/docs/index-input.asciidoc +395 -0
  9. data/docs/index-output.asciidoc +266 -0
  10. data/lib/logstash/inputs/rabbitmq.rb +317 -0
  11. data/lib/logstash/outputs/rabbitmq.rb +100 -0
  12. data/lib/logstash/plugin_mixins/rabbitmq_connection.rb +235 -0
  13. data/lib/logstash_registry.rb +7 -0
  14. data/logstash-integration-rabbitmq.gemspec +37 -0
  15. data/spec/fixtures/README.md +150 -0
  16. data/spec/fixtures/client/cert.pem +69 -0
  17. data/spec/fixtures/client/key.pem +27 -0
  18. data/spec/fixtures/client/keycert.p12 +0 -0
  19. data/spec/fixtures/client/req.pem +15 -0
  20. data/spec/fixtures/client_untrusted/cert.pem +19 -0
  21. data/spec/fixtures/client_untrusted/key.pem +28 -0
  22. data/spec/fixtures/client_untrusted/keycert.p12 +0 -0
  23. data/spec/fixtures/server/cert.pem +69 -0
  24. data/spec/fixtures/server/key.pem +27 -0
  25. data/spec/fixtures/server/key_password +1 -0
  26. data/spec/fixtures/server/keycert.p12 +0 -0
  27. data/spec/fixtures/server/rabbitmq.config +10 -0
  28. data/spec/fixtures/server/req.pem +15 -0
  29. data/spec/fixtures/testca/cacert.cer +0 -0
  30. data/spec/fixtures/testca/cacert.pem +17 -0
  31. data/spec/fixtures/testca/certs/01.pem +18 -0
  32. data/spec/fixtures/testca/certs/02.pem +18 -0
  33. data/spec/fixtures/testca/certs/05.pem +69 -0
  34. data/spec/fixtures/testca/certs/06.pem +69 -0
  35. data/spec/fixtures/testca/index.txt +4 -0
  36. data/spec/fixtures/testca/index.txt.attr +1 -0
  37. data/spec/fixtures/testca/index.txt.attr.old +1 -0
  38. data/spec/fixtures/testca/index.txt.old +3 -0
  39. data/spec/fixtures/testca/openssl.cnf +53 -0
  40. data/spec/fixtures/testca/private/cakey.pem +27 -0
  41. data/spec/fixtures/testca/serial +1 -0
  42. data/spec/fixtures/testca/serial.old +1 -0
  43. data/spec/inputs/rabbitmq_spec.rb +278 -0
  44. data/spec/outputs/rabbitmq_spec.rb +228 -0
  45. data/spec/plugin_mixins/rabbitmq_connection_spec.rb +175 -0
  46. metadata +241 -0
@@ -0,0 +1,175 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/pipeline"
4
+ require "logstash/plugin_mixins/rabbitmq_connection"
5
+ require "stud/temporary"
6
+
7
+ class TestPlugin < LogStash::Outputs::Base
8
+ include LogStash::PluginMixins::RabbitMQConnection
9
+
10
+ def register
11
+ connect!
12
+ end
13
+ end
14
+
15
+ describe LogStash::PluginMixins::RabbitMQConnection do
16
+ let(:klass) { TestPlugin }
17
+ let(:host) { "localhost" }
18
+ let(:port) { 5672 }
19
+ let(:rabbitmq_settings) {
20
+ {
21
+ "host" => host,
22
+ "port" => port,
23
+ }
24
+ }
25
+ let(:instance) {
26
+ klass.new(rabbitmq_settings)
27
+ }
28
+ let(:hare_info) { instance.instance_variable_get(:@hare_info) }
29
+
30
+ describe "rabbitmq_settings" do
31
+ let(:file) { Stud::Temporary.file }
32
+ let(:path) { file.path }
33
+ after { File.unlink(path)}
34
+
35
+ let(:rabbitmq_settings) { super.merge({"connection_timeout" => 123,
36
+ "heartbeat" => 456,
37
+ "ssl" => true,
38
+ "ssl_version" => "TLSv1.1",
39
+ "ssl_certificate_path" => path,
40
+ "ssl_certificate_password" => "123"}) }
41
+
42
+ it "should set the timeout to the expected value" do
43
+ expect(instance.rabbitmq_settings[:timeout]).to eql(rabbitmq_settings["connection_timeout"])
44
+ end
45
+
46
+ it "should set heartbeat to the expected value" do
47
+ expect(instance.rabbitmq_settings[:heartbeat]).to eql(rabbitmq_settings["heartbeat"])
48
+ end
49
+
50
+ it "should set tls to the expected value" do
51
+ expect(instance.rabbitmq_settings[:tls]).to eql("TLSv1.1")
52
+ end
53
+
54
+ it "should set tls_certificate_path to the expected value" do
55
+ expect(instance.rabbitmq_settings[:tls_certificate_path]).to eql(rabbitmq_settings["ssl_certificate_path"])
56
+ end
57
+
58
+ it "should set tls_certificate_password to the expected value" do
59
+ expect(instance.rabbitmq_settings[:tls_certificate_password]).to eql(rabbitmq_settings["ssl_certificate_password"])
60
+ end
61
+
62
+ it "should set hosts to the expected value " do
63
+ expect(instance.rabbitmq_settings[:hosts][0]).to eql(host)
64
+ end
65
+
66
+ it "should only insert a single host entry" do
67
+ expect(instance.rabbitmq_settings[:hosts].length).to eql(1)
68
+ end
69
+ end
70
+
71
+ describe "ssl enabled, but no verification" do
72
+ let(:rabbitmq_settings) { super.merge({"connection_timeout" => 123,
73
+ "heartbeat" => 456,
74
+ "ssl" => true}) }
75
+
76
+ it "should not have any certificates set" do
77
+ expect(instance.rabbitmq_settings[:tls_certificate_password]).to be nil
78
+ expect(instance.rabbitmq_settings[:tls_certificate_path]).to be nil
79
+ end
80
+
81
+ end
82
+ describe "rabbitmq_settings multiple hosts" do
83
+ let(:file) { Stud::Temporary.file }
84
+ let(:path) { file.path }
85
+ after { File.unlink(path)}
86
+
87
+ let(:rabbitmq_settings) { super.merge({"host" => ["host01", "host02", "host03"]}) }
88
+
89
+ it "should set hosts to the expected value" do
90
+ expect(instance.rabbitmq_settings[:hosts][0]).to eql("host01")
91
+ expect(instance.rabbitmq_settings[:hosts][1]).to eql("host02")
92
+ expect(instance.rabbitmq_settings[:hosts][2]).to eql("host03")
93
+ end
94
+
95
+ it "should insert 3 host entries" do
96
+ expect(instance.rabbitmq_settings[:hosts].length).to eql(3)
97
+ end
98
+ end
99
+
100
+ context "when connected" do
101
+ let(:connection) { double("MarchHare Connection") }
102
+ let(:channel) { double("Channel") }
103
+
104
+ before do
105
+ allow(instance).to receive(:connect!).and_call_original
106
+ allow(::MarchHare).to receive(:connect).and_return(connection)
107
+ allow(connection).to receive(:create_channel).and_return(channel)
108
+ allow(connection).to receive(:on_blocked)
109
+ allow(connection).to receive(:on_unblocked)
110
+ allow(connection).to receive(:on_shutdown)
111
+
112
+ instance.register
113
+ end
114
+
115
+ describe "#register" do
116
+ subject { instance }
117
+
118
+ it "should create cleanly" do
119
+ expect(subject).to be_a(klass)
120
+ end
121
+
122
+ it "should connect" do
123
+ expect(subject).to have_received(:connect!).once
124
+ end
125
+ end
126
+
127
+ describe "#connect!" do
128
+ subject { hare_info }
129
+
130
+ it "should set @hare_info correctly" do
131
+ expect(subject).to be_a(LogStash::PluginMixins::RabbitMQConnection::HareInfo)
132
+ end
133
+
134
+ it "should set @connection correctly" do
135
+ expect(subject.connection).to eql(connection)
136
+ end
137
+
138
+ it "should set the channel correctly" do
139
+ expect(subject.channel).to eql(channel)
140
+ end
141
+ end
142
+ end
143
+
144
+ # If the connection encounters an exception during its initial
145
+ # connection attempt we must handle that. Subsequent errors should be
146
+ # handled by the automatic retry mechanism built-in to MarchHare
147
+ describe "initial connection exceptions" do
148
+ subject { instance }
149
+
150
+ before do
151
+ allow(subject).to receive(:sleep_for_retry)
152
+
153
+
154
+ i = 0
155
+ allow(subject).to receive(:connect) do
156
+ i += 1
157
+ if i == 1
158
+ raise(MarchHare::ConnectionRefused, "Error!")
159
+ else
160
+ double("connection")
161
+ end
162
+ end
163
+
164
+ subject.send(:connect!)
165
+ end
166
+
167
+ it "should retry its connection when conn fails" do
168
+ expect(subject).to have_received(:connect).twice
169
+ end
170
+
171
+ it "should sleep between retries" do
172
+ expect(subject).to have_received(:sleep_for_retry).once
173
+ end
174
+ end
175
+ end
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-integration-rabbitmq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.60'
19
+ - - "<="
20
+ - !ruby/object:Gem::Version
21
+ version: '2.99'
22
+ name: logstash-core-plugin-api
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.60'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: logstash-core
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ name: logstash-codec-json
54
+ prerelease: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.0'
67
+ name: march_hare
68
+ prerelease: false
69
+ type: :runtime
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 0.0.22
81
+ name: stud
82
+ prerelease: false
83
+ type: :runtime
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.0.22
89
+ - !ruby/object:Gem::Dependency
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ name: logstash-devutils
96
+ prerelease: false
97
+ type: :development
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ name: logstash-input-generator
110
+ prerelease: false
111
+ type: :development
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ name: logstash-codec-plain
124
+ prerelease: false
125
+ type: :development
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ description: This gem is a Logstash plugin required to be installed on top of the
132
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
133
+ gem is not a stand-alone program
134
+ email: info@elastic.co
135
+ executables: []
136
+ extensions: []
137
+ extra_rdoc_files: []
138
+ files:
139
+ - CHANGELOG.md
140
+ - CONTRIBUTORS
141
+ - Gemfile
142
+ - LICENSE
143
+ - NOTICE.TXT
144
+ - README.md
145
+ - docs/index-input.asciidoc
146
+ - docs/index-output.asciidoc
147
+ - lib/logstash/inputs/rabbitmq.rb
148
+ - lib/logstash/outputs/rabbitmq.rb
149
+ - lib/logstash/plugin_mixins/rabbitmq_connection.rb
150
+ - lib/logstash_registry.rb
151
+ - logstash-integration-rabbitmq.gemspec
152
+ - spec/fixtures/README.md
153
+ - spec/fixtures/client/cert.pem
154
+ - spec/fixtures/client/key.pem
155
+ - spec/fixtures/client/keycert.p12
156
+ - spec/fixtures/client/req.pem
157
+ - spec/fixtures/client_untrusted/cert.pem
158
+ - spec/fixtures/client_untrusted/key.pem
159
+ - spec/fixtures/client_untrusted/keycert.p12
160
+ - spec/fixtures/server/cert.pem
161
+ - spec/fixtures/server/key.pem
162
+ - spec/fixtures/server/key_password
163
+ - spec/fixtures/server/keycert.p12
164
+ - spec/fixtures/server/rabbitmq.config
165
+ - spec/fixtures/server/req.pem
166
+ - spec/fixtures/testca/cacert.cer
167
+ - spec/fixtures/testca/cacert.pem
168
+ - spec/fixtures/testca/certs/01.pem
169
+ - spec/fixtures/testca/certs/02.pem
170
+ - spec/fixtures/testca/certs/05.pem
171
+ - spec/fixtures/testca/certs/06.pem
172
+ - spec/fixtures/testca/index.txt
173
+ - spec/fixtures/testca/index.txt.attr
174
+ - spec/fixtures/testca/index.txt.attr.old
175
+ - spec/fixtures/testca/index.txt.old
176
+ - spec/fixtures/testca/openssl.cnf
177
+ - spec/fixtures/testca/private/cakey.pem
178
+ - spec/fixtures/testca/serial
179
+ - spec/fixtures/testca/serial.old
180
+ - spec/inputs/rabbitmq_spec.rb
181
+ - spec/outputs/rabbitmq_spec.rb
182
+ - spec/plugin_mixins/rabbitmq_connection_spec.rb
183
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
184
+ licenses:
185
+ - Apache License (2.0)
186
+ metadata:
187
+ logstash_plugin: 'true'
188
+ logstash_group: integration
189
+ integration_plugins: logstash-input-rabbitmq,logstash-output-rabbitmq
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.6.11
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Integration with RabbitMQ - input and output plugins
210
+ test_files:
211
+ - spec/fixtures/README.md
212
+ - spec/fixtures/client/cert.pem
213
+ - spec/fixtures/client/key.pem
214
+ - spec/fixtures/client/keycert.p12
215
+ - spec/fixtures/client/req.pem
216
+ - spec/fixtures/client_untrusted/cert.pem
217
+ - spec/fixtures/client_untrusted/key.pem
218
+ - spec/fixtures/client_untrusted/keycert.p12
219
+ - spec/fixtures/server/cert.pem
220
+ - spec/fixtures/server/key.pem
221
+ - spec/fixtures/server/key_password
222
+ - spec/fixtures/server/keycert.p12
223
+ - spec/fixtures/server/rabbitmq.config
224
+ - spec/fixtures/server/req.pem
225
+ - spec/fixtures/testca/cacert.cer
226
+ - spec/fixtures/testca/cacert.pem
227
+ - spec/fixtures/testca/certs/01.pem
228
+ - spec/fixtures/testca/certs/02.pem
229
+ - spec/fixtures/testca/certs/05.pem
230
+ - spec/fixtures/testca/certs/06.pem
231
+ - spec/fixtures/testca/index.txt
232
+ - spec/fixtures/testca/index.txt.attr
233
+ - spec/fixtures/testca/index.txt.attr.old
234
+ - spec/fixtures/testca/index.txt.old
235
+ - spec/fixtures/testca/openssl.cnf
236
+ - spec/fixtures/testca/private/cakey.pem
237
+ - spec/fixtures/testca/serial
238
+ - spec/fixtures/testca/serial.old
239
+ - spec/inputs/rabbitmq_spec.rb
240
+ - spec/outputs/rabbitmq_spec.rb
241
+ - spec/plugin_mixins/rabbitmq_connection_spec.rb