Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - support section arguments #131

Closed
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
5 changes: 3 additions & 2 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ module Helpers
def self.params_to_text(parameters)
body = ''
parameters.each do |param_key, param_value|
param_key_closing_tag = param_key.to_s.split.first
if param_value.is_a?(Hash)
body += "<#{param_key}>\n"
body += params_to_text(param_value)
body += "</#{param_key}>\n"
body += "</#{param_key_closing_tag}>\n"
elsif param_value.is_a?(Array)
if param_value.all? { |array_value| array_value.is_a?(Hash) }
body += param_value.map { |array_value|
"<#{param_key}>\n#{params_to_text(array_value)}</#{param_key}>\n"
"<#{param_key}>\n#{params_to_text(array_value)}</#{param_key_closing_tag}>\n"
}.join
else
body += "#{param_key} [#{param_value.map { |array_value| array_value.to_s.dump }.join(", ")}]\n"
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license "Apache 2.0"
description "Installs/Configures td-agent"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "3.2.1"
version "3.3.0"
recipe "td-agent", "td-agent configuration"

chef_version ">= 12" if respond_to?(:chef_version)
Expand Down
2 changes: 2 additions & 0 deletions spec/unit/resources/td_agent_match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@

it 'creates unit test output' do
expect(chef_run).to create_td_agent_match('01_out_file')
expect(chef_run).to create_td_agent_match('02_buffer_with_arguments')
end

it 'creates the output config file' do
expect(chef_run).to create_template('/etc/td-agent/conf.d/01_out_file.conf')
expect(chef_run).to create_template('/etc/td-agent/conf.d/02_buffer_with_arguments.conf')
end
end
18 changes: 18 additions & 0 deletions test/fixtures/smoke/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@
end
end

td_agent_match 'test_section_attributes' do
type 'null'
tag 'null.*'
if TdAgent::Helpers.apply_params_kludge?
params(
'buffer tag, argument1, argument2' => {
timekey: '1d'
}
)
else
parameters(
'buffer tag, argument1, argument2' => {
timekey: '1d'
}
)
end
end

td_agent_filter 'test_filter' do
type 'record_transformer'
tag 'webserver.*'
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/td-agent-spec/recipes/match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@
}
)
end

td_agent_match '02_buffer_with_arguments' do
action :create
type 'null'
tag 'output.null'
parameters(
'buffer tag, argument1, argument2' => {
timekey: '1d'
}
)
end
8 changes: 8 additions & 0 deletions test/integration/1x-chef12/bash/spec/localhost/lwrp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
# its(:content) { should match %r|^\s*exclude_path\s+\["/tmp/access\.log\.\*\.gz",\s+"/tmp/access\.log\.\*\.bz2"\]$| }
end

describe file('/etc/td-agent/conf.d/test_section_attributes.conf') do
it { should be_a_file }
it { should be_mode 644 }
its(:content) { should match %r|^\s*.type null$| }
its(:content) { should match %r|^\s*<buffer tag, argument1, argument2>$| }
its(:content) { should match %r|^\s*</buffer>$| }
end

describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do
it { should be_a_file }
it { should be_mode 644 }
Expand Down
8 changes: 8 additions & 0 deletions test/integration/2x-chef12/bash/spec/localhost/lwrp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
# its(:content) { should match %r|^\s*exclude_path\s+\["/tmp/access\.log\.\*\.gz",\s+"/tmp/access\.log\.\*\.bz2"\]$| }
end

describe file('/etc/td-agent/conf.d/test_section_attributes.conf') do
it { should be_a_file }
it { should be_mode 644 }
its(:content) { should match %r|^\s*.type null$| }
its(:content) { should match %r|^\s*<buffer tag, argument1, argument2>$| }
its(:content) { should match %r|^\s*</buffer>$| }
end

describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do
it { should be_a_file }
it { should be_mode 644 }
Expand Down
8 changes: 8 additions & 0 deletions test/integration/2x-chef13/bash/spec/localhost/lwrp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
# its(:content) { should match %r|^\s*exclude_path\s+\["/tmp/access\.log\.\*\.gz",\s+"/tmp/access\.log\.\*\.bz2"\]$| }
end

describe file('/etc/td-agent/conf.d/test_section_attributes.conf') do
it { should be_a_file }
it { should be_mode 644 }
its(:content) { should match %r|^\s*.type null$| }
its(:content) { should match %r|^\s*<buffer tag, argument1, argument2>$| }
its(:content) { should match %r|^\s*</buffer>$| }
end

describe file('/etc/td-agent/conf.d/test_gelf_match.conf') do
it { should be_a_file }
it { should be_mode 644 }
Expand Down