Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/fluent/plugin/out_sumologic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class SumologicConnection

attr_reader :http

def initialize(endpoint, verify_ssl, connect_timeout, proxy_uri, disable_cookies)
def initialize(endpoint, verify_ssl, connect_timeout, proxy_uri, disable_cookies, sumo_client)
@endpoint = endpoint
@sumo_client = sumo_client
create_http_client(verify_ssl, connect_timeout, proxy_uri, disable_cookies)
end

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

config_section :buffer do
config_set_default :@type, DEFAULT_BUFFER_TYPE
Expand Down Expand Up @@ -136,7 +139,19 @@ def configure(conf)
conf['custom_fields'] = nil
end

@sumo_conn = SumologicConnection.new(conf['endpoint'], conf['verify_ssl'], conf['open_timeout'].to_i, conf['proxy_uri'], conf['disable_cookies'])
# For some reason default is set incorrectly in unit-tests
if conf['sumo_client'].nil? || conf['sumo_client'].strip.length == 0
conf['sumo_client'] = 'fluentd-output'
end

@sumo_conn = SumologicConnection.new(
conf['endpoint'],
conf['verify_ssl'],
conf['open_timeout'].to_i,
conf['proxy_uri'],
conf['disable_cookies'],
conf['sumo_client']
)
super
end

Expand Down
23 changes: 23 additions & 0 deletions test/plugin/test_out_sumologic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_default_configure
assert_equal instance.timestamp_key, 'timestamp'
assert_equal instance.proxy_uri, nil
assert_equal instance.disable_cookies, false
assert_equal instance.sumo_client, 'fluentd-output'
end

def test_emit_text
Expand All @@ -95,6 +96,28 @@ def test_emit_text
times:1
end

def test_emit_text_custom_sumo_client
config = %{
endpoint https://collectors.sumologic.com/v1/receivers/http/1234
log_format text
source_category test
source_host test
source_name test
sumo_client 'fluentd-custom-sender'

}
driver = create_driver(config)
time = event_time
stub_request(:post, 'https://collectors.sumologic.com/v1/receivers/http/1234')
driver.run do
driver.feed("output.test", time, {'foo' => 'bar', 'message' => 'test'})
end
assert_requested :post, "https://collectors.sumologic.com/v1/receivers/http/1234",
headers: {'X-Sumo-Category'=>'test', 'X-Sumo-Client'=>'fluentd-custom-sender', 'X-Sumo-Host'=>'test', 'X-Sumo-Name'=>'test'},
body: "test",
times:1
end

def test_emit_json
config = %{
endpoint https://collectors.sumologic.com/v1/receivers/http/1234
Expand Down