From 55274a7b398d4810a946a93e781c5422b6a8dde9 Mon Sep 17 00:00:00 2001 From: Greig McGill Date: Thu, 7 Jul 2016 09:30:55 +1200 Subject: [PATCH 1/4] Add ability to define the server port as part of a log_server entry --- README.md | 4 ++-- templates/rsyslog.conf.erb | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index db2e188..e3e1935 100644 --- a/README.md +++ b/README.md @@ -345,14 +345,14 @@ _OR_
 rsyslog::log_server:
   - 'log1'
-  - 'log2'
+  - 'log2:1514'
 
- *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/templates/rsyslog.conf.erb b/templates/rsyslog.conf.erb index 02edd6e..92d11b6 100644 --- a/templates/rsyslog.conf.erb +++ b/templates/rsyslog.conf.erb @@ -106,6 +106,9 @@ $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 -%> From 6681e71c35fa4775bf1af5a3d3f351db510de48b Mon Sep 17 00:00:00 2001 From: Greig McGill Date: Thu, 7 Jul 2016 09:50:37 +1200 Subject: [PATCH 2/4] Whoops, missed an <% end -%> tag. --- templates/rsyslog.conf.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/rsyslog.conf.erb b/templates/rsyslog.conf.erb index 92d11b6..26fed45 100644 --- a/templates/rsyslog.conf.erb +++ b/templates/rsyslog.conf.erb @@ -106,12 +106,13 @@ $ActionQueueType LinkedList # run asynchronously $ActionResumeRetryCount -1 # infinite retries if host is down <% end -%> <% @log_server_real.each do |server| -%> - <% if server.include? ":" -%> +<% 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' -%> From 7362b3d7e784b2fc50be8ab108357f43d483079e Mon Sep 17 00:00:00 2001 From: Greig McGill Date: Thu, 7 Jul 2016 10:06:49 +1200 Subject: [PATCH 3/4] Ensure each server in the remote servers list ends with a newline when it includes a port --- templates/rsyslog.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/rsyslog.conf.erb b/templates/rsyslog.conf.erb index 26fed45..c7d870a 100644 --- a/templates/rsyslog.conf.erb +++ b/templates/rsyslog.conf.erb @@ -107,7 +107,7 @@ $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 -%> +<%= @source_facilities %> <% if @transport_protocol == 'tcp' -%>@<% end -%>@<%= server %> <% else -%> <%= @source_facilities %> <% if @transport_protocol == 'tcp' -%>@<% end -%>@<%= server -%>:<%= @log_server_port %> <% end -%> From bb1ebee33e2f6af009992a142e62762189b0e177 Mon Sep 17 00:00:00 2001 From: Greig McGill Date: Thu, 14 Jul 2016 19:34:27 +1200 Subject: [PATCH 4/4] Clarify README example and add basic spec test for log_server entries with port values. --- README.md | 3 ++- spec/classes/init_spec.rb | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e3e1935..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:*
@@ -346,6 +346,7 @@ _OR_
 rsyslog::log_server:
   - 'log1'
   - 'log2:1514'
+  - 'log3:2514'
 
- *Default*: "log.${::domain}" 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$/) }