logstash-filter-elasticsearch 3.6.1 → 3.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/docs/index.asciidoc +22 -0
- data/lib/logstash/filters/elasticsearch.rb +80 -2
- data/logstash-filter-elasticsearch.gemspec +1 -1
- data/spec/filters/elasticsearch_spec.rb +81 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8fd49609af063aa843c5af56f09194753911fab6bc057dc8bde3c4e84c196b1
|
4
|
+
data.tar.gz: 728f386a7e634276b02705e2c37ad9316d8f490cf3811c3e85f7a0203485e480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4a567ac1f292ed3aced93934029b1048818c7ec930d88e86a3bffaa9dec27d90f54ba70b885771804fcb7175370ee67907de206d464af8e8658f6e4649f6607
|
7
|
+
data.tar.gz: bde67c1c10b2e1fcdde0160794d565389d443fb0667e45a3a5363d3f67f6e00571b7f284bbdc560721560965e1b5194c4e7087e345e838216b961c027e46f5e6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 3.7.0
|
2
|
+
- Feat: support cloud_id / cloud_auth configuration [#122](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/122)
|
3
|
+
|
1
4
|
## 3.6.1
|
2
5
|
- Loosen restrictions on Elasticsearch gem ([#120](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/120))
|
3
6
|
|
data/docs/index.asciidoc
CHANGED
@@ -122,6 +122,8 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
122
122
|
|Setting |Input type|Required
|
123
123
|
| <<plugins-{type}s-{plugin}-aggregation_fields>> |<<hash,hash>>|No
|
124
124
|
| <<plugins-{type}s-{plugin}-ca_file>> |a valid filesystem path|No
|
125
|
+
| <<plugins-{type}s-{plugin}-cloud_auth>> |<<password,password>>|No
|
126
|
+
| <<plugins-{type}s-{plugin}-cloud_id>> |<<string,string>>|No
|
125
127
|
| <<plugins-{type}s-{plugin}-docinfo_fields>> |<<hash,hash>>|No
|
126
128
|
| <<plugins-{type}s-{plugin}-enable_sort>> |<<boolean,boolean>>|No
|
127
129
|
| <<plugins-{type}s-{plugin}-fields>> |<<array,array>>|No
|
@@ -299,6 +301,26 @@ Tags the event on failure to look up previous log event information. This can be
|
|
299
301
|
|
300
302
|
Basic Auth - username
|
301
303
|
|
304
|
+
[id="plugins-{type}s-{plugin}-cloud_auth"]
|
305
|
+
===== `cloud_auth`
|
306
|
+
|
307
|
+
* Value type is <<password,password>>
|
308
|
+
* There is no default value for this setting.
|
309
|
+
|
310
|
+
Cloud authentication string ("<username>:<password>" format) is an alternative for the `user`/`password` pair.
|
311
|
+
|
312
|
+
For mode details, check out the https://www.elastic.co/guide/en/logstash/current/connecting-to-cloud.html#_cloud_auth[Logstash-to-Cloud documentation]
|
313
|
+
|
314
|
+
[id="plugins-{type}s-{plugin}-cloud_id"]
|
315
|
+
===== `cloud_id`
|
316
|
+
|
317
|
+
* Value type is <<string,string>>
|
318
|
+
* There is no default value for this setting.
|
319
|
+
|
320
|
+
Cloud ID, from the Elastic Cloud web console. If set `hosts` should not be used.
|
321
|
+
|
322
|
+
For mode details, check out the https://www.elastic.co/guide/en/logstash/current/connecting-to-cloud.html#_cloud_id[Logstash-to-Cloud documentation]
|
323
|
+
|
302
324
|
|
303
325
|
|
304
326
|
[id="plugins-{type}s-{plugin}-common-options"]
|
@@ -3,15 +3,23 @@ require "logstash/filters/base"
|
|
3
3
|
require "logstash/namespace"
|
4
4
|
require_relative "elasticsearch/client"
|
5
5
|
require "logstash/json"
|
6
|
+
require "logstash/util/safe_uri"
|
6
7
|
java_import "java.util.concurrent.ConcurrentHashMap"
|
7
8
|
|
8
9
|
|
9
10
|
class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
10
11
|
config_name "elasticsearch"
|
11
12
|
|
13
|
+
DEFAULT_HOST = ::LogStash::Util::SafeURI.new("//localhost:9200")
|
14
|
+
|
12
15
|
# List of elasticsearch hosts to use for querying.
|
13
|
-
config :hosts, :validate => :array,
|
14
|
-
|
16
|
+
config :hosts, :validate => :array, :default => [ DEFAULT_HOST ]
|
17
|
+
|
18
|
+
# Cloud ID, from the Elastic Cloud web console. If set `hosts` should not be used.
|
19
|
+
#
|
20
|
+
# For more info, check out the https://www.elastic.co/guide/en/logstash/current/connecting-to-cloud.html#_cloud_id[cloud documentation]
|
21
|
+
config :cloud_id, :validate => :string
|
22
|
+
|
15
23
|
# Comma-delimited list of index names to search; use `_all` or empty string to perform the operation on all indices.
|
16
24
|
# Field substitution (e.g. `index-name-%{date_field}`) is available
|
17
25
|
config :index, :validate => :string, :default => ""
|
@@ -42,6 +50,11 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
42
50
|
# Basic Auth - password
|
43
51
|
config :password, :validate => :password
|
44
52
|
|
53
|
+
# Cloud authentication string ("<username>:<password>" format) is an alternative for the `user`/`password` configuration.
|
54
|
+
#
|
55
|
+
# For more info, check out the https://www.elastic.co/guide/en/logstash/current/connecting-to-cloud.html#_cloud_auth[cloud documentation]
|
56
|
+
config :cloud_auth, :validate => :password
|
57
|
+
|
45
58
|
# SSL
|
46
59
|
config :ssl, :validate => :boolean, :default => false
|
47
60
|
|
@@ -71,6 +84,11 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
71
84
|
@query_dsl = file.read
|
72
85
|
end
|
73
86
|
|
87
|
+
fill_hosts_from_cloud_id
|
88
|
+
fill_user_password_from_cloud_auth
|
89
|
+
|
90
|
+
@hosts = Array(@hosts).map { |host| host.to_s } # for ES client URI#to_s
|
91
|
+
|
74
92
|
test_connection!
|
75
93
|
end # def register
|
76
94
|
|
@@ -148,6 +166,8 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
148
166
|
end
|
149
167
|
|
150
168
|
def new_client
|
169
|
+
# NOTE: could pass cloud-id/cloud-auth to client but than we would need to be stricter on ES version requirement
|
170
|
+
# and also LS parsing might differ from ES client's parsing so for consistency we do not pass cloud options ...
|
151
171
|
LogStash::Filters::ElasticsearchClient.new(@user, @password, client_options)
|
152
172
|
end
|
153
173
|
|
@@ -188,6 +208,64 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
188
208
|
total
|
189
209
|
end
|
190
210
|
|
211
|
+
def hosts_default?(hosts)
|
212
|
+
# NOTE: would be nice if pipeline allowed us a clean way to detect a config default :
|
213
|
+
hosts.is_a?(Array) && hosts.size == 1 && hosts.first.equal?(DEFAULT_HOST)
|
214
|
+
end
|
215
|
+
|
216
|
+
def fill_hosts_from_cloud_id
|
217
|
+
return unless @cloud_id
|
218
|
+
|
219
|
+
if @hosts && !hosts_default?(@hosts)
|
220
|
+
raise LogStash::ConfigurationError, 'Both cloud_id and hosts specified, please only use one of those.'
|
221
|
+
end
|
222
|
+
@hosts = parse_host_uri_from_cloud_id(@cloud_id)
|
223
|
+
end
|
224
|
+
|
225
|
+
def fill_user_password_from_cloud_auth
|
226
|
+
return unless @cloud_auth
|
227
|
+
|
228
|
+
if @user || @password
|
229
|
+
raise LogStash::ConfigurationError, 'Both cloud_auth and user/password specified, please only use one.'
|
230
|
+
end
|
231
|
+
@user, @password = parse_user_password_from_cloud_auth(@cloud_auth)
|
232
|
+
params['user'], params['password'] = @user, @password
|
233
|
+
end
|
234
|
+
|
235
|
+
def parse_host_uri_from_cloud_id(cloud_id)
|
236
|
+
begin # might not be available on older LS
|
237
|
+
require 'logstash/util/cloud_setting_id'
|
238
|
+
rescue LoadError
|
239
|
+
raise LogStash::ConfigurationError, 'The cloud_id setting is not supported by your version of Logstash, ' +
|
240
|
+
'please upgrade your installation (or set hosts instead).'
|
241
|
+
end
|
242
|
+
|
243
|
+
begin
|
244
|
+
cloud_id = LogStash::Util::CloudSettingId.new(cloud_id) # already does append ':{port}' to host
|
245
|
+
rescue ArgumentError => e
|
246
|
+
raise LogStash::ConfigurationError, e.message.to_s.sub(/Cloud Id/i, 'cloud_id')
|
247
|
+
end
|
248
|
+
cloud_uri = "#{cloud_id.elasticsearch_scheme}://#{cloud_id.elasticsearch_host}"
|
249
|
+
LogStash::Util::SafeURI.new(cloud_uri)
|
250
|
+
end
|
251
|
+
|
252
|
+
def parse_user_password_from_cloud_auth(cloud_auth)
|
253
|
+
begin # might not be available on older LS
|
254
|
+
require 'logstash/util/cloud_setting_auth'
|
255
|
+
rescue LoadError
|
256
|
+
raise LogStash::ConfigurationError, 'The cloud_auth setting is not supported by your version of Logstash, ' +
|
257
|
+
'please upgrade your installation (or set user/password instead).'
|
258
|
+
end
|
259
|
+
|
260
|
+
cloud_auth = cloud_auth.value if cloud_auth.is_a?(LogStash::Util::Password)
|
261
|
+
begin
|
262
|
+
cloud_auth = LogStash::Util::CloudSettingAuth.new(cloud_auth)
|
263
|
+
rescue ArgumentError => e
|
264
|
+
raise LogStash::ConfigurationError, e.message.to_s.sub(/Cloud Auth/i, 'cloud_auth')
|
265
|
+
end
|
266
|
+
[ cloud_auth.username, cloud_auth.password ]
|
267
|
+
end
|
268
|
+
|
191
269
|
def test_connection!
|
192
270
|
get_client.client.ping
|
193
271
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-elasticsearch'
|
4
|
-
s.version = '3.
|
4
|
+
s.version = '3.7.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Copies fields from previous log events in Elasticsearch to current events "
|
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/logstash-plugin install gemname. This gem is not a stand-alone program"
|
@@ -289,7 +289,87 @@ describe LogStash::Filters::Elasticsearch do
|
|
289
289
|
end
|
290
290
|
|
291
291
|
end
|
292
|
-
|
293
292
|
end
|
294
293
|
|
294
|
+
describe "client" do
|
295
|
+
let(:config) do
|
296
|
+
{
|
297
|
+
"query" => "response: unknown"
|
298
|
+
}
|
299
|
+
end
|
300
|
+
let(:plugin) { described_class.new(config) }
|
301
|
+
let(:event) { LogStash::Event.new({}) }
|
302
|
+
|
303
|
+
before(:each) do
|
304
|
+
allow(plugin).to receive(:test_connection!)
|
305
|
+
end
|
306
|
+
|
307
|
+
after(:each) do
|
308
|
+
Thread.current[:filter_elasticsearch_client] = nil
|
309
|
+
end
|
310
|
+
|
311
|
+
describe "cloud.id" do
|
312
|
+
let(:valid_cloud_id) do
|
313
|
+
'sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA=='
|
314
|
+
end
|
315
|
+
|
316
|
+
let(:config) { super.merge({ 'cloud_id' => valid_cloud_id }) }
|
317
|
+
|
318
|
+
it "should set host(s)" do
|
319
|
+
plugin.register
|
320
|
+
client = plugin.send(:get_client).client
|
321
|
+
expect( client.transport.hosts ).to eql [{
|
322
|
+
:scheme => "https",
|
323
|
+
:host => "ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io",
|
324
|
+
:port => 9243,
|
325
|
+
:path => "",
|
326
|
+
:protocol => "https"
|
327
|
+
}]
|
328
|
+
end
|
329
|
+
|
330
|
+
context 'invalid' do
|
331
|
+
let(:config) { super.merge({ 'cloud_id' => 'invalid:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlv' }) }
|
332
|
+
|
333
|
+
it "should fail" do
|
334
|
+
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_id.*? is invalid/
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
context 'hosts also set' do
|
339
|
+
let(:config) { super.merge({ 'cloud_id' => valid_cloud_id, 'hosts' => [ 'localhost:9200' ] }) }
|
340
|
+
|
341
|
+
it "should fail" do
|
342
|
+
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_id and hosts/
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end if LOGSTASH_VERSION > '6.0'
|
346
|
+
|
347
|
+
describe "cloud.auth" do
|
348
|
+
let(:config) { super.merge({ 'cloud_auth' => LogStash::Util::Password.new('elastic:my-passwd-00') }) }
|
349
|
+
|
350
|
+
it "should set authorization" do
|
351
|
+
plugin.register
|
352
|
+
client = plugin.send(:get_client).client
|
353
|
+
auth_header = client.transport.options[:transport_options][:headers][:Authorization]
|
354
|
+
|
355
|
+
expect( auth_header ).to eql "Basic #{Base64.encode64('elastic:my-passwd-00').rstrip}"
|
356
|
+
end
|
357
|
+
|
358
|
+
context 'invalid' do
|
359
|
+
let(:config) { super.merge({ 'cloud_auth' => 'invalid-format' }) }
|
360
|
+
|
361
|
+
it "should fail" do
|
362
|
+
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_auth.*? format/
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
context 'user also set' do
|
367
|
+
let(:config) { super.merge({ 'cloud_auth' => 'elastic:my-passwd-00', 'user' => 'another' }) }
|
368
|
+
|
369
|
+
it "should fail" do
|
370
|
+
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_auth and user/
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end if LOGSTASH_VERSION > '6.0'
|
374
|
+
end
|
295
375
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|