Skip to content

Commit e803590

Browse files
author
Dominik Rosiek
committed
Allow to override sumo client header value
1 parent e29465d commit e803590

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

lib/fluent/plugin/out_sumologic.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ class SumologicConnection
77

88
attr_reader :http
99

10-
def initialize(endpoint, verify_ssl, connect_timeout, proxy_uri, disable_cookies)
10+
def initialize(endpoint, verify_ssl, connect_timeout, proxy_uri, disable_cookies, sumo_client)
1111
@endpoint = endpoint
12+
@sumo_client = sumo_client
1213
create_http_client(verify_ssl, connect_timeout, proxy_uri, disable_cookies)
1314
end
1415

@@ -24,7 +25,7 @@ def request_headers(source_host, source_category, source_name, data_type, metric
2425
'X-Sumo-Name' => source_name,
2526
'X-Sumo-Category' => source_category,
2627
'X-Sumo-Host' => source_host,
27-
'X-Sumo-Client' => 'fluentd-output'
28+
'X-Sumo-Client' => @sumo_client,
2829
}
2930
if data_type == 'metrics'
3031
case metric_data_format
@@ -89,6 +90,8 @@ class Fluent::Plugin::Sumologic < Fluent::Plugin::Output
8990
# https://help.sumologic.com/Manage/Fields
9091
desc 'Fields string (eg "cluster=payment, service=credit_card") which is going to be added to every record.'
9192
config_param :custom_fields, :string, :default => nil
93+
desc 'Name of sumo client which is send as X-Sumo-Client header'
94+
config_param :sumo_client, :string, :default => 'fluentd-output'
9295

9396
config_section :buffer do
9497
config_set_default :@type, DEFAULT_BUFFER_TYPE
@@ -136,7 +139,19 @@ def configure(conf)
136139
conf['custom_fields'] = nil
137140
end
138141

139-
@sumo_conn = SumologicConnection.new(conf['endpoint'], conf['verify_ssl'], conf['open_timeout'].to_i, conf['proxy_uri'], conf['disable_cookies'])
142+
# For some reason default is set incorrectly in unit-tests
143+
if conf['sumo_client'].nil? || conf['sumo_client'].strip.length == 0
144+
conf['sumo_client'] = 'fluentd-output'
145+
end
146+
147+
@sumo_conn = SumologicConnection.new(
148+
conf['endpoint'],
149+
conf['verify_ssl'],
150+
conf['open_timeout'].to_i,
151+
conf['proxy_uri'],
152+
conf['disable_cookies'],
153+
conf['sumo_client']
154+
)
140155
super
141156
end
142157

test/plugin/test_out_sumologic.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def test_default_configure
7272
assert_equal instance.timestamp_key, 'timestamp'
7373
assert_equal instance.proxy_uri, nil
7474
assert_equal instance.disable_cookies, false
75+
assert_equal instance.sumo_client, 'fluentd-output'
7576
end
7677

7778
def test_emit_text
@@ -95,6 +96,28 @@ def test_emit_text
9596
times:1
9697
end
9798

99+
def test_emit_text_custom_sumo_client
100+
config = %{
101+
endpoint https://collectors.sumologic.com/v1/receivers/http/1234
102+
log_format text
103+
source_category test
104+
source_host test
105+
source_name test
106+
sumo_client 'fluentd-custom-sender'
107+
108+
}
109+
driver = create_driver(config)
110+
time = event_time
111+
stub_request(:post, 'https://collectors.sumologic.com/v1/receivers/http/1234')
112+
driver.run do
113+
driver.feed("output.test", time, {'foo' => 'bar', 'message' => 'test'})
114+
end
115+
assert_requested :post, "https://collectors.sumologic.com/v1/receivers/http/1234",
116+
headers: {'X-Sumo-Category'=>'test', 'X-Sumo-Client'=>'fluentd-custom-sender', 'X-Sumo-Host'=>'test', 'X-Sumo-Name'=>'test'},
117+
body: "test",
118+
times:1
119+
end
120+
98121
def test_emit_json
99122
config = %{
100123
endpoint https://collectors.sumologic.com/v1/receivers/http/1234

0 commit comments

Comments
 (0)