diff --git a/README.md b/README.md index db2e188..57eaf0b 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,12 @@ Whether a service should be enabled to start at boot. Valid values are true, fal - *Default*: true +msg_reduction +------------- +Filter duplicated messages. Valid values are true and false. + +- *Default*: false + is_log_server ------------- Boolean to determine if the system syslog service is meant to receive messages from remote hosts. diff --git a/manifests/init.pp b/manifests/init.pp index 28508eb..90e6036 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -31,6 +31,7 @@ $daemon = 'USE_DEFAULTS', $daemon_ensure = 'running', $daemon_enable = true, + $msg_reduction = false, $is_log_server = false, $log_dir = '/srv/logs', $log_dir_owner = 'root', @@ -169,6 +170,13 @@ } } + if is_string($msg_reduction) == true { + $msg_reduction_bool = str2bool($msg_reduction) + } else { + $msg_reduction_bool = $msg_reduction + } + validate_bool($msg_reduction_bool) + validate_absolute_path($rsyslog_d_dir) validate_re($daemon_ensure, '^(running|stopped)$', "daemon_ensure may be either 'running' or 'stopped' and is set to <${daemon_ensure}>.") validate_absolute_path($kernel_target) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 2f09bc9..08c1034 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -570,6 +570,16 @@ end it { should contain_file('rsyslog_config').with_content(/^\$DirCreateMode 0770$/) } end + + context 'with msg_reduction=true' do + let :params do + { + :msg_reduction => 'true', + } + end + it { should contain_file('rsyslog_config').with_content(/^# Filter duplicated messages$/) } + it { should contain_file('rsyslog_config').with_content(/^\$RepeatedMsgReduction on$/) } + end end end diff --git a/templates/rsyslog.conf.erb b/templates/rsyslog.conf.erb index 02edd6e..f765cd0 100644 --- a/templates/rsyslog.conf.erb +++ b/templates/rsyslog.conf.erb @@ -43,6 +43,11 @@ $template TraditionalFormat,"%timegenerated% %HOSTNAME% %syslogtag%%msg:::drop-l <% else -%> $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat +<% if @msg_reduction_bool.to_s == 'true' -%> +# Filter duplicated messages +$RepeatedMsgReduction on +<% end -%> + # File syncing capability is disabled by default. This feature is usually not required, # not useful and an extreme performance hit #$ActionFileEnableSync on