Skip to content

Commit b1ea91a

Browse files
authored
Add full_url parameter (#198)
* Updated construct_api * added full_url config
1 parent 8ce4621 commit b1ea91a

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/fluent/plugin/out_splunk_hec.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ class SplunkHecOutput < SplunkOutput
3131
config_param :protocol, :enum, list: %i[http https], default: :https
3232

3333
desc 'The hostname/IP to HEC, or HEC load balancer.'
34-
config_param :hec_host, :string
34+
config_param :hec_host, :string, default: ''
3535

3636
desc 'The port number to HEC, or HEC load balancer.'
3737
config_param :hec_port, :integer, default: 8088
3838

39+
desc 'Full url to connect tosplunk. Example: https://mydomain.com:8088/apps/splunk'
40+
config_param :full_url, :string, default: ''
41+
3942
desc 'The HEC token.'
4043
config_param :hec_token, :string
4144

@@ -132,7 +135,7 @@ def initialize
132135

133136
def configure(conf)
134137
super
135-
138+
raise Fluent::ConfigError, 'One of `hec_host` or `full_url` is required.' if @hec_host.empty? && @full_url.empty?
136139
check_metric_configs
137140
pick_custom_format_method
138141
end
@@ -279,9 +282,17 @@ def format_metric(tag, time, record)
279282
end
280283

281284
def construct_api
282-
URI("#{@protocol}://#{@hec_host}:#{@hec_port}/services/collector")
285+
if @full_url.empty?
286+
URI("#{@protocol}://#{@hec_host}:#{@hec_port}/services/collector")
287+
else
288+
URI("#{@full_url.delete_suffix("/")}/services/collector")
289+
end
283290
rescue StandardError
284-
raise Fluent::ConfigError, "hec_host (#{@hec_host}) and/or hec_port (#{@hec_port}) are invalid."
291+
if @full_url.empty?
292+
raise Fluent::ConfigError, "hec_host (#{@hec_host}) and/or hec_port (#{@hec_port}) are invalid."
293+
else
294+
raise Fluent::ConfigError, "full_url (#{@full_url}) is invalid."
295+
end
285296
end
286297

287298
def new_connection

test/fluent/plugin/out_splunk_hec_test.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
describe 'hec_host validation' do
6666
describe 'invalid host' do
67-
it 'should require hec_host' do
67+
it 'should require hec_host or full_url' do
6868
expect { create_hec_output_driver }.must_raise Fluent::ConfigError
6969
end
7070

@@ -78,6 +78,17 @@
7878
end
7979
end
8080

81+
describe 'full_url validation' do
82+
describe 'invalid full_url' do
83+
it { expect { create_hec_output_driver(full_url: '%bad-host%.com') }.must_raise Fluent::ConfigError }
84+
end
85+
describe 'good full_url' do
86+
it {
87+
expect(create_hec_output_driver('full_url https://splunk.com').instance.full_url).must_equal 'https://splunk.com'
88+
}
89+
end
90+
end
91+
8192
it 'should send request to Splunk' do
8293
req = verify_sent_events do |batch|
8394
expect(batch.size).must_equal 2

0 commit comments

Comments
 (0)