Skip to content

Commit

Permalink
Re-add support for module load overrides (#235)
Browse files Browse the repository at this point in the history
* Re-add support for module load overrides
  • Loading branch information
stlng2 authored Dec 18, 2024
1 parent 7f4b9cb commit d4155c8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This file is used to list changes made in each version of the rsyslog cookbook.

## Unreleased

Allow module parameters to be configurable by attributes
e.g.`node['rsyslog']['imuxsock_directives']`

## 10.0.0 - *2024-12-12*

- Update rsyslog.conf template to support newer platforms
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ See `attributes/default.rb` for default values.
- `node['rsyslog']['server_per_host_template']` - Template to use in the `rsyslog::server` recipe when creating the `35-server-per-host.conf` file
- `node['rsyslog']['server_per_host_cookbook']` - Cookbook name to get the `node['rsyslog']['server_per_host_template']` template from
- `node['rsyslog']['imfile']['KEY']` - Set `imfile` module parameters of label `KEY` to value. e.g. `PollingInterval`. Consult rsyslog documentation for valid entries.
- `node['rsyslog']['modules']` - Array of modules to load in the main rsyslog config filex
- `node['rsyslog']['<module>_directives']` - Hash of module directives and their values that apply to each `node['rsyslog']['modules']` when the module is loaded

## Recipes

Expand Down
3 changes: 2 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
default['rsyslog']['priv_user'] = nil
default['rsyslog']['priv_group'] = nil
default['rsyslog']['modules'] = %w(imuxsock imklog)
default['rsyslog']['imuxsock_directives'] = { 'SysSock.Use' => 'off' }
default['rsyslog']['file_create_mode'] = '0640'
default['rsyslog']['dir_create_mode'] = '0755'
default['rsyslog']['umask'] = '0022'
Expand Down Expand Up @@ -151,7 +152,7 @@
'local7.*' => "#{node['rsyslog']['default_log_dir']}/boot.log",
}
default['rsyslog']['modules'] = %w(imuxsock imjournal)
default['rsyslog']['additional_directives'] = { 'IMJournalStateFile' => 'imjournal.state' }
default['rsyslog']['imjournal_directives'] = { 'UsePid' => 'system', 'StateFile' => 'imjournal.state' }
else
# format { facility => destination }
default['rsyslog']['default_facility_logs'] = {
Expand Down
5 changes: 2 additions & 3 deletions spec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@

it do
is_expected.to render_file('/etc/rsyslog.conf').with_content('Config generated by Chef - manual edits will be overwritten')
%w(imuxsock imklog).each do |mod|
is_expected.to render_file('/etc/rsyslog.conf').with_content(/^module\(load="#{mod}"/)
end
is_expected.to render_file('/etc/rsyslog.conf').with_content(/^module\(load="imuxsock".*SysSock.Use=/)
is_expected.to render_file('/etc/rsyslog.conf').with_content(/^module\(load="imklog"/)
end

it do
Expand Down
13 changes: 4 additions & 9 deletions templates/default/rsyslog.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ $PreserveFQDN <%= node['rsyslog']['preserve_fqdn'] %>

<% if node['rsyslog']['modules'] && !node['rsyslog']['modules'].empty? %>
<% [*node['rsyslog']['modules']].each do |mod| %>
<% case mod -%>
<% when 'imuxsock' -%>
module(load="imuxsock" SysSock.Use="off")
<% when 'imjournal' -%>
module(load="imjournal" UsePid="system" StateFile="imjournal.state")
<% else -%>
module(load="<%= mod %>")
<% end %>
<% end %>
<% params = []%>
<% node['rsyslog']["#{mod}_directives"]&.each {|k, v| params.push("#{k}=\"#{v}\"")} %>
module(load="<%= mod %>" <%= params.join(' ') -%>)
<%- end -%>
<% end %>

<% if node['rsyslog']['server'] -%>
Expand Down

0 comments on commit d4155c8

Please sign in to comment.