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

Msg reduction filtering. Close: #102 #108

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,16 @@
end
it { should contain_file('rsyslog_config').with_content(/^\$DirCreateMode 0770$/) }
end

context 'with msg_reduction=true' do
Copy link
Owner

Choose a reason for hiding this comment

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

Good test, though we also need if msg_reduction is false. Since we allow stringified booleans, 'true' and 'false', we should check those as well. Try this approach.

describe 'with msg_reduction' do
  [true,'true'].each do |value|
    context "set to #{value.class} #{value}" do
      let (:params) { { :msg_reduction => value } }
      ... put tests here ...
    end
  [false,'false'].each do |value|
    context "set to #{value.class} #{value}" do
      let (:params) { { :msg_reduction => value } }
      ... put tests here ...
    end
  end
end

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

Expand Down
5 changes: 5 additions & 0 deletions templates/rsyslog.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down