logstash-filter-elasticsearch 3.8.0 → 3.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/CONTRIBUTORS +2 -0
- data/README.md +1 -1
- data/docs/index.asciidoc +51 -28
- data/lib/logstash/filters/elasticsearch.rb +28 -11
- data/lib/logstash/filters/elasticsearch/client.rb +7 -3
- data/lib/logstash/filters/elasticsearch/patches/_elasticsearch_transport_http_manticore.rb +33 -0
- data/logstash-filter-elasticsearch.gemspec +3 -3
- data/spec/es_helper.rb +6 -2
- data/spec/filters/elasticsearch_spec.rb +57 -12
- data/spec/filters/integration/elasticsearch_spec.rb +34 -17
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c42fd982d06ded966f625f3665120e64edc9b8585a2e5086214a14dd41f6e2a
|
4
|
+
data.tar.gz: 8411efb4ab1747adf5d824c39d098ccc64660c657916920b1bb4a194e8baf8ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7be68bcfcd60db5d7b7c76ae484d382f8efb470abe5c33393330b1a2344b8b01e79f6a02038b2f37032783bd6abc045f44a12c504cac8b2ca1d534d110872a9
|
7
|
+
data.tar.gz: 57d1ab30bb38a717d3f1e8da8dc9b70fb2b1873bb8e2e482b67a0ae2396a32948842233d586cf8ea29831280ad4af7f284f73e5eef5bf0027a9f2040588cca4b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## 3.9.5
|
2
|
+
- Fixed SSL handshake hang indefinitely with proxy setup [#151](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/151)
|
3
|
+
|
4
|
+
## 3.9.4
|
5
|
+
- Fix: a regression (in LS 7.14.0) where due the elasticsearch client update (from 5.0.5 to 7.5.0) the `Authorization`
|
6
|
+
header isn't passed, this leads to the plugin not being able to leverage `user`/`password` credentials set by the user.
|
7
|
+
[#148](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/148)
|
8
|
+
- Fix: default setting for `hosts` not working (since 3.7.0) GH-147
|
9
|
+
- Fix: mutating @hosts variable which leads to issues with multiple worker threads GH-129
|
10
|
+
|
11
|
+
## 3.9.3
|
12
|
+
- [DOC] Update links to use shared attributes [#144](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/144)
|
13
|
+
|
14
|
+
## 3.9.2
|
15
|
+
- [DOC] Fixed links to restructured Logstash-to-cloud docs [#142](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/142)
|
16
|
+
|
17
|
+
## 3.9.1
|
18
|
+
- [DOC] Document the permissions required in secured clusters [#140](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/140)
|
19
|
+
|
20
|
+
## 3.9.0
|
21
|
+
- Add support to define a proxy with the proxy config option [#134](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/134)
|
22
|
+
|
1
23
|
## 3.8.0
|
2
24
|
- Added api_key support [#132](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/132)
|
3
25
|
|
data/CONTRIBUTORS
CHANGED
@@ -10,6 +10,8 @@ Contributors:
|
|
10
10
|
* Suyog Rao (suyograo)
|
11
11
|
* Adrian Solom (addrians)
|
12
12
|
* Colin Surprenant (colinsurprenant)
|
13
|
+
* Andres Rodriguez (roaksoax)
|
14
|
+
* Luca Belluccini (lucabelluccini)
|
13
15
|
|
14
16
|
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
15
17
|
Logstash, and you aren't on the list above and want to be, please let us know
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Logstash Plugin
|
2
2
|
|
3
|
-
[![Travis Build Status](https://travis-ci.
|
3
|
+
[![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-filter-elasticsearch.svg)](https://travis-ci.com/logstash-plugins/logstash-filter-elasticsearch)
|
4
4
|
|
5
5
|
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
6
6
|
|
data/docs/index.asciidoc
CHANGED
@@ -24,7 +24,8 @@ Search Elasticsearch for a previous log event and copy some fields from it
|
|
24
24
|
into the current event. Below are two complete examples of how this filter might
|
25
25
|
be used.
|
26
26
|
|
27
|
-
The first example uses the legacy 'query' parameter where the user is limited to
|
27
|
+
The first example uses the legacy 'query' parameter where the user is limited to
|
28
|
+
an Elasticsearch query_string.
|
28
29
|
Whenever logstash receives an "end" event, it uses this elasticsearch
|
29
30
|
filter to find the matching "start" event based on some operation identifier.
|
30
31
|
Then it copies the `@timestamp` field from the "start" event into a new field on
|
@@ -110,6 +111,12 @@ Authentication to a secure Elasticsearch cluster is possible using _one_ of the
|
|
110
111
|
* <<plugins-{type}s-{plugin}-cloud_auth>>
|
111
112
|
* <<plugins-{type}s-{plugin}-api_key>>
|
112
113
|
|
114
|
+
[id="plugins-{type}s-{plugin}-autz"]
|
115
|
+
==== Authorization
|
116
|
+
|
117
|
+
Authorization to a secure Elasticsearch cluster requires `read` permission at index level and `monitoring` permissions at cluster level.
|
118
|
+
The `monitoring` permission at cluster level is necessary to perform periodic connectivity checks.
|
119
|
+
|
113
120
|
[id="plugins-{type}s-{plugin}-options"]
|
114
121
|
==== Elasticsearch Filter Configuration Options
|
115
122
|
|
@@ -129,6 +136,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
129
136
|
| <<plugins-{type}s-{plugin}-hosts>> |<<array,array>>|No
|
130
137
|
| <<plugins-{type}s-{plugin}-index>> |<<string,string>>|No
|
131
138
|
| <<plugins-{type}s-{plugin}-password>> |<<password,password>>|No
|
139
|
+
| <<plugins-{type}s-{plugin}-proxy>> |<<uri,uri>>|No
|
132
140
|
| <<plugins-{type}s-{plugin}-query>> |<<string,string>>|No
|
133
141
|
| <<plugins-{type}s-{plugin}-query_template>> |<<string,string>>|No
|
134
142
|
| <<plugins-{type}s-{plugin}-result_size>> |<<number,number>>|No
|
@@ -167,9 +175,11 @@ Example:
|
|
167
175
|
* Value type is <<password,password>>
|
168
176
|
* There is no default value for this setting.
|
169
177
|
|
170
|
-
Authenticate using Elasticsearch API key. Note that this option also requires
|
178
|
+
Authenticate using Elasticsearch API key. Note that this option also requires
|
179
|
+
enabling the `ssl` option.
|
171
180
|
|
172
|
-
Format is `id:api_key` where `id` and `api_key` are as returned by the
|
181
|
+
Format is `id:api_key` where `id` and `api_key` are as returned by the
|
182
|
+
Elasticsearch {ref}/security-api-create-api-key.html[Create API key API].
|
173
183
|
|
174
184
|
[id="plugins-{type}s-{plugin}-ca_file"]
|
175
185
|
===== `ca_file`
|
@@ -179,6 +189,28 @@ Format is `id:api_key` where `id` and `api_key` are as returned by the Elasticse
|
|
179
189
|
|
180
190
|
SSL Certificate Authority file
|
181
191
|
|
192
|
+
[id="plugins-{type}s-{plugin}-cloud_auth"]
|
193
|
+
===== `cloud_auth`
|
194
|
+
|
195
|
+
* Value type is <<password,password>>
|
196
|
+
* There is no default value for this setting.
|
197
|
+
|
198
|
+
Cloud authentication string ("<username>:<password>" format) is an alternative for the `user`/`password` pair.
|
199
|
+
|
200
|
+
For more info, check out the
|
201
|
+
{logstash-ref}/connecting-to-cloud.html[Logstash-to-Cloud documentation].
|
202
|
+
|
203
|
+
[id="plugins-{type}s-{plugin}-cloud_id"]
|
204
|
+
===== `cloud_id`
|
205
|
+
|
206
|
+
* Value type is <<string,string>>
|
207
|
+
* There is no default value for this setting.
|
208
|
+
|
209
|
+
Cloud ID, from the Elastic Cloud web console. If set `hosts` should not be used.
|
210
|
+
|
211
|
+
For more info, check out the
|
212
|
+
{logstash-ref}/connecting-to-cloud.html[Logstash-to-Cloud documentation].
|
213
|
+
|
182
214
|
[id="plugins-{type}s-{plugin}-docinfo_fields"]
|
183
215
|
===== `docinfo_fields`
|
184
216
|
|
@@ -252,14 +284,26 @@ Field substitution (e.g. `index-name-%{date_field}`) is available
|
|
252
284
|
|
253
285
|
Basic Auth - password
|
254
286
|
|
287
|
+
[id="plugins-{type}s-{plugin}-proxy"]
|
288
|
+
===== `proxy`
|
289
|
+
|
290
|
+
* Value type is <<uri,uri>>
|
291
|
+
* There is no default value for this setting.
|
292
|
+
|
293
|
+
Set the address of a forward HTTP proxy.
|
294
|
+
An empty string is treated as if proxy was not set, and is useful when using
|
295
|
+
environment variables e.g. `proxy => '${LS_PROXY:}'`.
|
296
|
+
|
255
297
|
[id="plugins-{type}s-{plugin}-query"]
|
256
298
|
===== `query`
|
257
299
|
|
258
300
|
* Value type is <<string,string>>
|
259
301
|
* There is no default value for this setting.
|
260
302
|
|
261
|
-
Elasticsearch query string.
|
262
|
-
|
303
|
+
Elasticsearch query string. More information is available in the
|
304
|
+
{ref}/query-dsl-query-string-query.html#query-string-syntax[Elasticsearch query
|
305
|
+
string documentation].
|
306
|
+
|
263
307
|
|
264
308
|
[id="plugins-{type}s-{plugin}-query_template"]
|
265
309
|
===== `query_template`
|
@@ -267,8 +311,8 @@ for more info at: https://www.elastic.co/guide/en/elasticsearch/reference/master
|
|
267
311
|
* Value type is <<string,string>>
|
268
312
|
* There is no default value for this setting.
|
269
313
|
|
270
|
-
File path to elasticsearch query in DSL format.
|
271
|
-
|
314
|
+
File path to elasticsearch query in DSL format. More information is available in
|
315
|
+
the {ref}/query-dsl.html[Elasticsearch query documentation].
|
272
316
|
|
273
317
|
[id="plugins-{type}s-{plugin}-result_size"]
|
274
318
|
===== `result_size`
|
@@ -310,27 +354,6 @@ Tags the event on failure to look up previous log event information. This can be
|
|
310
354
|
|
311
355
|
Basic Auth - username
|
312
356
|
|
313
|
-
[id="plugins-{type}s-{plugin}-cloud_auth"]
|
314
|
-
===== `cloud_auth`
|
315
|
-
|
316
|
-
* Value type is <<password,password>>
|
317
|
-
* There is no default value for this setting.
|
318
|
-
|
319
|
-
Cloud authentication string ("<username>:<password>" format) is an alternative for the `user`/`password` pair.
|
320
|
-
|
321
|
-
For more info, check out the https://www.elastic.co/guide/en/logstash/current/connecting-to-cloud.html#_cloud_auth[Logstash-to-Cloud documentation]
|
322
|
-
|
323
|
-
[id="plugins-{type}s-{plugin}-cloud_id"]
|
324
|
-
===== `cloud_id`
|
325
|
-
|
326
|
-
* Value type is <<string,string>>
|
327
|
-
* There is no default value for this setting.
|
328
|
-
|
329
|
-
Cloud ID, from the Elastic Cloud web console. If set `hosts` should not be used.
|
330
|
-
|
331
|
-
For more info, check out the https://www.elastic.co/guide/en/logstash/current/connecting-to-cloud.html#_cloud_id[Logstash-to-Cloud documentation]
|
332
|
-
|
333
|
-
|
334
357
|
|
335
358
|
[id="plugins-{type}s-{plugin}-common-options"]
|
336
359
|
include::{include_path}/{type}.asciidoc[]
|
@@ -1,19 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "logstash/filters/base"
|
3
3
|
require "logstash/namespace"
|
4
|
-
require_relative "elasticsearch/client"
|
5
4
|
require "logstash/json"
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
require_relative "elasticsearch/client"
|
6
|
+
require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
|
9
7
|
|
10
8
|
class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
11
9
|
config_name "elasticsearch"
|
12
10
|
|
13
|
-
DEFAULT_HOST = ::LogStash::Util::SafeURI.new("//localhost:9200")
|
14
|
-
|
15
11
|
# List of elasticsearch hosts to use for querying.
|
16
|
-
config :hosts, :validate => :array, :default => [
|
12
|
+
config :hosts, :validate => :array, :default => [ 'localhost:9200' ]
|
17
13
|
|
18
14
|
# Comma-delimited list of index names to search; use `_all` or empty string to perform the operation on all indices.
|
19
15
|
# Field substitution (e.g. `index-name-%{date_field}`) is available
|
@@ -59,6 +55,9 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
59
55
|
# format is id:api_key (as returned by https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html[Create API key])
|
60
56
|
config :api_key, :validate => :password
|
61
57
|
|
58
|
+
# Set the address of a forward HTTP proxy.
|
59
|
+
config :proxy, :validate => :uri_or_empty
|
60
|
+
|
62
61
|
# SSL
|
63
62
|
config :ssl, :validate => :boolean, :default => false
|
64
63
|
|
@@ -76,6 +75,23 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
76
75
|
|
77
76
|
attr_reader :clients_pool
|
78
77
|
|
78
|
+
##
|
79
|
+
# @override to handle proxy => '' as if none was set
|
80
|
+
# @param value [Array<Object>]
|
81
|
+
# @param validator [nil,Array,Symbol]
|
82
|
+
# @return [Array(true,Object)]: if validation is a success, a tuple containing `true` and the coerced value
|
83
|
+
# @return [Array(false,String)]: if validation is a failure, a tuple containing `false` and the failure reason.
|
84
|
+
def self.validate_value(value, validator)
|
85
|
+
return super unless validator == :uri_or_empty
|
86
|
+
|
87
|
+
value = deep_replace(value)
|
88
|
+
value = hash_or_array(value)
|
89
|
+
|
90
|
+
return true, value.first if value.size == 1 && value.first.empty?
|
91
|
+
|
92
|
+
return super(value, :uri)
|
93
|
+
end
|
94
|
+
|
79
95
|
def register
|
80
96
|
@clients_pool = java.util.concurrent.ConcurrentHashMap.new
|
81
97
|
|
@@ -92,7 +108,7 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
92
108
|
fill_user_password_from_cloud_auth
|
93
109
|
fill_hosts_from_cloud_id
|
94
110
|
|
95
|
-
@hosts = Array(@hosts).map { |host| host.to_s } #
|
111
|
+
@hosts = Array(@hosts).map { |host| host.to_s } # potential SafeURI#to_s
|
96
112
|
|
97
113
|
test_connection!
|
98
114
|
end # def register
|
@@ -100,7 +116,7 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
100
116
|
def filter(event)
|
101
117
|
matched = false
|
102
118
|
begin
|
103
|
-
params = {:index => event.sprintf(@index) }
|
119
|
+
params = { :index => event.sprintf(@index) }
|
104
120
|
|
105
121
|
if @query_dsl
|
106
122
|
query = LogStash::Json.load(event.sprintf(@query_dsl))
|
@@ -167,6 +183,7 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
167
183
|
:user => @user,
|
168
184
|
:password => @password,
|
169
185
|
:api_key => @api_key,
|
186
|
+
:proxy => @proxy,
|
170
187
|
:ssl => @ssl,
|
171
188
|
:ca_file => @ca_file,
|
172
189
|
}
|
@@ -216,8 +233,7 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
216
233
|
end
|
217
234
|
|
218
235
|
def hosts_default?(hosts)
|
219
|
-
|
220
|
-
hosts.is_a?(Array) && hosts.size == 1 && hosts.first.equal?(DEFAULT_HOST)
|
236
|
+
hosts.is_a?(Array) && hosts.size == 1 && !original_params.key?('hosts')
|
221
237
|
end
|
222
238
|
|
223
239
|
def validate_authentication
|
@@ -252,6 +268,7 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
252
268
|
end
|
253
269
|
|
254
270
|
def parse_host_uri_from_cloud_id(cloud_id)
|
271
|
+
require 'logstash/util/safe_uri'
|
255
272
|
begin # might not be available on older LS
|
256
273
|
require 'logstash/util/cloud_setting_id'
|
257
274
|
rescue LoadError
|
@@ -15,12 +15,16 @@ module LogStash
|
|
15
15
|
user = options.fetch(:user, nil)
|
16
16
|
password = options.fetch(:password, nil)
|
17
17
|
api_key = options.fetch(:api_key, nil)
|
18
|
+
proxy = options.fetch(:proxy, nil)
|
18
19
|
|
19
20
|
transport_options = {:headers => {}}
|
20
21
|
transport_options[:headers].merge!(setup_basic_auth(user, password))
|
21
22
|
transport_options[:headers].merge!(setup_api_key(api_key))
|
22
23
|
|
23
|
-
|
24
|
+
logger.warn "Supplied proxy setting (proxy => '') has no effect" if @proxy.eql?('')
|
25
|
+
transport_options[:proxy] = proxy.to_s if proxy && !proxy.eql?('')
|
26
|
+
|
27
|
+
hosts = hosts.map { |host| { host: host, scheme: 'https' } } if ssl
|
24
28
|
# set ca_file even if ssl isn't on, since the host can be an https url
|
25
29
|
ssl_options = { ssl: true, ca_file: options[:ca_file] } if options[:ca_file]
|
26
30
|
ssl_options ||= {}
|
@@ -39,14 +43,14 @@ module LogStash
|
|
39
43
|
return {} unless user && password && password.value
|
40
44
|
|
41
45
|
token = ::Base64.strict_encode64("#{user}:#{password.value}")
|
42
|
-
{ Authorization
|
46
|
+
{ 'Authorization' => "Basic #{token}" }
|
43
47
|
end
|
44
48
|
|
45
49
|
def setup_api_key(api_key)
|
46
50
|
return {} unless (api_key && api_key.value)
|
47
51
|
|
48
52
|
token = ::Base64.strict_encode64(api_key.value)
|
49
|
-
{ Authorization
|
53
|
+
{ 'Authorization' => "ApiKey #{token}" }
|
50
54
|
end
|
51
55
|
end
|
52
56
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "elasticsearch"
|
3
|
+
require "elasticsearch/transport/transport/http/manticore"
|
4
|
+
|
5
|
+
es_client_version = Gem.loaded_specs['elasticsearch-transport'].version
|
6
|
+
if es_client_version >= Gem::Version.new('7.2') && es_client_version < Gem::Version.new('7.16')
|
7
|
+
# elasticsearch-transport 7.2.0 - 7.14.0 had a bug where setting http headers
|
8
|
+
# ES::Client.new ..., transport_options: { headers: { 'Authorization' => ... } }
|
9
|
+
# would be lost https://github.com/elastic/elasticsearch-ruby/issues/1428
|
10
|
+
#
|
11
|
+
# NOTE: needs to be idempotent as input ES plugin might apply the same patch!
|
12
|
+
#
|
13
|
+
# @private
|
14
|
+
module Elasticsearch
|
15
|
+
module Transport
|
16
|
+
module Transport
|
17
|
+
module HTTP
|
18
|
+
class Manticore
|
19
|
+
|
20
|
+
def apply_headers(request_options, options)
|
21
|
+
headers = (options && options[:headers]) || {}
|
22
|
+
headers[CONTENT_TYPE_STR] = find_value(headers, CONTENT_TYPE_REGEX) || DEFAULT_CONTENT_TYPE
|
23
|
+
headers[USER_AGENT_STR] = find_value(headers, USER_AGENT_REGEX) || user_agent_header
|
24
|
+
headers[ACCEPT_ENCODING] = GZIP if use_compression?
|
25
|
+
(request_options[:headers] ||= {}).merge!(headers) # this line was changed
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
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.9.5'
|
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"
|
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
# Gem dependencies
|
23
23
|
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
24
|
-
s.add_runtime_dependency 'elasticsearch', ">= 5.0.
|
25
|
-
s.add_runtime_dependency 'manticore', "
|
24
|
+
s.add_runtime_dependency 'elasticsearch', ">= 5.0.5" # LS >= 6.7 and < 7.14 all used version 5.0.5
|
25
|
+
s.add_runtime_dependency 'manticore', ">= 0.7.1"
|
26
26
|
|
27
27
|
s.add_development_dependency 'logstash-devutils'
|
28
28
|
end
|
data/spec/es_helper.rb
CHANGED
@@ -7,8 +7,12 @@ module ESHelper
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.get_client
|
11
|
-
|
10
|
+
def self.get_client(credentials)
|
11
|
+
require 'elasticsearch/transport/transport/http/faraday' # supports user/password options
|
12
|
+
host, port = get_host_port.split(':')
|
13
|
+
host_opts = credentials.inject({}) { |h, (k, v)| h[k.to_sym] = v; h } # user: _, password: _
|
14
|
+
host_opts.merge! host: host, port: port, scheme: 'http'
|
15
|
+
Elasticsearch::Client.new(hosts: [host_opts], transport_class: Elasticsearch::Transport::Transport::HTTP::Faraday)
|
12
16
|
end
|
13
17
|
|
14
18
|
def self.doc_type
|
@@ -313,12 +313,12 @@ describe LogStash::Filters::Elasticsearch do
|
|
313
313
|
'sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA=='
|
314
314
|
end
|
315
315
|
|
316
|
-
let(:config) { super.merge({ 'cloud_id' => valid_cloud_id }) }
|
316
|
+
let(:config) { super().merge({ 'cloud_id' => valid_cloud_id }) }
|
317
317
|
|
318
318
|
it "should set host(s)" do
|
319
319
|
plugin.register
|
320
320
|
client = plugin.send(:get_client).client
|
321
|
-
expect( client.
|
321
|
+
expect( extract_transport(client).hosts ).to eql [{
|
322
322
|
:scheme => "https",
|
323
323
|
:host => "ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io",
|
324
324
|
:port => 9243,
|
@@ -328,7 +328,7 @@ describe LogStash::Filters::Elasticsearch do
|
|
328
328
|
end
|
329
329
|
|
330
330
|
context 'invalid' do
|
331
|
-
let(:config) { super.merge({ 'cloud_id' => 'invalid:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlv' }) }
|
331
|
+
let(:config) { super().merge({ 'cloud_id' => 'invalid:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlv' }) }
|
332
332
|
|
333
333
|
it "should fail" do
|
334
334
|
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_id.*? is invalid/
|
@@ -336,7 +336,7 @@ describe LogStash::Filters::Elasticsearch do
|
|
336
336
|
end
|
337
337
|
|
338
338
|
context 'hosts also set' do
|
339
|
-
let(:config) { super.merge({ 'cloud_id' => valid_cloud_id, 'hosts' => [ 'localhost:9200' ] }) }
|
339
|
+
let(:config) { super().merge({ 'cloud_id' => valid_cloud_id, 'hosts' => [ 'localhost:9200' ] }) }
|
340
340
|
|
341
341
|
it "should fail" do
|
342
342
|
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_id and hosts/
|
@@ -345,18 +345,18 @@ describe LogStash::Filters::Elasticsearch do
|
|
345
345
|
end if LOGSTASH_VERSION > '6.0'
|
346
346
|
|
347
347
|
describe "cloud.auth" do
|
348
|
-
let(:config) { super.merge({ 'cloud_auth' => LogStash::Util::Password.new('elastic:my-passwd-00') }) }
|
348
|
+
let(:config) { super().merge({ 'cloud_auth' => LogStash::Util::Password.new('elastic:my-passwd-00') }) }
|
349
349
|
|
350
350
|
it "should set authorization" do
|
351
351
|
plugin.register
|
352
352
|
client = plugin.send(:get_client).client
|
353
|
-
auth_header = client.
|
353
|
+
auth_header = extract_transport(client).options[:transport_options][:headers]['Authorization']
|
354
354
|
|
355
355
|
expect( auth_header ).to eql "Basic #{Base64.encode64('elastic:my-passwd-00').rstrip}"
|
356
356
|
end
|
357
357
|
|
358
358
|
context 'invalid' do
|
359
|
-
let(:config) { super.merge({ 'cloud_auth' => 'invalid-format' }) }
|
359
|
+
let(:config) { super().merge({ 'cloud_auth' => 'invalid-format' }) }
|
360
360
|
|
361
361
|
it "should fail" do
|
362
362
|
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /cloud_auth.*? format/
|
@@ -364,7 +364,7 @@ describe LogStash::Filters::Elasticsearch do
|
|
364
364
|
end
|
365
365
|
|
366
366
|
context 'user also set' do
|
367
|
-
let(:config) { super.merge({ 'cloud_auth' => 'elastic:my-passwd-00', 'user' => 'another' }) }
|
367
|
+
let(:config) { super().merge({ 'cloud_auth' => 'elastic:my-passwd-00', 'user' => 'another' }) }
|
368
368
|
|
369
369
|
it "should fail" do
|
370
370
|
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/
|
@@ -374,7 +374,7 @@ describe LogStash::Filters::Elasticsearch do
|
|
374
374
|
|
375
375
|
describe "api_key" do
|
376
376
|
context "without ssl" do
|
377
|
-
let(:config) { super.merge({ 'api_key' => LogStash::Util::Password.new('foo:bar') }) }
|
377
|
+
let(:config) { super().merge({ 'api_key' => LogStash::Util::Password.new('foo:bar') }) }
|
378
378
|
|
379
379
|
it "should fail" do
|
380
380
|
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /api_key authentication requires SSL\/TLS/
|
@@ -382,18 +382,18 @@ describe LogStash::Filters::Elasticsearch do
|
|
382
382
|
end
|
383
383
|
|
384
384
|
context "with ssl" do
|
385
|
-
let(:config) { super.merge({ 'api_key' => LogStash::Util::Password.new('foo:bar'), "ssl" => true }) }
|
385
|
+
let(:config) { super().merge({ 'api_key' => LogStash::Util::Password.new('foo:bar'), "ssl" => true }) }
|
386
386
|
|
387
387
|
it "should set authorization" do
|
388
388
|
plugin.register
|
389
389
|
client = plugin.send(:get_client).client
|
390
|
-
auth_header = client.
|
390
|
+
auth_header = extract_transport(client).options[:transport_options][:headers]['Authorization']
|
391
391
|
|
392
392
|
expect( auth_header ).to eql "ApiKey #{Base64.strict_encode64('foo:bar')}"
|
393
393
|
end
|
394
394
|
|
395
395
|
context 'user also set' do
|
396
|
-
let(:config) { super.merge({ 'api_key' => 'foo:bar', 'user' => 'another' }) }
|
396
|
+
let(:config) { super().merge({ 'api_key' => 'foo:bar', 'user' => 'another' }) }
|
397
397
|
|
398
398
|
it "should fail" do
|
399
399
|
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/
|
@@ -401,6 +401,45 @@ describe LogStash::Filters::Elasticsearch do
|
|
401
401
|
end
|
402
402
|
end
|
403
403
|
end if LOGSTASH_VERSION > '6.0'
|
404
|
+
|
405
|
+
describe "proxy" do
|
406
|
+
context 'valid' do
|
407
|
+
let(:config) { super().merge({ 'proxy' => 'http://localhost:1234' }) }
|
408
|
+
|
409
|
+
it "should set proxy" do
|
410
|
+
plugin.register
|
411
|
+
client = plugin.send(:get_client).client
|
412
|
+
proxy = extract_transport(client).options[:transport_options][:proxy]
|
413
|
+
|
414
|
+
expect( proxy ).to eql "http://localhost:1234"
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
context 'invalid' do
|
419
|
+
let(:config) { super().merge({ 'proxy' => '${A_MISSING_ENV_VAR:}' }) }
|
420
|
+
|
421
|
+
it "should not set proxy" do
|
422
|
+
plugin.register
|
423
|
+
client = plugin.send(:get_client).client
|
424
|
+
|
425
|
+
expect( extract_transport(client).options[:transport_options] ).to_not include(:proxy)
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
describe "defaults" do
|
432
|
+
|
433
|
+
let(:config) { Hash.new }
|
434
|
+
let(:plugin) { described_class.new(config) }
|
435
|
+
|
436
|
+
before { allow(plugin).to receive(:test_connection!) }
|
437
|
+
|
438
|
+
it "should set localhost:9200 as hosts" do
|
439
|
+
plugin.register
|
440
|
+
client = plugin.send(:get_client).client
|
441
|
+
expect( extract_transport(client).hosts ).to eql [{ :host => "localhost", :port => 9200, :protocol => "http"}]
|
442
|
+
end
|
404
443
|
end
|
405
444
|
|
406
445
|
describe "query template" do
|
@@ -428,4 +467,10 @@ describe LogStash::Filters::Elasticsearch do
|
|
428
467
|
plugin.filter(LogStash::Event.new)
|
429
468
|
end
|
430
469
|
end
|
470
|
+
|
471
|
+
# @note can be removed once gem depends on elasticsearch >= 6.x
|
472
|
+
def extract_transport(client) # on 7.x client.transport is a ES::Transport::Client
|
473
|
+
client.transport.respond_to?(:transport) ? client.transport.transport : client.transport
|
474
|
+
end
|
475
|
+
|
431
476
|
end
|
@@ -6,21 +6,31 @@ require_relative "../../../spec/es_helper"
|
|
6
6
|
|
7
7
|
describe LogStash::Filters::Elasticsearch, :integration => true do
|
8
8
|
|
9
|
+
ELASTIC_SECURITY_ENABLED = ENV['ELASTIC_SECURITY_ENABLED'].eql? 'true'
|
9
10
|
|
10
|
-
let(:
|
11
|
+
let(:base_config) do
|
11
12
|
{
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
"index" => 'logs',
|
14
|
+
"hosts" => [ESHelper.get_host_port],
|
15
|
+
"query" => "response: 404",
|
16
|
+
"sort" => "response",
|
17
|
+
"fields" => [ ["response", "code"] ],
|
17
18
|
}
|
18
19
|
end
|
20
|
+
|
21
|
+
let(:credentials) do
|
22
|
+
{ 'user' => 'elastic', 'password' => ENV['ELASTIC_PASSWORD'] }
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:config) do
|
26
|
+
ELASTIC_SECURITY_ENABLED ? base_config.merge(credentials) : base_config
|
27
|
+
end
|
28
|
+
|
19
29
|
let(:plugin) { described_class.new(config) }
|
20
30
|
let(:event) { LogStash::Event.new({}) }
|
21
31
|
|
22
32
|
before(:each) do
|
23
|
-
@es = ESHelper.get_client
|
33
|
+
@es = ESHelper.get_client(ELASTIC_SECURITY_ENABLED ? credentials : {})
|
24
34
|
# Delete all templates first.
|
25
35
|
# Clean ES of data before we start.
|
26
36
|
@es.indices.delete_template(:name => "*")
|
@@ -30,11 +40,10 @@ describe LogStash::Filters::Elasticsearch, :integration => true do
|
|
30
40
|
ESHelper.index_doc(@es, :index => 'logs', :body => { :response => 404, :this => 'that'})
|
31
41
|
end
|
32
42
|
@es.indices.refresh
|
33
|
-
|
34
|
-
plugin.register
|
35
43
|
end
|
36
44
|
|
37
45
|
it "should enhance the current event with new data" do
|
46
|
+
plugin.register
|
38
47
|
plugin.filter(event)
|
39
48
|
expect(event.get('code')).to eq(404)
|
40
49
|
end
|
@@ -42,20 +51,28 @@ describe LogStash::Filters::Elasticsearch, :integration => true do
|
|
42
51
|
context "when retrieving a list of elements" do
|
43
52
|
|
44
53
|
let(:config) do
|
45
|
-
|
46
|
-
"index" => 'logs',
|
47
|
-
"hosts" => [ESHelper.get_host_port],
|
48
|
-
"query" => "response: 404",
|
49
|
-
"fields" => [ ["response", "code"] ],
|
50
|
-
"sort" => "response",
|
51
|
-
"result_size" => 10
|
52
|
-
}
|
54
|
+
super().merge("fields" => [ ["response", "code"] ], "result_size" => 10)
|
53
55
|
end
|
54
56
|
|
57
|
+
before { plugin.register }
|
58
|
+
|
55
59
|
it "should enhance the current event with new data" do
|
56
60
|
plugin.filter(event)
|
57
61
|
expect(event.get("code")).to eq([404]*10)
|
58
62
|
end
|
59
63
|
|
60
64
|
end
|
65
|
+
|
66
|
+
context "incorrect auth credentials" do
|
67
|
+
|
68
|
+
let(:config) do
|
69
|
+
super().reject { |key, _| key == 'password' }
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should enhance the current event with new data" do
|
73
|
+
expect { plugin.register }.to raise_error Elasticsearch::Transport::Transport::Errors::Unauthorized
|
74
|
+
end
|
75
|
+
|
76
|
+
end if ELASTIC_SECURITY_ENABLED
|
77
|
+
|
61
78
|
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.9.5
|
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: 2021-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
requirements:
|
36
36
|
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version: 5.0.
|
38
|
+
version: 5.0.5
|
39
39
|
name: elasticsearch
|
40
40
|
prerelease: false
|
41
41
|
type: :runtime
|
@@ -43,21 +43,21 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 5.0.
|
46
|
+
version: 5.0.5
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
|
-
- - "
|
50
|
+
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: 0.7.1
|
53
53
|
name: manticore
|
54
54
|
prerelease: false
|
55
55
|
type: :runtime
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 0.7.1
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- docs/index.asciidoc
|
90
90
|
- lib/logstash/filters/elasticsearch.rb
|
91
91
|
- lib/logstash/filters/elasticsearch/client.rb
|
92
|
+
- lib/logstash/filters/elasticsearch/patches/_elasticsearch_transport_http_manticore.rb
|
92
93
|
- logstash-filter-elasticsearch.gemspec
|
93
94
|
- spec/es_helper.rb
|
94
95
|
- spec/filters/elasticsearch_spec.rb
|
@@ -121,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: '0'
|
123
124
|
requirements: []
|
124
|
-
|
125
|
-
rubygems_version: 2.6.13
|
125
|
+
rubygems_version: 3.1.6
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Copies fields from previous log events in Elasticsearch to current events
|