logstash-filter-rest2 0.5.5 → 0.5.6

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
  SHA256:
3
- metadata.gz: 73bc32f0f3dfe3e5d5595e824370ab60504c4e05fedeeddc95bbf22116f98d99
4
- data.tar.gz: 753676d528768372a1caa807862e809d653ef04264eea27692b6c10425725324
3
+ metadata.gz: 5ab5b1d60c37832b9a11a67b2784b0b7de98c44634599f3d26e429a4b6ab5f12
4
+ data.tar.gz: 18b1e0aba93432f15a6f50802d7e9a5386159b274baeaeaeda5735e5176e002e
5
5
  SHA512:
6
- metadata.gz: ade33bab3d69e1973e9136fa1bdceefc6cff78a019df97520a0fa05eaec25e6b3841f4cb04dd941cacce11d60dc031c1e00e1c8db5c90dfbf8596890335ceb8d
7
- data.tar.gz: 51eb265f4a9d35bcd0238b386bb38cb04aa814914eaaba85183d48ec1a3cee13bae57d899efb0968e1b35eeb08a19672bb361c4c69a9e441a46dce62e52d1c0d
6
+ metadata.gz: aa63c876f7c13b3da5714d211f26176c4545bc7a97d9567aab881a41954fe0207ba0722e704a59912fcdfad76dc443b3eb2073861baee8e5f21962b1e25a845f
7
+ data.tar.gz: 88d7499efe89056b99aa273f688b98e1da4f8c1b5fe0d10d5c20f6ffb23d0e31a9430269bdaa7c48f6cd8ad70fed34e387129b5c91edbb2f62a3dc168ad62ff7
@@ -257,7 +257,11 @@ class LogStash::Filters::Rest < LogStash::Filters::Base
257
257
  end
258
258
  end
259
259
  else
260
- event.set(@target, response.strip)
260
+ begin
261
+ event.set(@target, response.strip)
262
+ rescue
263
+ event.set(@target, @fallback)
264
+ end
261
265
  end
262
266
  end
263
267
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-rest2'
3
- s.version = '0.5.5'
3
+ s.version = '0.5.6'
4
4
  s.licenses = ['Apache-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-rest2. This gem is not a stand-alone program'
@@ -27,7 +27,7 @@ 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-http_client', '>= 2.2.4', '< 6.0.0'
30
+ s.add_runtime_dependency 'logstash-mixin-http_client', '>= 5.0.0', '< 9.0.0'
31
31
 
32
32
  s.add_development_dependency 'logstash-devutils', '>= 0', '< 2.0.0'
33
33
  end
@@ -7,12 +7,8 @@ describe LogStash::Filters::Rest do
7
7
  filter {
8
8
  rest {
9
9
  request => {
10
- url => 'https://sbt-otib.sigma.sbrf.ru/otib/rest/application/12'
11
- truststore => "/var/app/ca2.jks"
12
- truststore_password => "password"
10
+ url => 'http://jsonplaceholder.typicode.com/users/10'
13
11
  }
14
- # truststore => "/var/app/ca2.jks"
15
- # truststore_password => "password1"
16
12
  json => true
17
13
  target => 'rest'
18
14
  }
@@ -27,405 +23,384 @@ describe LogStash::Filters::Rest do
27
23
  expect(subject.get('rest')).to_not include('fallback')
28
24
  end
29
25
  end
30
- # describe 'Set to Rest Filter Get without params' do
31
- # let(:config) do <<-CONFIG
32
- # filter {
33
- # rest {
34
- # request => {
35
- # url => 'http://jsonplaceholder.typicode.com/users/10'
36
- # }
37
- # json => true
38
- # target => 'rest'
39
- # }
40
- # }
41
- # CONFIG
42
- # end
43
- #
44
- # sample('message' => 'some text') do
45
- # expect(subject).to include('rest')
46
- # expect(subject.get('rest')).to include('id')
47
- # expect(subject.get('[rest][id]')).to eq(10)
48
- # expect(subject.get('rest')).to_not include('fallback')
49
- # end
50
- # end
51
- # describe 'Set to Rest Filter Get without params custom target' do
52
- # let(:config) do <<-CONFIG
53
- # filter {
54
- # rest {
55
- # request => {
56
- # url => 'http://jsonplaceholder.typicode.com/users/10'
57
- # }
58
- # json => true
59
- # target => 'testing'
60
- # }
61
- # }
62
- # CONFIG
63
- # end
64
- #
65
- # sample('message' => 'some text') do
66
- # expect(subject).to include('testing')
67
- # expect(subject.get('testing')).to include('id')
68
- # expect(subject.get('[testing][id]')).to eq(10)
69
- # expect(subject.get('testing')).to_not include('fallback')
70
- # end
71
- # end
72
- # describe 'Set to Rest Filter Get without params and sprintf' do
73
- # let(:config) do <<-CONFIG
74
- # filter {
75
- # rest {
76
- # request => {
77
- # url => "http://jsonplaceholder.typicode.com/users/%{message}"
78
- # }
79
- # json => true
80
- # sprintf => true
81
- # target => 'rest'
82
- # }
83
- # }
84
- # CONFIG
85
- # end
86
- #
87
- # sample('message' => '10') do
88
- # expect(subject).to include('rest')
89
- # expect(subject.get('rest')).to include('id')
90
- # expect(subject.get('[rest][id]')).to eq(10)
91
- # expect(subject.get('rest')).to_not include('fallback')
92
- # end
93
- # sample('message' => '9') do
94
- # expect(subject).to include('rest')
95
- # expect(subject.get('rest')).to include('id')
96
- # expect(subject.get('[rest][id]')).to eq(9)
97
- # expect(subject.get('rest')).to_not include('fallback')
98
- # end
99
- # end
100
- # describe 'Set to Rest Filter Get without params http error' do
101
- # let(:config) do <<-CONFIG
102
- # filter {
103
- # rest {
104
- # request => {
105
- # url => 'http://httpstat.us/404'
106
- # }
107
- # json => true
108
- # target => 'rest'
109
- # }
110
- # }
111
- # CONFIG
112
- # end
113
- #
114
- # sample('message' => 'some text') do
115
- # expect(subject).to_not include('rest')
116
- # expect(subject.get('tags')).to include('_restfailure')
117
- # end
118
- # end
119
- # describe 'Set to Rest Filter Get with params' do
120
- # let(:config) do <<-CONFIG
121
- # filter {
122
- # rest {
123
- # request => {
124
- # url => 'https://jsonplaceholder.typicode.com/posts'
125
- # params => {
126
- # userId => 10
127
- # }
128
- # headers => {
129
- # 'Content-Type' => 'application/json'
130
- # }
131
- # }
132
- # json => true
133
- # target => 'rest'
134
- # }
135
- # }
136
- # CONFIG
137
- # end
138
- #
139
- # sample('message' => 'some text') do
140
- # expect(subject).to include('rest')
141
- # expect(subject.get('[rest][0]')).to include('userId')
142
- # expect(subject.get('[rest][0][userId]')).to eq(10)
143
- # expect(subject.get('rest')).to_not include('fallback')
144
- # end
145
- # end
146
- # describe 'empty response' do
147
- # let(:config) do <<-CONFIG
148
- # filter {
149
- # rest {
150
- # request => {
151
- # url => 'https://jsonplaceholder.typicode.com/posts'
152
- # params => {
153
- # userId => 0
154
- # }
155
- # headers => {
156
- # 'Content-Type' => 'application/json'
157
- # }
158
- # }
159
- # target => 'rest'
160
- # }
161
- # }
162
- # CONFIG
163
- # end
164
- #
165
- # sample('message' => 'some text') do
166
- # expect(subject).to_not include('rest')
167
- # expect(subject.get('tags')).to include('_restfailure')
168
- # end
169
- # end
170
- # describe 'Set to Rest Filter Get with params sprintf' do
171
- # let(:config) do <<-CONFIG
172
- # filter {
173
- # rest {
174
- # request => {
175
- # url => 'https://jsonplaceholder.typicode.com/posts'
176
- # params => {
177
- # userId => "%{message}"
178
- # id => "%{message}"
179
- # }
180
- # headers => {
181
- # 'Content-Type' => 'application/json'
182
- # }
183
- # }
184
- # json => true
185
- # target => 'rest'
186
- # }
187
- # }
188
- # CONFIG
189
- # end
190
- #
191
- # sample('message' => '1') do
192
- # expect(subject).to include('rest')
193
- # expect(subject.get('[rest][0]')).to include('userId')
194
- # expect(subject.get('[rest][0][userId]')).to eq(1)
195
- # expect(subject.get('[rest][0][id]')).to eq(1)
196
- # expect(subject.get('rest').length).to eq(1)
197
- # expect(subject.get('rest')).to_not include('fallback')
198
- # end
199
- # end
200
- # describe 'Set to Rest Filter Post with params' do
201
- # let(:config) do <<-CONFIG
202
- # filter {
203
- # rest {
204
- # request => {
205
- # url => 'https://jsonplaceholder.typicode.com/posts'
206
- # method => 'post'
207
- # params => {
208
- # title => 'foo'
209
- # body => 'bar'
210
- # userId => 42
211
- # }
212
- # headers => {
213
- # 'Content-Type' => 'application/json'
214
- # }
215
- # }
216
- # json => true
217
- # target => 'rest'
218
- # }
219
- # }
220
- # CONFIG
221
- # end
222
- #
223
- # sample('message' => 'some text') do
224
- # expect(subject).to include('rest')
225
- # expect(subject.get('rest')).to include('id')
226
- # expect(subject.get('[rest][userId]')).to eq(42)
227
- # expect(subject.get('rest')).to_not include('fallback')
228
- # end
229
- # end
230
- # describe 'Set to Rest Filter Post with params sprintf' do
231
- # let(:config) do <<-CONFIG
232
- # filter {
233
- # rest {
234
- # request => {
235
- # url => 'https://jsonplaceholder.typicode.com/posts'
236
- # method => 'post'
237
- # params => {
238
- # title => '%{message}'
239
- # body => 'bar'
240
- # userId => "%{message}"
241
- # }
242
- # headers => {
243
- # 'Content-Type' => 'application/json'
244
- # }
245
- # }
246
- # json => true
247
- # target => 'rest'
248
- # }
249
- # }
250
- # CONFIG
251
- # end
252
- #
253
- # sample('message' => '42') do
254
- # expect(subject).to include('rest')
255
- # expect(subject.get('rest')).to include('id')
256
- # expect(subject.get('[rest][title]')).to eq(42)
257
- # expect(subject.get('[rest][userId]')).to eq(42)
258
- # expect(subject.get('rest')).to_not include('fallback')
259
- # end
260
- # sample('message' => ':5e?#!-_') do
261
- # expect(subject).to include('rest')
262
- # expect(subject.get('rest')).to include('id')
263
- # expect(subject.get('[rest][title]')).to eq(':5e?#!-_')
264
- # expect(subject.get('[rest][userId]')).to eq(':5e?#!-_')
265
- # expect(subject.get('rest')).to_not include('fallback')
266
- # end
267
- # sample('message' => ':4c43=>') do
268
- # expect(subject).to include('rest')
269
- # expect(subject.get('rest')).to include('id')
270
- # expect(subject.get('[rest][title]')).to eq(':4c43=>')
271
- # expect(subject.get('[rest][userId]')).to eq(':4c43=>')
272
- # expect(subject.get('rest')).to_not include('fallback')
273
- # end
274
- # end
275
- # describe 'Set to Rest Filter Post with body sprintf' do
276
- # let(:config) do <<-CONFIG
277
- # filter {
278
- # rest {
279
- # request => {
280
- # url => 'https://jsonplaceholder.typicode.com/posts'
281
- # method => 'post'
282
- # body => {
283
- # title => 'foo'
284
- # body => 'bar'
285
- # userId => "%{message}"
286
- # }
287
- # headers => {
288
- # 'Content-Type' => 'application/json'
289
- # }
290
- # }
291
- # json => true
292
- # target => 'rest'
293
- # }
294
- # }
295
- # CONFIG
296
- # end
297
- #
298
- # sample('message' => '42') do
299
- # expect(subject).to include('rest')
300
- # expect(subject.get('rest')).to include('id')
301
- # expect(subject.get('[rest][userId]')).to eq(42)
302
- # expect(subject.get('rest')).to_not include('fallback')
303
- # end
304
- # end
305
- # describe 'Set to Rest Filter Post with body sprintf nested params' do
306
- # let(:config) do <<-CONFIG
307
- # filter {
308
- # rest {
309
- # request => {
310
- # url => 'https://jsonplaceholder.typicode.com/posts'
311
- # method => 'post'
312
- # body => {
313
- # key1 => [
314
- # {
315
- # "filterType" => "text"
316
- # "text" => "salmon"
317
- # "boolean" => false
318
- # },
319
- # {
320
- # "filterType" => "unique"
321
- # }
322
- # ]
323
- # key2 => [
324
- # {
325
- # "message" => "123%{message}"
326
- # "boolean" => true
327
- # }
328
- # ]
329
- # key3 => [
330
- # {
331
- # "text" => "%{message}123"
332
- # "filterType" => "text"
333
- # "number" => 44
334
- # },
335
- # {
336
- # "filterType" => "unique"
337
- # "null" => nil
338
- # }
339
- # ]
340
- # userId => "%{message}"
341
- # }
342
- # headers => {
343
- # 'Content-Type' => 'application/json'
344
- # }
345
- # }
346
- # target => 'rest'
347
- # }
348
- # }
349
- # CONFIG
350
- # end
351
- #
352
- # sample('message' => '42') do
353
- # expect(subject).to include('rest')
354
- # expect(subject.get('rest')).to include('key1')
355
- # expect(subject.get('[rest][key1][0][boolean]')).to eq('false')
356
- # expect(subject.get('[rest][key1][1][filterType]')).to eq('unique')
357
- # expect(subject.get('[rest][key2][0][message]')).to eq('12342')
358
- # expect(subject.get('[rest][key2][0][boolean]')).to eq('true')
359
- # expect(subject.get('[rest][key3][0][text]')).to eq('42123')
360
- # expect(subject.get('[rest][key3][0][filterType]')).to eq('text')
361
- # expect(subject.get('[rest][key3][0][number]')).to eq(44)
362
- # expect(subject.get('[rest][key3][1][filterType]')).to eq('unique')
363
- # expect(subject.get('[rest][key3][1][null]')).to eq('nil')
364
- # expect(subject.get('[rest][userId]')).to eq(42)
365
- # expect(subject.get('rest')).to_not include('fallback')
366
- # end
367
- # end
368
- # describe 'fallback' do
369
- # let(:config) do <<-CONFIG
370
- # filter {
371
- # rest {
372
- # request => {
373
- # url => 'http://jsonplaceholder.typicode.com/users/0'
374
- # }
375
- # json => true
376
- # fallback => {
377
- # 'fallback1' => true
378
- # 'fallback2' => true
379
- # }
380
- # target => 'rest'
381
- # }
382
- # }
383
- # CONFIG
384
- # end
385
- #
386
- # sample('message' => 'some text') do
387
- # expect(subject).to include('rest')
388
- # expect(subject.get('rest')).to include('fallback1')
389
- # expect(subject.get('rest')).to include('fallback2')
390
- # expect(subject.get('rest')).to_not include('id')
391
- # end
392
- # end
393
- # describe 'empty target exception' do
394
- # let(:config) do <<-CONFIG
395
- # filter {
396
- # rest {
397
- # request => {
398
- # url => 'http://jsonplaceholder.typicode.com/users/0'
399
- # }
400
- # json => true
401
- # fallback => {
402
- # 'fallback1' => true
403
- # 'fallback2' => true
404
- # }
405
- # target => ''
406
- # }
407
- # }
408
- # CONFIG
409
- # end
410
- # sample('message' => 'some text') do
411
- # expect { subject }.to raise_error(LogStash::ConfigurationError)
412
- # end
413
- # end
414
- # describe 'http client throws exception' do
415
- # let(:config) do <<-CONFIG
416
- # filter {
417
- # rest {
418
- # request => {
419
- # url => 'invalid_url'
420
- # }
421
- # target => 'rest'
422
- # }
423
- # }
424
- # CONFIG
425
- # end
426
- # sample('message' => 'some text') do
427
- # expect(subject).to_not include('rest')
428
- # expect(subject.get('tags')).to include('_restfailure')
429
- # end
430
- # end
26
+ describe 'Set to Rest Filter Get without params custom target' do
27
+ let(:config) do <<-CONFIG
28
+ filter {
29
+ rest {
30
+ request => {
31
+ url => 'http://jsonplaceholder.typicode.com/users/10'
32
+ }
33
+ json => true
34
+ target => 'testing'
35
+ }
36
+ }
37
+ CONFIG
38
+ end
39
+
40
+ sample('message' => 'some text') do
41
+ expect(subject).to include('testing')
42
+ expect(subject.get('testing')).to include('id')
43
+ expect(subject.get('[testing][id]')).to eq(10)
44
+ expect(subject.get('testing')).to_not include('fallback')
45
+ end
46
+ end
47
+ describe 'Set to Rest Filter Get without params and sprintf' do
48
+ let(:config) do <<-CONFIG
49
+ filter {
50
+ rest {
51
+ request => {
52
+ url => "http://jsonplaceholder.typicode.com/users/%{message}"
53
+ }
54
+ json => true
55
+ sprintf => true
56
+ target => 'rest'
57
+ }
58
+ }
59
+ CONFIG
60
+ end
61
+
62
+ sample('message' => '10') do
63
+ expect(subject).to include('rest')
64
+ expect(subject.get('rest')).to include('id')
65
+ expect(subject.get('[rest][id]')).to eq(10)
66
+ expect(subject.get('rest')).to_not include('fallback')
67
+ end
68
+ sample('message' => '9') do
69
+ expect(subject).to include('rest')
70
+ expect(subject.get('rest')).to include('id')
71
+ expect(subject.get('[rest][id]')).to eq(9)
72
+ expect(subject.get('rest')).to_not include('fallback')
73
+ end
74
+ end
75
+ describe 'Set to Rest Filter Get without params http error' do
76
+ let(:config) do <<-CONFIG
77
+ filter {
78
+ rest {
79
+ request => {
80
+ url => 'http://httpstat.us/404'
81
+ }
82
+ json => true
83
+ target => 'rest'
84
+ }
85
+ }
86
+ CONFIG
87
+ end
88
+
89
+ sample('message' => 'some text') do
90
+ expect(subject).to_not include('rest')
91
+ expect(subject.get('tags')).to include('_restfailure')
92
+ end
93
+ end
94
+ describe 'Set to Rest Filter Get with params' do
95
+ let(:config) do <<-CONFIG
96
+ filter {
97
+ rest {
98
+ request => {
99
+ url => 'https://jsonplaceholder.typicode.com/posts'
100
+ params => {
101
+ userId => 10
102
+ }
103
+ headers => {
104
+ 'Content-Type' => 'application/json'
105
+ }
106
+ }
107
+ json => true
108
+ target => 'rest'
109
+ }
110
+ }
111
+ CONFIG
112
+ end
113
+
114
+ sample('message' => 'some text') do
115
+ expect(subject).to include('rest')
116
+ expect(subject.get('[rest][0]')).to include('userId')
117
+ expect(subject.get('[rest][0][userId]')).to eq(10)
118
+ expect(subject.get('rest')).to_not include('fallback')
119
+ end
120
+ end
121
+ describe 'empty response' do
122
+ let(:config) do <<-CONFIG
123
+ filter {
124
+ rest {
125
+ request => {
126
+ url => 'https://jsonplaceholder.typicode.com/posts'
127
+ params => {
128
+ userId => 0
129
+ }
130
+ headers => {
131
+ 'Content-Type' => 'application/json'
132
+ }
133
+ }
134
+ target => 'rest'
135
+ }
136
+ }
137
+ CONFIG
138
+ end
139
+
140
+ sample('message' => 'some text') do
141
+ expect(subject).to_not include('rest')
142
+ expect(subject.get('tags')).to include('_restfailure')
143
+ end
144
+ end
145
+ describe 'Set to Rest Filter Get with params sprintf' do
146
+ let(:config) do <<-CONFIG
147
+ filter {
148
+ rest {
149
+ request => {
150
+ url => 'https://jsonplaceholder.typicode.com/posts'
151
+ params => {
152
+ userId => "%{message}"
153
+ id => "%{message}"
154
+ }
155
+ headers => {
156
+ 'Content-Type' => 'application/json'
157
+ }
158
+ }
159
+ json => true
160
+ target => 'rest'
161
+ }
162
+ }
163
+ CONFIG
164
+ end
165
+
166
+ sample('message' => '1') do
167
+ expect(subject).to include('rest')
168
+ expect(subject.get('[rest][0]')).to include('userId')
169
+ expect(subject.get('[rest][0][userId]')).to eq(1)
170
+ expect(subject.get('[rest][0][id]')).to eq(1)
171
+ expect(subject.get('rest').length).to eq(1)
172
+ expect(subject.get('rest')).to_not include('fallback')
173
+ end
174
+ end
175
+ describe 'Set to Rest Filter Post with params' do
176
+ let(:config) do <<-CONFIG
177
+ filter {
178
+ rest {
179
+ request => {
180
+ url => 'https://jsonplaceholder.typicode.com/posts'
181
+ method => 'post'
182
+ params => {
183
+ title => 'foo'
184
+ body => 'bar'
185
+ userId => 42
186
+ }
187
+ headers => {
188
+ 'Content-Type' => 'application/json'
189
+ }
190
+ }
191
+ json => true
192
+ target => 'rest'
193
+ }
194
+ }
195
+ CONFIG
196
+ end
197
+
198
+ sample('message' => 'some text') do
199
+ expect(subject).to include('rest')
200
+ expect(subject.get('rest')).to include('id')
201
+ expect(subject.get('[rest][userId]')).to eq(42)
202
+ expect(subject.get('rest')).to_not include('fallback')
203
+ end
204
+ end
205
+ describe 'Set to Rest Filter Post with params sprintf' do
206
+ let(:config) do <<-CONFIG
207
+ filter {
208
+ rest {
209
+ request => {
210
+ url => 'https://jsonplaceholder.typicode.com/posts'
211
+ method => 'post'
212
+ params => {
213
+ title => '%{message}'
214
+ body => 'bar'
215
+ userId => "%{message}"
216
+ }
217
+ headers => {
218
+ 'Content-Type' => 'application/json'
219
+ }
220
+ }
221
+ json => true
222
+ target => 'rest'
223
+ }
224
+ }
225
+ CONFIG
226
+ end
227
+
228
+ sample('message' => '42') do
229
+ expect(subject).to include('rest')
230
+ expect(subject.get('rest')).to include('id')
231
+ expect(subject.get('[rest][title]')).to eq(42)
232
+ expect(subject.get('[rest][userId]')).to eq(42)
233
+ expect(subject.get('rest')).to_not include('fallback')
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
249
+ end
250
+ describe 'Set to Rest Filter Post with body sprintf' do
251
+ let(:config) do <<-CONFIG
252
+ filter {
253
+ rest {
254
+ request => {
255
+ url => 'https://jsonplaceholder.typicode.com/posts'
256
+ method => 'post'
257
+ body => {
258
+ title => 'foo'
259
+ body => 'bar'
260
+ userId => "%{message}"
261
+ }
262
+ headers => {
263
+ 'Content-Type' => 'application/json'
264
+ }
265
+ }
266
+ json => true
267
+ target => 'rest'
268
+ }
269
+ }
270
+ CONFIG
271
+ end
272
+
273
+ sample('message' => '42') do
274
+ expect(subject).to include('rest')
275
+ expect(subject.get('rest')).to include('id')
276
+ expect(subject.get('[rest][userId]')).to eq(42)
277
+ expect(subject.get('rest')).to_not include('fallback')
278
+ end
279
+ end
280
+ describe 'Set to Rest Filter Post with body sprintf nested params' do
281
+ let(:config) do <<-CONFIG
282
+ filter {
283
+ rest {
284
+ request => {
285
+ url => 'https://jsonplaceholder.typicode.com/posts'
286
+ method => 'post'
287
+ body => {
288
+ key1 => [
289
+ {
290
+ "filterType" => "text"
291
+ "text" => "salmon"
292
+ "boolean" => false
293
+ },
294
+ {
295
+ "filterType" => "unique"
296
+ }
297
+ ]
298
+ key2 => [
299
+ {
300
+ "message" => "123%{message}"
301
+ "boolean" => true
302
+ }
303
+ ]
304
+ key3 => [
305
+ {
306
+ "text" => "%{message}123"
307
+ "filterType" => "text"
308
+ "number" => 44
309
+ },
310
+ {
311
+ "filterType" => "unique"
312
+ "null" => nil
313
+ }
314
+ ]
315
+ userId => "%{message}"
316
+ }
317
+ headers => {
318
+ 'Content-Type' => 'application/json'
319
+ }
320
+ }
321
+ target => 'rest'
322
+ }
323
+ }
324
+ CONFIG
325
+ end
326
+
327
+ sample('message' => '42') do
328
+ expect(subject).to include('rest')
329
+ expect(subject.get('rest')).to include('key1')
330
+ expect(subject.get('[rest][key1][0][boolean]')).to eq('false')
331
+ expect(subject.get('[rest][key1][1][filterType]')).to eq('unique')
332
+ expect(subject.get('[rest][key2][0][message]')).to eq('12342')
333
+ expect(subject.get('[rest][key2][0][boolean]')).to eq('true')
334
+ expect(subject.get('[rest][key3][0][text]')).to eq('42123')
335
+ expect(subject.get('[rest][key3][0][filterType]')).to eq('text')
336
+ expect(subject.get('[rest][key3][0][number]')).to eq(44)
337
+ expect(subject.get('[rest][key3][1][filterType]')).to eq('unique')
338
+ expect(subject.get('[rest][key3][1][null]')).to eq('nil')
339
+ expect(subject.get('[rest][userId]')).to eq(42)
340
+ expect(subject.get('rest')).to_not include('fallback')
341
+ end
342
+ end
343
+ describe 'fallback' do
344
+ let(:config) do <<-CONFIG
345
+ filter {
346
+ rest {
347
+ request => {
348
+ url => 'http://jsonplaceholder.typicode.com/users/0'
349
+ }
350
+ json => true
351
+ fallback => {
352
+ 'fallback1' => true
353
+ 'fallback2' => true
354
+ }
355
+ target => 'rest'
356
+ }
357
+ }
358
+ CONFIG
359
+ end
360
+
361
+ sample('message' => 'some text') do
362
+ expect(subject).to include('rest')
363
+ expect(subject.get('rest')).to include('fallback1')
364
+ expect(subject.get('rest')).to include('fallback2')
365
+ expect(subject.get('rest')).to_not include('id')
366
+ end
367
+ end
368
+ describe 'empty target exception' do
369
+ let(:config) do <<-CONFIG
370
+ filter {
371
+ rest {
372
+ request => {
373
+ url => 'http://jsonplaceholder.typicode.com/users/0'
374
+ }
375
+ json => true
376
+ fallback => {
377
+ 'fallback1' => true
378
+ 'fallback2' => true
379
+ }
380
+ target => ''
381
+ }
382
+ }
383
+ CONFIG
384
+ end
385
+ sample('message' => 'some text') do
386
+ expect { subject }.to raise_error(LogStash::ConfigurationError)
387
+ end
388
+ end
389
+ describe 'http client throws exception' do
390
+ let(:config) do <<-CONFIG
391
+ filter {
392
+ rest {
393
+ request => {
394
+ url => 'invalid_url'
395
+ }
396
+ target => 'rest'
397
+ }
398
+ }
399
+ CONFIG
400
+ end
401
+ sample('message' => 'some text') do
402
+ expect(subject).to_not include('rest')
403
+ expect(subject.get('tags')).to include('_restfailure')
404
+ end
405
+ end
431
406
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-rest2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Henning
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-09-27 00:00:00.000000000 Z
13
+ date: 2020-03-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement
@@ -22,8 +22,8 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: '2.99'
24
24
  name: logstash-core-plugin-api
25
- prerelease: false
26
25
  type: :runtime
26
+ prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
29
  - - ">="
@@ -37,21 +37,21 @@ dependencies:
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.2.4
40
+ version: 5.0.0
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: 6.0.0
43
+ version: 9.0.0
44
44
  name: logstash-mixin-http_client
45
- prerelease: false
46
45
  type: :runtime
46
+ prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: 2.2.4
51
+ version: 5.0.0
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: 6.0.0
54
+ version: 9.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
@@ -62,8 +62,8 @@ dependencies:
62
62
  - !ruby/object:Gem::Version
63
63
  version: 2.0.0
64
64
  name: logstash-devutils
65
- prerelease: false
66
65
  type: :development
66
+ prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - ">="
@@ -109,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubyforge_project:
113
- rubygems_version: 2.6.11
112
+ rubygems_version: 3.0.6
114
113
  signing_key:
115
114
  specification_version: 4
116
115
  summary: This filter requests data from a RESTful Web Service.