logstash-output-http 4.0.0 → 4.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb4ed46a005d9af73da085335c1f1f516cd54f1b
4
- data.tar.gz: ea8ded7326eef70f098bbcab8e910d9e3cfe7b2a
3
+ metadata.gz: 96be92dd03ba701e5c21af44559f567fe9e9d00e
4
+ data.tar.gz: eee63a9d3a744b0e298116cf5842b6efa60ab5a4
5
5
  SHA512:
6
- metadata.gz: 7c7e3a3e18f434a3d575f280cd5f8f6502833338a270519facf6d6f9115f78e033df68bcbfb6d050fcda56230a914cab22f61a1c06854203af51ce8d54e3dc03
7
- data.tar.gz: 7e8b34fc4f8872a4754bc2868d48dbd57e7db5bee7006bfc2f6d6be116457e36a6d50edcb7a8fd8a3fb8747b7e2c0b022a387c8642f599e44bcc621dbf878a16
6
+ metadata.gz: 259ba5e8cd221de83656a1c04a3c032cfd93de96930cc1a7e9ff80a014356bb180e28e47a5c8dfeae3decc5bc59c2e29f391e49561834903f98405f14e21cfeb
7
+ data.tar.gz: 3a33c97b68551e0a335bdac609de359124027314cc6350d5ebbef6537d508f9a8f91ebea06b261316d7c9110d89acba2d659b89e22e3ec52546ef8657fd5450b
@@ -1,3 +1,6 @@
1
+ ## 4.1.0
2
+ - Allow nested field definitions in `mappings`
3
+
1
4
  ## 4.0.0
2
5
  - Major overhaul of internals, adds new retry options
3
6
  - Allow users to specify non-standard response codes as ignorable
@@ -66,7 +66,7 @@ class LogStash::Outputs::Http < LogStash::Outputs::Base
66
66
  #
67
67
  # For example:
68
68
  # [source,ruby]
69
- # mapping => {"foo" => "%{host}"
69
+ # mapping => {"foo" => "%{host}"
70
70
  # "bar" => "%{type}"}
71
71
  config :mapping, :validate => :hash
72
72
 
@@ -305,11 +305,27 @@ class LogStash::Outputs::Http < LogStash::Outputs::Base
305
305
  end
306
306
  end
307
307
 
308
+ def reduce_hash(hash, event)
309
+ hash.reduce({}) do |acc, kv|
310
+ k, v = kv
311
+ if v.is_a?(Hash)
312
+ acc[k] = reduce_hash(v, event)
313
+ else
314
+ acc[k] = event.sprintf(v)
315
+ end
316
+ acc
317
+ end
318
+ end
319
+
308
320
  def map_event(event)
309
321
  if @mapping
310
322
  @mapping.reduce({}) do |acc,kv|
311
323
  k,v = kv
312
- acc[k] = event.sprintf(v)
324
+ if v.is_a?(Hash)
325
+ acc[k] = reduce_hash(v, event)
326
+ else
327
+ acc[k] = event.sprintf(v)
328
+ end
313
329
  acc
314
330
  end
315
331
  else
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-http'
4
- s.version = '4.0.0'
4
+ s.version = '4.1.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "This output lets you `PUT` or `POST` events to a generic HTTP(S) endpoint"
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"
@@ -102,7 +102,9 @@ describe LogStash::Outputs::Http do
102
102
  # Requires pool_max to be 1
103
103
 
104
104
  let(:port) { PORT }
105
- let(:event) { LogStash::Event.new("message" => "hi") }
105
+ let(:event) {
106
+ LogStash::Event.new({"message" => "hi"})
107
+ }
106
108
  let(:url) { "http://localhost:#{port}/good" }
107
109
  let(:method) { "post" }
108
110
 
@@ -225,7 +227,9 @@ describe LogStash::Outputs::Http do
225
227
 
226
228
  describe "integration tests" do
227
229
  let(:url) { "http://localhost:#{port}/good" }
228
- let(:event) { LogStash::Event.new("foo" => "bar", "baz" => "bot")}
230
+ let(:event) {
231
+ LogStash::Event.new("foo" => "bar", "baz" => "bot", "user" => "McBest")
232
+ }
229
233
 
230
234
  subject { LogStash::Outputs::Http.new(config) }
231
235
 
@@ -265,12 +269,39 @@ describe LogStash::Outputs::Http do
265
269
 
266
270
  describe "sending a mapped event" do
267
271
  let(:config) {
268
- {"url" => url, "http_method" => "post", "pool_max" => 1, "mapping" => {"blah" => "X %{foo}"}}
272
+ {"url" => url, "http_method" => "post", "pool_max" => 1, "mapping" => {"blah" => "X %{foo}"} }
269
273
  }
270
274
  let(:expected_body) { LogStash::Json.dump("blah" => "X #{event.get("foo")}") }
271
275
  let(:expected_content_type) { "application/json" }
272
276
 
273
277
  include_examples("a received event")
274
278
  end
279
+
280
+ describe "sending a mapped, nested event" do
281
+ let(:config) {
282
+ {
283
+ "url" => url,
284
+ "http_method" => "post",
285
+ "pool_max" => 1,
286
+ "mapping" => {
287
+ "host" => "X %{foo}",
288
+ "event" => {
289
+ "user" => "Y %{user}"
290
+ }
291
+ }
292
+ }
293
+ }
294
+ let(:expected_body) {
295
+ LogStash::Json.dump({
296
+ "host" => "X #{event.get("foo")}",
297
+ "event" => {
298
+ "user" => "Y #{event.get("user")}"
299
+ }
300
+ })
301
+ }
302
+ let(:expected_content_type) { "application/json" }
303
+
304
+ include_examples("a received event")
305
+ end
275
306
  end
276
307
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic