From 6af0df03ef40d9db3ab9d385f1779a155a95f565 Mon Sep 17 00:00:00 2001 From: Greig McGill Date: Thu, 7 Jul 2016 09:30:55 +1200 Subject: [PATCH] Add ability to define the server port as part of a log_server entry --- README.md | 7 ++++--- spec/classes/init_spec.rb | 8 ++++++-- templates/rsyslog.conf.erb | 4 ++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index db2e188..16b1ec9 100644 --- a/README.md +++ b/README.md @@ -335,7 +335,7 @@ Transport protocol used by rsyslog. Valid values are 'tcp' and 'udp' log_server ---------- -String or array of server to send logs to if remote_logging is true. +String or array of server to send logs to if remote_logging is true. May include an optional port number if you wish to override the log_server_port value for an entry. *Example:*
@@ -345,14 +345,15 @@ _OR_
 
 rsyslog::log_server:
   - 'log1'
-  - 'log2'
+  - 'log2:1514'
+  - 'log3:2514'
 
- *Default*: "log.${::domain}" log_server_port --------------- -Port of the server to send logs to if remote_logging is true. +Default port of the server to send logs to if remote_logging is true. Will not be used if a log_server entry contains a port number. - *Default*: '514' diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 9f111e1..baf7970 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -250,7 +250,7 @@ it { should contain_file('rsyslog_config').without_content(/^\$ModLoad imtcp.so$/) } end - ['logserver', %w(logserver1 logserver2)].each do |values| + ['logserver', %w(logserver1 logserver2 logserver3:1514 logserver4:2514)].each do |values| context "with remote_logging enabled and log_server=#{values} (as #{values.class})" do let :params do { @@ -261,7 +261,11 @@ if values.class == Array values.each do |value| - it { should contain_file('rsyslog_config').with_content(/^\*\.\* @@#{value}:514$/) } + if value.include? ":" + it { should contain_file('rsyslog_config').with_content(/^\*\.\* @@#{value}$/) } + else + it { should contain_file('rsyslog_config').with_content(/^\*\.\* @@#{value}:514$/) } + end end else it { should contain_file('rsyslog_config').with_content(/^\*\.\* @@logserver:514$/) } diff --git a/templates/rsyslog.conf.erb b/templates/rsyslog.conf.erb index 02edd6e..c7d870a 100644 --- a/templates/rsyslog.conf.erb +++ b/templates/rsyslog.conf.erb @@ -106,9 +106,13 @@ $ActionQueueType LinkedList # run asynchronously $ActionResumeRetryCount -1 # infinite retries if host is down <% end -%> <% @log_server_real.each do |server| -%> +<% if server.include? ":" -%> +<%= @source_facilities %> <% if @transport_protocol == 'tcp' -%>@<% end -%>@<%= server %> +<% else -%> <%= @source_facilities %> <% if @transport_protocol == 'tcp' -%>@<% end -%>@<%= server -%>:<%= @log_server_port %> <% end -%> <% end -%> +<% end -%> <% if @rsyslog_conf_version_real > 2 -%> <% if @is_log_server_real.to_s == 'true' -%>