logstash-filter-rest 0.5.1 → 0.5.2
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 +6 -0
- data/lib/logstash/filters/rest.rb +21 -11
- data/logstash-filter-rest.gemspec +1 -1
- data/spec/filters/rest_spec.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 798eff3d04ef565f8b78b1692b53f05a3d823271
|
4
|
+
data.tar.gz: 94d72901fbfea799a846785bd63fbe3d85fd6349
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 777e34a187f60db34636e69380432f020daf8dc9c7928252ea2938d65a5f35f27f8146cd40831eb7ab9eec66c4b0a3f47fd6c1f3d5003cb92eee65e2b6ecf237
|
7
|
+
data.tar.gz: c8a295158a7dad5737cc5ddec33d53c1ab8d3e6c6f81d05980b126617d4ccfcd74fae0cce0cd50a7702486b04368fafffeb1a12cf1302206410fc4d85efe7b3f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.5.2
|
2
|
+
- Fix behavior, where a referenced field (`%{...}`) has `ruby` chars
|
3
|
+
(i.e., consisting of `:`)
|
4
|
+
- Field interpolation is done by assigning explicit values instead
|
5
|
+
of converting the `sprintf` string back into a `hash`
|
6
|
+
|
1
7
|
## 0.5.0
|
2
8
|
- Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99
|
3
9
|
- Require devutils >= 0 to make `bundler` update the package
|
@@ -16,16 +16,6 @@ class Hash
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
# Monkey Patch string to parse to hsh
|
20
|
-
class String
|
21
|
-
def to_object(symbolize = true)
|
22
|
-
LogStash::Json.load(
|
23
|
-
gsub(/:([a-zA-z]+)/, '"\\1"').gsub('=>', ': '),
|
24
|
-
:symbolize_keys => symbolize
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
19
|
# Monkey Patch Array with deep freeze
|
30
20
|
class Array
|
31
21
|
def deep_freeze
|
@@ -254,13 +244,33 @@ class LogStash::Filters::Rest < LogStash::Filters::Base
|
|
254
244
|
end
|
255
245
|
end
|
256
246
|
|
247
|
+
private
|
248
|
+
|
249
|
+
def field_intrpl(intrpl_fields, event)
|
250
|
+
return intrpl_fields if intrpl_fields.empty?
|
251
|
+
return event.sprintf(intrpl_fields) unless intrpl_fields.respond_to?(:each)
|
252
|
+
case intrpl_fields
|
253
|
+
when Array
|
254
|
+
result = []
|
255
|
+
intrpl_fields.each do |v|
|
256
|
+
result << field_intrpl(v, event)
|
257
|
+
end
|
258
|
+
when Hash
|
259
|
+
result = {}
|
260
|
+
intrpl_fields.each do |k, v|
|
261
|
+
result[k] = field_intrpl(v, event)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
result
|
265
|
+
end
|
266
|
+
|
257
267
|
public
|
258
268
|
|
259
269
|
def filter(event)
|
260
270
|
return unless filter?(event)
|
261
271
|
@logger.debug? && @logger.debug('Parsing event fields',
|
262
272
|
:sprintf_fields => @sprintf_fields)
|
263
|
-
parsed_request_fields =
|
273
|
+
parsed_request_fields = field_intrpl(@sprintf_fields, event)
|
264
274
|
parsed_request_fields.each do |v|
|
265
275
|
case v
|
266
276
|
when Hash
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-filter-rest'
|
3
|
-
s.version = '0.5.
|
3
|
+
s.version = '0.5.2'
|
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-rest. This gem is not a stand-alone program'
|
data/spec/filters/rest_spec.rb
CHANGED
@@ -210,7 +210,7 @@ describe LogStash::Filters::Rest do
|
|
210
210
|
url => 'https://jsonplaceholder.typicode.com/posts'
|
211
211
|
method => 'post'
|
212
212
|
params => {
|
213
|
-
title => '
|
213
|
+
title => '%{message}'
|
214
214
|
body => 'bar'
|
215
215
|
userId => "%{message}"
|
216
216
|
}
|
@@ -228,9 +228,24 @@ describe LogStash::Filters::Rest do
|
|
228
228
|
sample('message' => '42') do
|
229
229
|
expect(subject).to include('rest')
|
230
230
|
expect(subject.get('rest')).to include('id')
|
231
|
+
expect(subject.get('[rest][title]')).to eq(42)
|
231
232
|
expect(subject.get('[rest][userId]')).to eq(42)
|
232
233
|
expect(subject.get('rest')).to_not include('fallback')
|
233
234
|
end
|
235
|
+
sample('message' => ':5e?#!-_') do
|
236
|
+
expect(subject).to include('rest')
|
237
|
+
expect(subject.get('rest')).to include('id')
|
238
|
+
expect(subject.get('[rest][title]')).to eq(':5e?#!-_')
|
239
|
+
expect(subject.get('[rest][userId]')).to eq(':5e?#!-_')
|
240
|
+
expect(subject.get('rest')).to_not include('fallback')
|
241
|
+
end
|
242
|
+
sample('message' => ':4c43=>') do
|
243
|
+
expect(subject).to include('rest')
|
244
|
+
expect(subject.get('rest')).to include('id')
|
245
|
+
expect(subject.get('[rest][title]')).to eq(':4c43=>')
|
246
|
+
expect(subject.get('[rest][userId]')).to eq(':4c43=>')
|
247
|
+
expect(subject.get('rest')).to_not include('fallback')
|
248
|
+
end
|
234
249
|
end
|
235
250
|
describe 'Set to Rest Filter Post with body sprintf' do
|
236
251
|
let(:config) do <<-CONFIG
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Henning
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|