diff --git a/spec/classes/splunk_ouputs_indexandforward_spec.rb b/spec/classes/splunk_ouputs_indexandforward_spec.rb index 82214cb..7238bd2 100644 --- a/spec/classes/splunk_ouputs_indexandforward_spec.rb +++ b/spec/classes/splunk_ouputs_indexandforward_spec.rb @@ -30,5 +30,39 @@ it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/server = server1.example.com:50514/) } it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/indexAndForward = True/) } end + describe "with multiple servers in target group" do + let(:params) { { + :configure_outputs => true, + :indexandforward => true, + :port => '50514', + :path => '/opt/splunk/etc/system/local', + :output_hash => { }, + :target_group => { "example1" => ["server1.example.com","server2.example.com"] } + } } + + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/[tcpout]/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/defaultGroup = example1/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/disabled = false/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/tcpout:example1/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/server = server1.example.com:50514,server2.example.com:50514/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/indexAndForward = True/) } + end + describe "with an Array of server in target group" do + let(:params) { { + :configure_outputs => true, + :indexandforward => true, + :port => '50514', + :path => '/opt/splunk/etc/system/local', + :output_hash => { }, + :target_group => { "example1" => ["server1.example.com"] } + } } + + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/[tcpout]/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/defaultGroup = example1/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/disabled = false/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/tcpout:example1/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/server = server1.example.com:50514/) } + it { should contain_file('/opt/splunk/etc/system/local/outputs.conf').with_content(/indexAndForward = True/) } + end end end diff --git a/templates/opt/splunk/etc/system/local/outputs.conf.erb b/templates/opt/splunk/etc/system/local/outputs.conf.erb index 0e19cfc..e08f3f9 100644 --- a/templates/opt/splunk/etc/system/local/outputs.conf.erb +++ b/templates/opt/splunk/etc/system/local/outputs.conf.erb @@ -6,8 +6,11 @@ disabled = <%= @tcpout_disabled %> <% @groupkeys.sort.each do |group| -%> [tcpout:<%= group -%>] +<% if @target_group[group].is_a?(Array) -%> +server = <%= @target_group[group].map { |server| "#{server}:#{@port}"}.join(',') %> +<% else -%> server = <%= @target_group[group] -%>:<%= @port %> - +<% end -%> <% end -%> <% end -%> <% if @indexandforward == true || @indexandforward == 'true' || @indexandforward == 'True' -%>