logstash-input-s3 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logstash/inputs/s3.rb +7 -3
- data/logstash-input-s3.gemspec +2 -1
- data/spec/fixtures/json.log +2 -0
- data/spec/inputs/s3_spec.rb +64 -21
- metadata +36 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 817a07b535fd53bce46a4015d694c66bbacb62db
|
4
|
+
data.tar.gz: 998c24e3ea4faa4d76c825d5f128a2024b9429be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6c8086b030bf048fb96e85409a106ac222500311c1531e9836304d44725d51ec5e4cc7457bc68480aa6c2c632e1fe2e62296890a8c9ae7f77def69e9fedbc14
|
7
|
+
data.tar.gz: eeee1c7e0a47bbe091ccf3ce6b8e49c70c40a100f10f1311b3fe0d6d966d3ebfb286802c82d408eac27ff73416ad877ad02ee6ebad9d095491832457188aac6f
|
data/lib/logstash/inputs/s3.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
require "logstash/inputs/base"
|
3
3
|
require "logstash/namespace"
|
4
4
|
require "logstash/plugin_mixins/aws_config"
|
5
|
-
|
6
5
|
require "time"
|
7
6
|
require "tmpdir"
|
8
7
|
require "stud/interval"
|
@@ -70,6 +69,7 @@ class LogStash::Inputs::S3 < LogStash::Inputs::Base
|
|
70
69
|
|
71
70
|
public
|
72
71
|
def register
|
72
|
+
require "fileutils"
|
73
73
|
require "digest/md5"
|
74
74
|
require "aws-sdk"
|
75
75
|
|
@@ -91,6 +91,8 @@ class LogStash::Inputs::S3 < LogStash::Inputs::Base
|
|
91
91
|
unless @backup_to_dir.nil?
|
92
92
|
Dir.mkdir(@backup_to_dir, 0700) unless File.exists?(@backup_to_dir)
|
93
93
|
end
|
94
|
+
|
95
|
+
FileUtils.mkdir_p(@temporary_directory) unless Dir.exist?(@temporary_directory)
|
94
96
|
end # def register
|
95
97
|
|
96
98
|
public
|
@@ -188,7 +190,8 @@ class LogStash::Inputs::S3 < LogStash::Inputs::Base
|
|
188
190
|
|
189
191
|
private
|
190
192
|
def event_is_metadata?(event)
|
191
|
-
|
193
|
+
return false if event["message"].nil?
|
194
|
+
line = event["message"]
|
192
195
|
version_metadata?(line) || fields_metadata?(line)
|
193
196
|
end
|
194
197
|
|
@@ -293,11 +296,12 @@ class LogStash::Inputs::S3 < LogStash::Inputs::Base
|
|
293
296
|
backup_to_dir(filename)
|
294
297
|
|
295
298
|
delete_file_from_bucket(object)
|
299
|
+
FileUtils.remove_entry_secure(filename, true)
|
296
300
|
end
|
297
301
|
|
298
302
|
private
|
299
303
|
def download_remote_file(remote_object, local_filename)
|
300
|
-
@logger.debug("S3 input: Download
|
304
|
+
@logger.debug("S3 input: Download remote file", :remote_key => remote_object.key, :local_filename => local_filename)
|
301
305
|
File.open(local_filename, 'wb') do |s3file|
|
302
306
|
remote_object.read do |chunk|
|
303
307
|
s3file.write(chunk)
|
data/logstash-input-s3.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-input-s3'
|
4
|
-
s.version = '0.1.
|
4
|
+
s.version = '0.1.10'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Stream events from files from a S3 bucket."
|
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"
|
@@ -27,5 +27,6 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.add_development_dependency 'logstash-devutils'
|
28
28
|
s.add_development_dependency 'simplecov'
|
29
29
|
s.add_development_dependency 'coveralls'
|
30
|
+
s.add_development_dependency "logstash-codec-json"
|
30
31
|
end
|
31
32
|
|
data/spec/inputs/s3_spec.rb
CHANGED
@@ -2,24 +2,49 @@
|
|
2
2
|
require "logstash/devutils/rspec/spec_helper"
|
3
3
|
require "logstash/inputs/s3"
|
4
4
|
require "logstash/errors"
|
5
|
-
require "aws-sdk"
|
6
|
-
require "stud/temporary"
|
7
5
|
require_relative "../support/helpers"
|
6
|
+
require "stud/temporary"
|
7
|
+
require "aws-sdk"
|
8
|
+
require "fileutils"
|
8
9
|
|
9
10
|
describe LogStash::Inputs::S3 do
|
10
|
-
|
11
|
-
AWS.stub!
|
12
|
-
Thread.abort_on_exception = true
|
13
|
-
end
|
11
|
+
let(:temporary_directory) { Stud::Temporary.pathname }
|
14
12
|
let(:day) { 3600 * 24 }
|
15
13
|
let(:settings) {
|
16
14
|
{
|
17
15
|
"access_key_id" => "1234",
|
18
16
|
"secret_access_key" => "secret",
|
19
|
-
"bucket" => "logstash-test"
|
17
|
+
"bucket" => "logstash-test",
|
18
|
+
"temporary_directory" => temporary_directory
|
20
19
|
}
|
21
20
|
}
|
22
21
|
|
22
|
+
before do
|
23
|
+
AWS.stub!
|
24
|
+
Thread.abort_on_exception = true
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#register" do
|
28
|
+
subject { LogStash::Inputs::S3.new(settings) }
|
29
|
+
|
30
|
+
context "with temporary directory" do
|
31
|
+
let(:settings) {
|
32
|
+
{
|
33
|
+
"access_key_id" => "1234",
|
34
|
+
"secret_access_key" => "secret",
|
35
|
+
"bucket" => "logstash-test",
|
36
|
+
"temporary_directory" => temporary_directory
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
let(:temporary_directory) { Stud::Temporary.pathname }
|
41
|
+
|
42
|
+
it "creates the direct when it doesn't exist" do
|
43
|
+
expect { subject.register }.to change { Dir.exist?(temporary_directory) }.from(false).to(true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
23
48
|
describe "#list_new_files" do
|
24
49
|
before { allow_any_instance_of(AWS::S3::ObjectCollection).to receive(:with_prefix).with(nil) { objects_list } }
|
25
50
|
|
@@ -160,6 +185,18 @@ describe LogStash::Inputs::S3 do
|
|
160
185
|
end
|
161
186
|
end
|
162
187
|
|
188
|
+
shared_examples "generated events" do
|
189
|
+
it 'should process events' do
|
190
|
+
events = fetch_events(settings)
|
191
|
+
expect(events.size).to eq(2)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "deletes the temporary file" do
|
195
|
+
events = fetch_events(settings)
|
196
|
+
expect(Dir.glob(File.join(temporary_directory, "*")).size).to eq(0)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
163
200
|
context 'when working with logs' do
|
164
201
|
let(:objects) { [log] }
|
165
202
|
let(:log) { double(:key => 'uncompressed.log', :last_modified => Time.now - 2 * day) }
|
@@ -170,32 +207,38 @@ describe LogStash::Inputs::S3 do
|
|
170
207
|
expect(log).to receive(:read) { |&block| block.call(File.read(log_file)) }
|
171
208
|
end
|
172
209
|
|
210
|
+
context "when event doesn't have a `message` field" do
|
211
|
+
let(:log_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'json.log') }
|
212
|
+
let(:settings) {
|
213
|
+
{
|
214
|
+
"access_key_id" => "1234",
|
215
|
+
"secret_access_key" => "secret",
|
216
|
+
"bucket" => "logstash-test",
|
217
|
+
"codec" => "json",
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
include_examples "generated events"
|
222
|
+
end
|
223
|
+
|
173
224
|
context 'compressed' do
|
174
225
|
let(:log) { double(:key => 'log.gz', :last_modified => Time.now - 2 * day) }
|
175
226
|
let(:log_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'compressed.log.gz') }
|
176
227
|
|
177
|
-
|
178
|
-
|
179
|
-
expect(events.size).to eq(2)
|
180
|
-
end
|
228
|
+
|
229
|
+
include_examples "generated events"
|
181
230
|
end
|
182
231
|
|
183
232
|
context 'plain text' do
|
184
233
|
let(:log_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'uncompressed.log') }
|
185
234
|
|
186
|
-
|
187
|
-
events = fetch_events(settings)
|
188
|
-
expect(events.size).to eq(2)
|
189
|
-
end
|
235
|
+
include_examples "generated events"
|
190
236
|
end
|
191
237
|
|
192
238
|
context 'encoded' do
|
193
239
|
let(:log_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'invalid_utf8.log') }
|
194
240
|
|
195
|
-
|
196
|
-
events = fetch_events(settings)
|
197
|
-
expect(events.size).to eq(2)
|
198
|
-
end
|
241
|
+
include_examples "generated events"
|
199
242
|
end
|
200
243
|
|
201
244
|
context 'cloudfront' do
|
@@ -204,13 +247,13 @@ describe LogStash::Inputs::S3 do
|
|
204
247
|
it 'should extract metadata from cloudfront log' do
|
205
248
|
events = fetch_events(settings)
|
206
249
|
|
207
|
-
expect(events.size).to eq(2)
|
208
|
-
|
209
250
|
events.each do |event|
|
210
251
|
expect(event['cloudfront_fields']).to eq('date time x-edge-location c-ip x-event sc-bytes x-cf-status x-cf-client-id cs-uri-stem cs-uri-query c-referrer x-page-url c-user-agent x-sname x-sname-query x-file-ext x-sid')
|
211
252
|
expect(event['cloudfront_version']).to eq('1.0')
|
212
253
|
end
|
213
254
|
end
|
255
|
+
|
256
|
+
include_examples "generated events"
|
214
257
|
end
|
215
258
|
end
|
216
259
|
end
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
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-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
|
14
|
+
name: logstash-core
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - '>='
|
17
18
|
- !ruby/object:Gem::Version
|
@@ -19,10 +20,7 @@ dependencies:
|
|
19
20
|
- - <
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: 2.0.0
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
type: :runtime
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
25
|
- - '>='
|
28
26
|
- !ruby/object:Gem::Version
|
@@ -30,76 +28,92 @@ dependencies:
|
|
30
28
|
- - <
|
31
29
|
- !ruby/object:Gem::Version
|
32
30
|
version: 2.0.0
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-mixin-aws
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
34
40
|
requirement: !ruby/object:Gem::Requirement
|
35
41
|
requirements:
|
36
42
|
- - '>='
|
37
43
|
- !ruby/object:Gem::Version
|
38
44
|
version: '0'
|
39
|
-
name: logstash-mixin-aws
|
40
45
|
prerelease: false
|
41
46
|
type: :runtime
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: stud
|
42
49
|
version_requirements: !ruby/object:Gem::Requirement
|
43
50
|
requirements:
|
44
|
-
- -
|
51
|
+
- - ~>
|
45
52
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
47
|
-
- !ruby/object:Gem::Dependency
|
53
|
+
version: 0.0.18
|
48
54
|
requirement: !ruby/object:Gem::Requirement
|
49
55
|
requirements:
|
50
56
|
- - ~>
|
51
57
|
- !ruby/object:Gem::Version
|
52
58
|
version: 0.0.18
|
53
|
-
name: stud
|
54
59
|
prerelease: false
|
55
60
|
type: :runtime
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: logstash-devutils
|
56
63
|
version_requirements: !ruby/object:Gem::Requirement
|
57
64
|
requirements:
|
58
|
-
- -
|
65
|
+
- - '>='
|
59
66
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0
|
61
|
-
- !ruby/object:Gem::Dependency
|
67
|
+
version: '0'
|
62
68
|
requirement: !ruby/object:Gem::Requirement
|
63
69
|
requirements:
|
64
70
|
- - '>='
|
65
71
|
- !ruby/object:Gem::Version
|
66
72
|
version: '0'
|
67
|
-
name: logstash-devutils
|
68
73
|
prerelease: false
|
69
74
|
type: :development
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
70
77
|
version_requirements: !ruby/object:Gem::Requirement
|
71
78
|
requirements:
|
72
79
|
- - '>='
|
73
80
|
- !ruby/object:Gem::Version
|
74
81
|
version: '0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
82
|
requirement: !ruby/object:Gem::Requirement
|
77
83
|
requirements:
|
78
84
|
- - '>='
|
79
85
|
- !ruby/object:Gem::Version
|
80
86
|
version: '0'
|
81
|
-
name: simplecov
|
82
87
|
prerelease: false
|
83
88
|
type: :development
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: coveralls
|
84
91
|
version_requirements: !ruby/object:Gem::Requirement
|
85
92
|
requirements:
|
86
93
|
- - '>='
|
87
94
|
- !ruby/object:Gem::Version
|
88
95
|
version: '0'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
96
|
requirement: !ruby/object:Gem::Requirement
|
91
97
|
requirements:
|
92
98
|
- - '>='
|
93
99
|
- !ruby/object:Gem::Version
|
94
100
|
version: '0'
|
95
|
-
name: coveralls
|
96
101
|
prerelease: false
|
97
102
|
type: :development
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: logstash-codec-json
|
98
105
|
version_requirements: !ruby/object:Gem::Requirement
|
99
106
|
requirements:
|
100
107
|
- - '>='
|
101
108
|
- !ruby/object:Gem::Version
|
102
109
|
version: '0'
|
110
|
+
requirement: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
prerelease: false
|
116
|
+
type: :development
|
103
117
|
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
|
104
118
|
email: info@elastic.co
|
105
119
|
executables: []
|
@@ -117,6 +131,7 @@ files:
|
|
117
131
|
- spec/fixtures/cloudfront.log
|
118
132
|
- spec/fixtures/compressed.log.gz
|
119
133
|
- spec/fixtures/invalid_utf8.log
|
134
|
+
- spec/fixtures/json.log
|
120
135
|
- spec/fixtures/uncompressed.log
|
121
136
|
- spec/inputs/s3_spec.rb
|
122
137
|
- spec/integration/s3_spec.rb
|
@@ -151,6 +166,7 @@ test_files:
|
|
151
166
|
- spec/fixtures/cloudfront.log
|
152
167
|
- spec/fixtures/compressed.log.gz
|
153
168
|
- spec/fixtures/invalid_utf8.log
|
169
|
+
- spec/fixtures/json.log
|
154
170
|
- spec/fixtures/uncompressed.log
|
155
171
|
- spec/inputs/s3_spec.rb
|
156
172
|
- spec/integration/s3_spec.rb
|