logstash-input-beats 2.1.4 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require "childprocess"
3
+ module ClientProcessHelpers
4
+ def start_client(timeout = 1)
5
+ @client_out = Stud::Temporary.file
6
+ @client_out.sync
7
+
8
+ @process = ChildProcess.build(*cmd)
9
+ @process.duplex = true
10
+ @process.io.stdout = @process.io.stderr = @client_out
11
+ ChildProcess.posix_spawn = true
12
+ @process.start
13
+ end
14
+
15
+ def stop_client
16
+ begin
17
+ @process.poll_for_exit(5)
18
+ rescue ChildProcess::TimeoutError
19
+ @process.stop
20
+ end
21
+
22
+ @client_out.rewind
23
+
24
+ # can be used to helper debugging when a test fails
25
+ @execution_output = @client_out.read
26
+ end
27
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ # Add an helper method named `let_tmp_file` to spec example, this
4
+ # helper will create a temporary file with the content from the block,
5
+ # it behave like a normal `let` statement. Also to make things easier temporary
6
+ # debug it will create another `let` statement with the actual content of the block.
7
+ #
8
+ # Example:
9
+ # ```
10
+ # let_tmp_file(:hello_world_file) { "Hello world" } # return a path to a tmp file containing "Hello World"
11
+ # and will create this debug `let`, the value of the file will be the same.
12
+ # let(:hello_world_file_content) # return "Hello world"
13
+ #
14
+ module FileHelpers
15
+ AUTO_CLEAN = true
16
+
17
+ def self.included(base)
18
+ base.extend(ClassMethods)
19
+ end
20
+
21
+ def write_to_tmp_file(content)
22
+ file = Stud::Temporary.file
23
+ file.write(content.to_s)
24
+ file.close
25
+ file.path
26
+ end
27
+
28
+ module ClassMethods
29
+ def let_empty_tmp_file(name, &block)
30
+ let(name) do
31
+ path = nil
32
+ f = Stud::Temporary.file
33
+ f.close
34
+ path = f.path
35
+ @__let_tmp_files = [] unless @__let_tmp_files
36
+ @__let_tmp_files << path
37
+ path
38
+ end
39
+ end
40
+
41
+ def let_tmp_file(name, &block)
42
+ after :each do
43
+ if @__let_tmp_files && FileHelpers::AUTO_CLEAN
44
+ @__let_tmp_files.each do |f|
45
+ FileUtils.rm_f(f)
46
+ end
47
+ end
48
+ end
49
+
50
+ name_content = "#{name}_content"
51
+ let(name_content, &block)
52
+ let(name) do
53
+ content = __send__(name_content)
54
+ path = write_to_tmp_file(content)
55
+ @__let_tmp_files = [] unless @__let_tmp_files
56
+ @__let_tmp_files << path
57
+ path
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ require "flores/pki"
3
+ module Flores
4
+ module PKI
5
+ DEFAULT_CERTIFICATE_OPTIONS = {
6
+ :duration => Flores::Random.number(100..2000),
7
+ :key_size => GENERATE_DEFAULT_KEY_SIZE,
8
+ :exponent => GENERATE_DEFAULT_EXPONENT,
9
+ :want_signature_ability => false
10
+ }
11
+
12
+ def self.chain_certificates(*certificates)
13
+ certificates.join("\n")
14
+ end
15
+
16
+ def self.create_intermediate_certificate(subject, signing_certificate, signing_private_key, options = {})
17
+ create_a_signed_certificate(subject, signing_certificate, signing_private_key, options.merge({ :want_signature_ability => true }))
18
+ end
19
+
20
+ def self.create_client_certicate(subject, signing_certificate, signing_private_key, options = {})
21
+ create_a_signed_certificate(subject, signing_certificate, signing_private_key, options)
22
+ end
23
+
24
+ private
25
+ def self.create_a_signed_certificate(subject, signing_certificate, signing_private_key, options = {})
26
+ options = DEFAULT_CERTIFICATE_OPTIONS.merge(options)
27
+
28
+ client_key = OpenSSL::PKey::RSA.new(options[:key_size], options[:exponent])
29
+
30
+ csr = Flores::PKI::CertificateSigningRequest.new
31
+ csr.start_time = Time.now
32
+ csr.expire_time = csr.start_time + options[:duration]
33
+ csr.public_key = client_key.public_key
34
+ csr.subject = subject
35
+ csr.signing_key = signing_private_key
36
+ csr.signing_certificate = signing_certificate
37
+ csr.want_signature_ability = options[:want_signature_ability]
38
+
39
+ [csr.create, client_key]
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ require "flores/random"
3
+
4
+ shared_examples "send events" do
5
+ it "successfully send the events" do
6
+ expect(queue.size).to eq(number_of_events), "Expected: #{number_of_events} got: #{queue.size}, execution output:\n #{@execution_output}"
7
+ expect(queue.collect { |e| e["message"] }).to eq(events)
8
+ end
9
+ end
10
+
11
+ shared_examples "doesn't send events" do
12
+ it "doesn't send any events" do
13
+ expect(queue.size).to eq(0), "Expected: #{number_of_events} got: #{queue.size}, execution output:\n #{@execution_output}"
14
+ end
15
+ end
16
+
17
+ shared_context "beats configuration" do
18
+ # common
19
+ let(:port) { Flores::Random.integer(1024..65335) }
20
+ let(:host) { "localhost" }
21
+
22
+ let(:queue) { [] }
23
+ let(:log_file) { write_to_tmp_file(events.join("\n") + "\n") } # make sure we end of line
24
+ let(:number_of_events) { 5 }
25
+ let(:event) { "Hello world" }
26
+ let(:events) do
27
+ events = []
28
+ number_of_events.times { |n| events << "#{event} #{n}" }
29
+ events
30
+ end
31
+
32
+ let(:input_config) do
33
+ {
34
+ "host" => host,
35
+ "port" => port
36
+ }
37
+ end
38
+
39
+ let(:beats) do
40
+ LogStash::Inputs::Beats.new(input_config)
41
+ end
42
+
43
+ before :each do
44
+ beats.register
45
+
46
+ @server = Thread.new do
47
+ beats.run(queue)
48
+ end
49
+ @server.abort_on_exception = true
50
+
51
+ sleep(1) while @server.status != "run"
52
+ end
53
+
54
+ after(:each) { beats.stop }
55
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-beats
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-19 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -184,6 +184,20 @@ dependencies:
184
184
  version: '0'
185
185
  prerelease: false
186
186
  type: :development
187
+ - !ruby/object:Gem::Dependency
188
+ name: childprocess
189
+ version_requirements: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirement: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - '>='
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ prerelease: false
200
+ type: :development
187
201
  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
188
202
  email: info@elastic.co
189
203
  executables: []
@@ -216,6 +230,8 @@ files:
216
230
  - spec/inputs/beats_support/decoded_event_transform_spec.rb
217
231
  - spec/inputs/beats_support/event_transform_common_spec.rb
218
232
  - spec/inputs/beats_support/raw_event_transform_spec.rb
233
+ - spec/integration/filebeat_spec.rb
234
+ - spec/integration/logstash_forwarder_spec.rb
219
235
  - spec/integration_spec.rb
220
236
  - spec/lumberjack/beats/acking_protocol_v1_spec.rb
221
237
  - spec/lumberjack/beats/acking_protocol_v2_spec.rb
@@ -223,6 +239,10 @@ files:
223
239
  - spec/lumberjack/beats/connection_spec.rb
224
240
  - spec/lumberjack/beats/server_spec.rb
225
241
  - spec/spec_helper.rb
242
+ - spec/support/client_process_helpers.rb
243
+ - spec/support/file_helpers.rb
244
+ - spec/support/flores_extensions.rb
245
+ - spec/support/integration_shared_context.rb
226
246
  - spec/support/logstash_test.rb
227
247
  - spec/support/shared_examples.rb
228
248
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
@@ -259,6 +279,8 @@ test_files:
259
279
  - spec/inputs/beats_support/decoded_event_transform_spec.rb
260
280
  - spec/inputs/beats_support/event_transform_common_spec.rb
261
281
  - spec/inputs/beats_support/raw_event_transform_spec.rb
282
+ - spec/integration/filebeat_spec.rb
283
+ - spec/integration/logstash_forwarder_spec.rb
262
284
  - spec/integration_spec.rb
263
285
  - spec/lumberjack/beats/acking_protocol_v1_spec.rb
264
286
  - spec/lumberjack/beats/acking_protocol_v2_spec.rb
@@ -266,5 +288,9 @@ test_files:
266
288
  - spec/lumberjack/beats/connection_spec.rb
267
289
  - spec/lumberjack/beats/server_spec.rb
268
290
  - spec/spec_helper.rb
291
+ - spec/support/client_process_helpers.rb
292
+ - spec/support/file_helpers.rb
293
+ - spec/support/flores_extensions.rb
294
+ - spec/support/integration_shared_context.rb
269
295
  - spec/support/logstash_test.rb
270
296
  - spec/support/shared_examples.rb