logstash-filter-http 1.0.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/LICENSE +199 -10
- data/README.md +1 -1
- data/lib/logstash/filters/http.rb +44 -10
- data/logstash-filter-http.gemspec +4 -2
- data/spec/filters/http_spec.rb +139 -54
- metadata +31 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d5469fab82031f6b39e205f18142291d9896c97cd4b650c5124ff0f661ca945
|
4
|
+
data.tar.gz: 878169ea102e2c342fabed654cc8d265df31a7a935fbe8dd4260f79c2b393fce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f0f5d51f50ec667de851cf7223d004062d3946c1bc0ee4b849edb3de26bc3da5246a168502c3a169023d646772835f79ebf990daf615085e4ce57a8ed5cc2db
|
7
|
+
data.tar.gz: 25d1125226d4c5adbc0bb74bac0ba1d0e7aa02eba55d765e0a15c084638efea664bab10e618eeb80d85e36cc4e94140708c93b26fab6843e3c9a15d13947732a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 1.2.1
|
2
|
+
- Fix: do not set content-type if provided by user [#36](https://github.com/logstash-plugins/logstash-filter-http/pull/36)
|
3
|
+
|
4
|
+
## 1.2.0
|
5
|
+
- Feat: improve ECS compatibility [#35](https://github.com/logstash-plugins/logstash-filter-http/pull/35)
|
6
|
+
|
7
|
+
## 1.1.0
|
8
|
+
- Add support for PUT requests [#34](https://github.com/logstash-plugins/logstash-filter-http/pull/34)
|
9
|
+
|
10
|
+
## 1.0.2
|
11
|
+
- Fixed exception when using debug logging [#14](https://github.com/logstash-plugins/logstash-filter-http/pull/14)
|
12
|
+
|
1
13
|
## 1.0.1
|
2
14
|
- Fixed minor documentation issues [#9](https://github.com/logstash-plugins/logstash-filter-http/pull/9)
|
3
15
|
|
data/LICENSE
CHANGED
@@ -1,13 +1,202 @@
|
|
1
|
-
Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
6
5
|
|
7
|
-
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2020 Elastic and contributors
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Logstash REST Filter [![Build Status](https://travis-ci.
|
1
|
+
# Logstash REST Filter [![Build Status](https://travis-ci.com/logstash-plugins/logstash-filter-http.svg?branch=master)](https://travis-ci.com/logstash-plugins/logstash-filter-http)
|
2
2
|
|
3
3
|
This is a filter plugin for [Logstash](https://github.com/elastic/logstash).
|
4
4
|
|
@@ -1,18 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'logstash/filters/base'
|
3
|
+
require 'logstash/json'
|
3
4
|
require 'logstash/namespace'
|
4
5
|
require 'logstash/plugin_mixins/http_client'
|
5
|
-
require 'logstash/
|
6
|
+
require 'logstash/plugin_mixins/ecs_compatibility_support'
|
7
|
+
require 'logstash/plugin_mixins/ecs_compatibility_support/target_check'
|
8
|
+
require 'logstash/plugin_mixins/validator_support/field_reference_validation_adapter'
|
6
9
|
|
7
10
|
# Logstash HTTP Filter
|
8
11
|
# This filter calls a defined URL and saves the answer into a specified field.
|
9
12
|
#
|
10
13
|
class LogStash::Filters::Http < LogStash::Filters::Base
|
14
|
+
|
15
|
+
include LogStash::PluginMixins::ECSCompatibilitySupport(:disabled, :v1, :v8 => :v1)
|
16
|
+
|
17
|
+
extend LogStash::PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
|
18
|
+
|
11
19
|
include LogStash::PluginMixins::HttpClient
|
12
20
|
|
13
21
|
config_name 'http'
|
14
22
|
|
15
|
-
VALID_VERBS = ['GET', 'HEAD', 'PATCH', 'DELETE', 'POST']
|
23
|
+
VALID_VERBS = ['GET', 'HEAD', 'PATCH', 'DELETE', 'POST', 'PUT']
|
16
24
|
|
17
25
|
config :url, :validate => :string, :required => true
|
18
26
|
config :verb, :validate => VALID_VERBS, :required => false, :default => 'GET'
|
@@ -21,14 +29,28 @@ class LogStash::Filters::Http < LogStash::Filters::Base
|
|
21
29
|
config :body, :required => false
|
22
30
|
config :body_format, :validate => ['text', 'json'], :default => "text"
|
23
31
|
|
24
|
-
|
25
|
-
config :
|
32
|
+
# default [body] (legacy) required to be specified in ECS mode
|
33
|
+
config :target_body, :validate => :field_reference
|
34
|
+
# default [headers] (legacy) or [@metadata][filter][http][response][headers] in ECS mode
|
35
|
+
config :target_headers, :validate => :field_reference
|
26
36
|
|
27
37
|
# Append values to the `tags` field when there has been no
|
28
38
|
# successful match or json parsing error
|
29
39
|
config :tag_on_request_failure, :validate => :array, :default => ['_httprequestfailure']
|
30
40
|
config :tag_on_json_failure, :validate => :array, :default => ['_jsonparsefailure']
|
31
41
|
|
42
|
+
def initialize(*params)
|
43
|
+
super
|
44
|
+
|
45
|
+
@target_body ||= ecs_select[disabled: '[body]', v1: false]
|
46
|
+
if @target_body.eql? false # user needs to specify target in ECS mode
|
47
|
+
@logger.error missing_config_message(:target_body)
|
48
|
+
raise LogStash::ConfigurationError.new "Wrong configuration (in ecs_compatibility mode #{ecs_compatibility.inspect})"
|
49
|
+
end
|
50
|
+
|
51
|
+
@target_headers ||= ecs_select[disabled: '[headers]', v1: '[@metadata][filter][http][response][headers]']
|
52
|
+
end
|
53
|
+
|
32
54
|
def register
|
33
55
|
# nothing to see here
|
34
56
|
@verb = verb.downcase
|
@@ -37,10 +59,8 @@ class LogStash::Filters::Http < LogStash::Filters::Base
|
|
37
59
|
def filter(event)
|
38
60
|
url_for_event = event.sprintf(@url)
|
39
61
|
headers_sprintfed = sprintf_object(event, @headers)
|
40
|
-
if
|
41
|
-
headers_sprintfed[
|
42
|
-
else
|
43
|
-
headers_sprintfed["content-type"] = "text/plain"
|
62
|
+
if !headers_sprintfed.key?('content-type') && !headers_sprintfed.key?('Content-Type')
|
63
|
+
headers_sprintfed['content-type'] = @body_format == "json" ? "application/json" : "text/plain"
|
44
64
|
end
|
45
65
|
query_sprintfed = sprintf_object(event, @query)
|
46
66
|
body_sprintfed = sprintf_object(event, @body)
|
@@ -51,7 +71,7 @@ class LogStash::Filters::Http < LogStash::Filters::Base
|
|
51
71
|
|
52
72
|
options = { :headers => headers_sprintfed, :query => query_sprintfed, :body => body_sprintfed }
|
53
73
|
|
54
|
-
@logger.debug? && @logger.debug('processing request', :url => url_for_event, :headers => headers_sprintfed, :
|
74
|
+
@logger.debug? && @logger.debug('processing request', :url => url_for_event, :headers => headers_sprintfed, :query => query_sprintfed)
|
55
75
|
client_error = nil
|
56
76
|
|
57
77
|
begin
|
@@ -62,7 +82,7 @@ class LogStash::Filters::Http < LogStash::Filters::Base
|
|
62
82
|
|
63
83
|
if client_error
|
64
84
|
@logger.error('error during HTTP request',
|
65
|
-
:url => url_for_event, :body =>
|
85
|
+
:url => url_for_event, :body => body_sprintfed,
|
66
86
|
:client_error => client_error.message)
|
67
87
|
@tag_on_request_failure.each { |tag| event.tag(tag) }
|
68
88
|
elsif !code.between?(200, 299)
|
@@ -79,6 +99,20 @@ class LogStash::Filters::Http < LogStash::Filters::Base
|
|
79
99
|
end # def filter
|
80
100
|
|
81
101
|
private
|
102
|
+
|
103
|
+
def missing_config_message(name)
|
104
|
+
<<-EOF
|
105
|
+
Missing a required setting for the http filter plugin:
|
106
|
+
|
107
|
+
filter {
|
108
|
+
http {
|
109
|
+
#{name} => # SETTING MISSING
|
110
|
+
...
|
111
|
+
}
|
112
|
+
}
|
113
|
+
EOF
|
114
|
+
end
|
115
|
+
|
82
116
|
def request_http(verb, url, options = {})
|
83
117
|
response = client.http(verb, url, options)
|
84
118
|
[response.code, response.headers, response.body]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-filter-http'
|
3
|
-
s.version = '1.
|
3
|
+
s.version = '1.2.1'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = 'This filter requests data from a RESTful Web Service.'
|
6
6
|
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 logstash-filter-http. This gem is not a stand-alone program'
|
@@ -27,7 +27,9 @@ Gem::Specification.new do |s|
|
|
27
27
|
|
28
28
|
# Gem dependencies
|
29
29
|
s.add_runtime_dependency 'logstash-core-plugin-api', '>= 1.60', '<= 2.99'
|
30
|
+
s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.2'
|
30
31
|
s.add_runtime_dependency 'logstash-mixin-http_client', '>= 5.0.0', '< 9.0.0'
|
32
|
+
s.add_runtime_dependency 'logstash-mixin-validator_support', '~> 1.0'
|
31
33
|
|
32
|
-
s.add_development_dependency 'logstash-devutils'
|
34
|
+
s.add_development_dependency 'logstash-devutils'
|
33
35
|
end
|
data/spec/filters/http_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'logstash/devutils/rspec/spec_helper'
|
2
|
+
require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper'
|
2
3
|
require 'logstash/filters/http'
|
3
4
|
|
4
5
|
describe LogStash::Filters::Http do
|
@@ -6,34 +7,74 @@ describe LogStash::Filters::Http do
|
|
6
7
|
let(:event) { LogStash::Event.new(data) }
|
7
8
|
let(:data) { { "message" => "test" } }
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
let(:url) { 'https://a-non-existent.url1' }
|
11
|
+
let(:config) { { "url" => url, 'target_body' => '[the][body]' } }
|
12
|
+
|
13
|
+
let(:response) { [200, {}, "Bom dia"] }
|
14
|
+
|
15
|
+
describe 'target_body default', :ecs_compatibility_support do
|
16
|
+
|
17
|
+
let(:config) { { "url" => url, "ecs_compatibility" => ecs_compatibility } }
|
18
|
+
|
19
|
+
ecs_compatibility_matrix(:disabled, :v1, :v8) do |ecs_select|
|
20
|
+
|
21
|
+
it "has a default body_target (in legacy mode)" do
|
22
|
+
subject.register
|
23
|
+
allow(subject).to receive(:request_http).and_return(response)
|
24
|
+
subject.filter(event)
|
25
|
+
|
26
|
+
expect(event.get('body')).to eq("Bom dia")
|
27
|
+
end if ecs_select.active_mode == :disabled
|
28
|
+
|
29
|
+
it "fails due missing body_target (in ECS mode)" do
|
30
|
+
expect { subject }.to raise_error(LogStash::ConfigurationError)
|
31
|
+
end if ecs_select.active_mode != :disabled
|
32
|
+
|
14
33
|
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'response body handling', :ecs_compatibility_support do
|
38
|
+
|
39
|
+
let(:url) { 'http://laceholder.typicode.com/users/10' }
|
40
|
+
|
15
41
|
before(:each) do
|
42
|
+
subject.register
|
43
|
+
|
16
44
|
allow(subject).to receive(:request_http).and_return(response)
|
17
45
|
subject.filter(event)
|
18
46
|
end
|
19
47
|
|
20
|
-
|
21
|
-
|
48
|
+
ecs_compatibility_matrix(:disabled, :v1, :v8) do
|
49
|
+
|
50
|
+
let(:config) { super().merge "ecs_compatibility" => ecs_compatibility, 'target_body' => 'gw-response' }
|
51
|
+
|
52
|
+
context "when body is JSON" do
|
53
|
+
context "and headers are set correctly" do
|
54
|
+
|
55
|
+
let(:response) { [200, {"content-type" => "application/json"}, "{\"id\": 10}"] }
|
56
|
+
|
57
|
+
it "fetches and writes body to target" do
|
58
|
+
expect(event.get('[gw-response][id]')).to eq(10)
|
59
|
+
end
|
22
60
|
|
23
|
-
|
24
|
-
expect(event.get('rest')).to eq("Bom dia")
|
61
|
+
end
|
25
62
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
let(:
|
63
|
+
|
64
|
+
context 'with body target' do
|
65
|
+
|
66
|
+
let(:config) { super().merge "target_body" => '[rest]' }
|
30
67
|
|
31
68
|
it "fetches and writes body to target" do
|
32
|
-
expect(event.get('
|
69
|
+
expect(event.get('rest')).to eq("Bom dia")
|
70
|
+
expect(event.include?('body')).to be false
|
33
71
|
end
|
72
|
+
|
34
73
|
end
|
74
|
+
|
35
75
|
end
|
36
76
|
end
|
77
|
+
|
37
78
|
describe 'URL parameter' do
|
38
79
|
before(:each) { subject.register }
|
39
80
|
context "when url contains field references" do
|
@@ -45,6 +86,7 @@ describe LogStash::Filters::Http do
|
|
45
86
|
it "interpolates request url using event data" do
|
46
87
|
expect(subject).to receive(:request_http).with(anything, "http://stringsize.com/test", anything).and_return(response)
|
47
88
|
subject.filter(event)
|
89
|
+
expect(event.get('size')).to eql '4'
|
48
90
|
end
|
49
91
|
end
|
50
92
|
end
|
@@ -68,38 +110,77 @@ describe LogStash::Filters::Http do
|
|
68
110
|
expect(event.get('tags')).to include('_httprequestfailure')
|
69
111
|
end
|
70
112
|
end
|
71
|
-
|
113
|
+
|
114
|
+
describe "headers", :ecs_compatibility_support do
|
72
115
|
before(:each) { subject.register }
|
73
|
-
let(:response)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
116
|
+
let(:response) do
|
117
|
+
response_headers = {
|
118
|
+
'Server' => 'Apache',
|
119
|
+
'Last-Modified' => 'Mon, 18 Jul 2016 02:36:04 GMT',
|
120
|
+
'X-Backend-Server' => 'logstash.elastic.co',
|
121
|
+
}
|
122
|
+
[200, response_headers, "Bom dia"]
|
123
|
+
end
|
124
|
+
|
125
|
+
let(:url) { "http://stringsize.com" }
|
126
|
+
|
127
|
+
ecs_compatibility_matrix(:disabled, :v1) do |ecs_select|
|
128
|
+
|
129
|
+
let(:config) { super().merge "ecs_compatibility" => ecs_compatibility }
|
130
|
+
|
131
|
+
it "sets response headers in the event" do
|
132
|
+
expect(subject).to receive(:request_http).with(anything, config['url'], anything).and_return(response)
|
133
|
+
|
134
|
+
subject.filter(event)
|
135
|
+
|
136
|
+
if ecs_select.active_mode == :disabled
|
137
|
+
expect(event.get('headers')).to include "Server" => "Apache"
|
138
|
+
expect(event.get('headers')).to include "X-Backend-Server" => "logstash.elastic.co"
|
139
|
+
else
|
140
|
+
expect(event.include?('headers')).to be false
|
141
|
+
expect(event.get('[@metadata][filter][http][response][headers]')).to include "Server" => "Apache"
|
142
|
+
expect(event.get('[@metadata][filter][http][response][headers]')).to include "X-Backend-Server" => "logstash.elastic.co"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'with a headers target' do
|
147
|
+
|
148
|
+
let(:config) { super().merge "target_headers" => '[res][headers]' }
|
149
|
+
|
150
|
+
it "sets response headers in the event" do
|
151
|
+
expect(subject).to receive(:request_http).with(anything, config['url'], anything).and_return(response)
|
152
|
+
|
153
|
+
subject.filter(event)
|
154
|
+
|
155
|
+
expect(event.get('[res][headers]')).to include "Server" => "Apache"
|
156
|
+
expect(event.get('[res][headers]').keys).to include "Last-Modified"
|
157
|
+
end
|
158
|
+
|
82
159
|
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
context "(extra) request headers" do
|
164
|
+
let(:headers) { { "Cache-Control" => "nocache" } }
|
165
|
+
let(:config) { super().merge "headers" => headers }
|
166
|
+
|
83
167
|
it "are included in the request" do
|
84
168
|
expect(subject).to receive(:request_http) do |verb, url, options|
|
85
|
-
expect(options.fetch(:headers, {})).to include(headers)
|
169
|
+
expect( options.fetch(:headers, {}) ).to include(headers)
|
86
170
|
end.and_return(response)
|
171
|
+
|
87
172
|
subject.filter(event)
|
88
173
|
end
|
89
174
|
end
|
90
175
|
end
|
176
|
+
|
91
177
|
describe "query string parameters" do
|
92
178
|
before(:each) { subject.register }
|
93
179
|
let(:response) { [200, {}, "Bom dia"] }
|
94
180
|
context "when set" do
|
95
181
|
let(:query) { { "color" => "green" } }
|
96
|
-
let(:config)
|
97
|
-
|
98
|
-
"url" => "http://stringsize.com/%{message}",
|
99
|
-
"target_body" => "size",
|
100
|
-
"query" => query
|
101
|
-
}
|
102
|
-
end
|
182
|
+
let(:config) { super().merge "query" => query }
|
183
|
+
|
103
184
|
it "are included in the request" do
|
104
185
|
expect(subject).to receive(:request_http).with(anything, anything, include(:query => query)).and_return(response)
|
105
186
|
subject.filter(event)
|
@@ -109,21 +190,11 @@ describe LogStash::Filters::Http do
|
|
109
190
|
describe "request body" do
|
110
191
|
before(:each) { subject.register }
|
111
192
|
let(:response) { [200, {}, "Bom dia"] }
|
112
|
-
let(:
|
113
|
-
|
114
|
-
"url" => "http://stringsize.com",
|
115
|
-
"body" => body
|
116
|
-
}
|
117
|
-
end
|
193
|
+
let(:url) { "http://stringsize.com" }
|
194
|
+
let(:config) { super().merge "body" => body }
|
118
195
|
|
119
196
|
describe "format" do
|
120
|
-
let(:config)
|
121
|
-
{
|
122
|
-
"url" => "http://stringsize.com",
|
123
|
-
"body_format" => body_format,
|
124
|
-
"body" => body
|
125
|
-
}
|
126
|
-
end
|
197
|
+
let(:config) { super().merge "body_format" => body_format, "body" => body }
|
127
198
|
|
128
199
|
context "when is json" do
|
129
200
|
let(:body_format) { "json" }
|
@@ -138,12 +209,14 @@ describe LogStash::Filters::Http do
|
|
138
209
|
end.and_return(response)
|
139
210
|
subject.filter(event)
|
140
211
|
end
|
212
|
+
|
141
213
|
it "sets content-type to application/json" do
|
142
214
|
expect(subject).to receive(:request_http) do |verb, url, options|
|
143
215
|
expect(options).to include(:headers => { "content-type" => "application/json"})
|
144
216
|
end.and_return(response)
|
145
217
|
subject.filter(event)
|
146
218
|
end
|
219
|
+
|
147
220
|
end
|
148
221
|
context "when is text" do
|
149
222
|
let(:body_format) { "text" }
|
@@ -155,12 +228,29 @@ describe LogStash::Filters::Http do
|
|
155
228
|
end.and_return(response)
|
156
229
|
subject.filter(event)
|
157
230
|
end
|
231
|
+
|
158
232
|
it "sets content-type to text/plain" do
|
159
233
|
expect(subject).to receive(:request_http) do |verb, url, options|
|
160
234
|
expect(options).to include(:headers => { "content-type" => "text/plain"})
|
161
235
|
end.and_return(response)
|
162
236
|
subject.filter(event)
|
163
237
|
end
|
238
|
+
|
239
|
+
context 'content-type header present' do
|
240
|
+
|
241
|
+
let(:config) { super().merge 'headers' => { 'X-UA' => 'FOO', 'Content-Type' => 'application/x-www-form-urlencoded' } }
|
242
|
+
|
243
|
+
it "respects set header and does not add another" do
|
244
|
+
expect(subject).to receive(:request_http) do |verb, url, options|
|
245
|
+
headers = options[:headers]
|
246
|
+
expect(headers).to include("Content-Type" => "application/x-www-form-urlencoded")
|
247
|
+
expect(headers).to_not include("content-type")
|
248
|
+
end.and_return(response)
|
249
|
+
subject.filter(event)
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
164
254
|
end
|
165
255
|
end
|
166
256
|
context "when using field references" do
|
@@ -190,14 +280,9 @@ describe LogStash::Filters::Http do
|
|
190
280
|
end
|
191
281
|
describe "verb" do
|
192
282
|
let(:response) { [200, {}, "Bom dia"] }
|
193
|
-
let(:config)
|
194
|
-
|
195
|
-
|
196
|
-
"url" => "http://stringsize.com",
|
197
|
-
"target_body" => "size"
|
198
|
-
}
|
199
|
-
end
|
200
|
-
["GET", "HEAD", "POST", "DELETE"].each do |verb_string|
|
283
|
+
let(:config) { super().merge "verb" => verb }
|
284
|
+
|
285
|
+
["GET", "HEAD", "POST", "DELETE", "PATCH", "PUT"].each do |verb_string|
|
201
286
|
let(:verb) { verb_string }
|
202
287
|
context "when verb #{verb_string} is set" do
|
203
288
|
before(:each) { subject.register }
|
@@ -217,7 +302,7 @@ describe LogStash::Filters::Http do
|
|
217
302
|
end
|
218
303
|
|
219
304
|
=begin
|
220
|
-
# TODO refactor remaning tests to avoid
|
305
|
+
# TODO refactor remaning tests to avoid whole pipeline instantiation
|
221
306
|
describe 'empty response' do
|
222
307
|
let(:config) do <<-CONFIG
|
223
308
|
filter {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
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-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<="
|
31
31
|
- !ruby/object:Gem::Version
|
32
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: '1.2'
|
39
|
+
name: logstash-mixin-ecs_compatibility_support
|
40
|
+
prerelease: false
|
41
|
+
type: :runtime
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.2'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
requirement: !ruby/object:Gem::Requirement
|
35
49
|
requirements:
|
@@ -50,15 +64,26 @@ dependencies:
|
|
50
64
|
- - "<"
|
51
65
|
- !ruby/object:Gem::Version
|
52
66
|
version: 9.0.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
requirement: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '1.0'
|
73
|
+
name: logstash-mixin-validator_support
|
74
|
+
prerelease: false
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '1.0'
|
53
81
|
- !ruby/object:Gem::Dependency
|
54
82
|
requirement: !ruby/object:Gem::Requirement
|
55
83
|
requirements:
|
56
84
|
- - ">="
|
57
85
|
- !ruby/object:Gem::Version
|
58
86
|
version: '0'
|
59
|
-
- - "<"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2.0.0
|
62
87
|
name: logstash-devutils
|
63
88
|
prerelease: false
|
64
89
|
type: :development
|
@@ -67,9 +92,6 @@ dependencies:
|
|
67
92
|
- - ">="
|
68
93
|
- !ruby/object:Gem::Version
|
69
94
|
version: '0'
|
70
|
-
- - "<"
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: 2.0.0
|
73
95
|
description: This gem is a logstash plugin required to be installed on top of the
|
74
96
|
Logstash core pipeline using $LS_HOME/bin/logstash-plugin install logstash-filter-http.
|
75
97
|
This gem is not a stand-alone program
|
@@ -107,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
129
|
- !ruby/object:Gem::Version
|
108
130
|
version: '0'
|
109
131
|
requirements: []
|
110
|
-
|
111
|
-
rubygems_version: 2.6.13
|
132
|
+
rubygems_version: 3.1.6
|
112
133
|
signing_key:
|
113
134
|
specification_version: 4
|
114
135
|
summary: This filter requests data from a RESTful Web Service.
|