From c1f296bf779662474e397499b466072ac45a3d91 Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Fri, 25 Oct 2019 12:36:59 -0700 Subject: [PATCH] Fix sumo_key hash tuple to support colons --- lib/fluent/plugin/out_sumologic.rb | 6 ++++-- test/plugin/test_out_sumologic.rb | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/fluent/plugin/out_sumologic.rb b/lib/fluent/plugin/out_sumologic.rb index ba98de3..4265536 100644 --- a/lib/fluent/plugin/out_sumologic.rb +++ b/lib/fluent/plugin/out_sumologic.rb @@ -198,7 +198,8 @@ def sumo_key(sumo_metadata, chunk) fields = sumo_metadata['fields'] || "" fields = extract_placeholders(fields, chunk) unless fields.nil? - "#{source_name}:#{source_category}:#{source_host}:#{fields}" + { :source_name => "#{source_name}", :source_category => "#{source_category}", + :source_host => "#{source_host}", :fields => "#{fields}" } end # Convert timestamp to 13 digit epoch if necessary @@ -265,7 +266,8 @@ def write(chunk) # Push logs to sumo messages_list.each do |key, messages| - source_name, source_category, source_host, fields = key.split(':') + source_name, source_category, source_host, fields = key[:source_name], key[:source_category], + key[:source_host], key[:fields] @sumo_conn.publish( messages.join("\n"), source_host =source_host, diff --git a/test/plugin/test_out_sumologic.rb b/test/plugin/test_out_sumologic.rb index d0d057a..a0f97b8 100644 --- a/test/plugin/test_out_sumologic.rb +++ b/test/plugin/test_out_sumologic.rb @@ -455,7 +455,7 @@ def test_batching_different_fields driver.feed("output.test", time, {'message' => 'test1'}) driver.feed("output.test", time, {'message' => 'test2', '_sumo_metadata' => {"fields": "foo=bar"}}) driver.feed("output.test", time, {'message' => 'test3', '_sumo_metadata' => {"fields": "foo=bar,sumo=logic"}}) - driver.feed("output.test", time, {'message' => 'test4', '_sumo_metadata' => {"fields": "foo=bar,abc=123"}}) + driver.feed("output.test", time, {'message' => 'test4', '_sumo_metadata' => {"fields": "foo=bar,master_url=https://100.64.0.1:443"}}) end assert_requested :post, "https://collectors.sumologic.com/v1/receivers/http/1234", headers: {'X-Sumo-Category'=>'test', 'X-Sumo-Client'=>'fluentd-output', 'X-Sumo-Host'=>'test', 'X-Sumo-Name'=>'test'}, @@ -470,7 +470,7 @@ def test_batching_different_fields body: /\A{"timestamp":\d+.,"message":"test3"}\z/, times:1 assert_requested :post, "https://collectors.sumologic.com/v1/receivers/http/1234", - headers: {'X-Sumo-Category'=>'test', 'X-Sumo-Client'=>'fluentd-output', 'X-Sumo-Host'=>'test', 'X-Sumo-Name'=>'test', 'X-Sumo-Fields' => 'foo=bar,abc=123'}, + headers: {'X-Sumo-Category'=>'test', 'X-Sumo-Client'=>'fluentd-output', 'X-Sumo-Host'=>'test', 'X-Sumo-Name'=>'test', 'X-Sumo-Fields' => 'foo=bar,master_url=https://100.64.0.1:443'}, body: /\A{"timestamp":\d+.,"message":"test4"}\z/, times:1 end