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

add support for mutiple log server #89

Merged
merged 3 commits into from
Dec 20, 2015
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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,18 @@ Transport protocol used by rsyslog. Valid values are 'tcp' and 'udp'

log_server
----------
Server to send logs to if remote_logging is true.
String or array of server to send logs to if remote_logging is true.

*Example:*
<pre>
rsyslog::log_server: 'log'
</pre>
_OR_
<pre>
rsyslog::log_server:
- 'log1'
- 'log2'
</pre>

- *Default*: "log.${::domain}"

Expand Down
13 changes: 13 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,19 @@
}
validate_bool($is_log_server_real)

case type3x($log_server) {
'array': {
$log_server_real = $log_server
}
'string': {
$log_server_real = any2array($log_server)
}
default: {
fail('rsyslog::log_server must be an array or string.')
}
}
validate_array($log_server_real)

if is_string($remote_logging) == true {
$remote_logging_bool = str2bool($remote_logging)
} else {
Expand Down
69 changes: 69 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,26 @@
it { should contain_file('rsyslog_config').without_content(/^\$ModLoad imtcp.so$/) }
end

['logserver', %w(logserver1 logserver2)].each do |values|
context "with remote_logging enabled and log_server=#{values} (as #{values.class})" do
let :params do
{
:remote_logging => true,
:log_server => values,
}
end

if values.class == Array
values.each do |value|
it { should contain_file('rsyslog_config').with_content(/^\*\.\* @@#{value}:514$/) }
end
else
it { should contain_file('rsyslog_config').with_content(/^\*\.\* @@logserver:514$/) }
end

end
end

context 'with source_facilities set to an empty string' do
let :params do
{ :source_facilities => '' }
Expand Down Expand Up @@ -1327,4 +1347,53 @@
end

end

describe 'variable type and content validations' do
# set needed custom facts and variables
let :facts do
{
:kernel => 'Linux',
:osfamily => 'RedHat',
:operatingsystemrelease => '6.5',
:domain => 'defaultdomain',
:rsyslog_version => '5.8.10',
}
end
let(:validation_params) do
{
#:param => 'value',
}
end

validations = {
'array/string' => {
:name => %w(log_server),
:valid => [%w(ar ray), 'string'],
:invalid => [{ 'ha' => 'sh' }, 3, 2.42, true, false],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

242 eh.. @Phil-Friderici you listening to those belgium fellows while you code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that often these days, but yeah you are right :)

:message => 'must be an array or string',
},
}

validations.sort.each do |type, var|
var[:name].each do |var_name|
var[:valid].each do |valid|
context "with #{var_name} (#{type}) set to valid #{valid} (as #{valid.class})" do
let(:params) { validation_params.merge({ :"#{var_name}" => valid, }) }
it { should compile }
end
end

var[:invalid].each do |invalid|
context "with #{var_name} (#{type}) set to invalid #{invalid} (as #{invalid.class})" do
let(:params) { validation_params.merge({ :"#{var_name}" => invalid, }) }
it 'should fail' do
expect do
should contain_class(subject)
end.to raise_error(Puppet::Error, /#{var[:message]}/)
end
end
end
end # var[:name].each
end # validations.sort.each
end # describe 'variable type and content validations'
end
4 changes: 3 additions & 1 deletion templates/rsyslog.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ $ActionQueueSaveOnShutdown on # save messages to disk on shutdown
$ActionQueueType LinkedList # run asynchronously
$ActionResumeRetryCount -1 # infinite retries if host is down
<% end -%>
<%= @source_facilities %> <% if @transport_protocol == 'tcp' -%>@<% end -%>@<%= @log_server -%>:<%= @log_server_port %>
<% @log_server_real.each do |server| -%>
<%= @source_facilities %> <% if @transport_protocol == 'tcp' -%>@<% end -%>@<%= server -%>:<%= @log_server_port %>
<% end -%>
<% end -%>
<% if @rsyslog_conf_version_real > 2 -%>

Expand Down