logstash-filter-rest 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2468297289c6978316c5d27c664d5c162cd0412c
4
- data.tar.gz: 6bb1e1e69ef6ac4409e14e4170b81ea46f657094
3
+ metadata.gz: 798eff3d04ef565f8b78b1692b53f05a3d823271
4
+ data.tar.gz: 94d72901fbfea799a846785bd63fbe3d85fd6349
5
5
  SHA512:
6
- metadata.gz: 01227dc244aeb7c369dd7d5127423ce63e21cedc63797052ec30164c7800906141a2b5249de77c4adb8d6f053d7d949790a5a8120d9e1fdcb42f2e256932ab15
7
- data.tar.gz: b5d5599af27a350e07122ff29cea1dd94d9f4866005568c38a062bb1a4ac6a4e576161c457f5c59e8b145248943b46a51c9bd7e738714629e186b9daea2edd82
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 = event.sprintf(@sprintf_fields).to_object
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.1'
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'
@@ -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 => 'foo'
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.1
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-01-03 00:00:00.000000000 Z
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