Skip to content

Commit 15c0560

Browse files
committed
config: add "timestamp_key" for customizing "timestamp"
1 parent 6736a5c commit 15c0560

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/fluent/plugin/out_sumologic.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Fluent::Plugin::Sumologic < Fluent::Plugin::Output
8080
config_param :delimiter, :string, :default => "."
8181
config_param :open_timeout, :integer, :default => 60
8282
config_param :add_timestamp, :bool, :default => true
83+
config_param :timestamp_key, :string, :default => 'timestamp'
8384
config_param :proxy_uri, :string, :default => nil
8485
config_param :disable_cookies, :bool, :default => false
8586

@@ -255,12 +256,12 @@ def write(chunk)
255256
end
256257
when 'json_merge'
257258
if @add_timestamp
258-
record = { :timestamp => sumo_timestamp(time) }.merge(record)
259+
record = { @timestamp_key => sumo_timestamp(time) }.merge(record)
259260
end
260261
log = dump_log(merge_json(record))
261262
else
262263
if @add_timestamp
263-
record = { :timestamp => sumo_timestamp(time) }.merge(record)
264+
record = { @timestamp_key => sumo_timestamp(time) }.merge(record)
264265
end
265266
log = dump_log(record)
266267
end

test/plugin/test_out_sumologic.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def test_default_configure
6969
assert_equal instance.delimiter, '.'
7070
assert_equal instance.open_timeout, 60
7171
assert_equal instance.add_timestamp, true
72+
assert_equal instance.timestamp_key, 'timestamp'
7273
assert_equal instance.proxy_uri, nil
7374
assert_equal instance.disable_cookies, false
7475
end
@@ -221,6 +222,27 @@ def test_emit_json_no_timestamp
221222
times:1
222223
end
223224

225+
def test_emit_json_timestamp_key
226+
config = %{
227+
endpoint https://collectors.sumologic.com/v1/receivers/http/1234
228+
log_format json
229+
source_category test
230+
source_host test
231+
source_name test
232+
timestamp_key ts
233+
}
234+
driver = create_driver(config)
235+
time = event_time
236+
stub_request(:post, 'https://collectors.sumologic.com/v1/receivers/http/1234')
237+
driver.run do
238+
driver.feed("output.test", time, {'message' => 'test'})
239+
end
240+
assert_requested :post, "https://collectors.sumologic.com/v1/receivers/http/1234",
241+
headers: {'X-Sumo-Category'=>'test', 'X-Sumo-Client'=>'fluentd-output', 'X-Sumo-Host'=>'test', 'X-Sumo-Name'=>'test'},
242+
body: /\A{"ts":\d+.,"message":"test"}\z/,
243+
times:1
244+
end
245+
224246
def test_emit_graphite
225247
config = %{
226248
endpoint https://collectors.sumologic.com/v1/receivers/http/1234

0 commit comments

Comments
 (0)