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

Fix default group and dir-group for RHEL-derived linux config #153

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This file is used to list changes made in each version of the rsyslog cookbook.

## Unreleased

- Remove remote.conf when no more remote servers
- Enhance imfile template management
- Fix default group and dir-group for RHEL-derived linux config

## 7.2.1 - *2020-11-23*

- Fixed a bug during the release of 7.2.0
Expand All @@ -13,6 +17,7 @@ This file is used to list changes made in each version of the rsyslog cookbook.

- Add an attribute for setting the mode on the configuration directory


xorima marked this conversation as resolved.
Show resolved Hide resolved
## 7.1.0 (2020-10-26)

### Changed
Expand Down
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
}
when 'rhel', 'fedora', 'amazon'
default['rsyslog']['working_dir'] = '/var/lib/rsyslog'
default['rsyslog']['group'] = 'root'
default['rsyslog']['dir_group'] = 'root'
# format { facility => destination }
default['rsyslog']['default_facility_logs'] = {
'*.info;mail.none;authpriv.none;cron.none' => "#{node['rsyslog']['default_log_dir']}/messages",
Expand Down
37 changes: 20 additions & 17 deletions recipes/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,25 @@

if rsyslog_servers.empty?
Chef::Log.warn('The rsyslog::client recipe was unable to determine the remote syslog server. Checked both the server_ip attribute and search! Not forwarding logs.')
else
remote_type = node['rsyslog']['use_relp'] ? 'relp' : 'remote'
template "#{node['rsyslog']['config_prefix']}/rsyslog.d/49-remote.conf" do
source "49-#{remote_type}.conf.erb"
owner node['rsyslog']['config_files']['owner']
group node['rsyslog']['config_files']['group']
mode node['rsyslog']['config_files']['mode']
variables(servers: rsyslog_servers)
notifies :run, 'execute[validate_config]'
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
only_if { node['rsyslog']['remote_logs'] }
end
end

file "#{node['rsyslog']['config_prefix']}/rsyslog.d/server.conf" do
action :delete
notifies :run, 'execute[validate_config]'
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
end
# create or delete config as appropriate
remote_type = node['rsyslog']['use_relp'] ? 'relp' : 'remote'
template "#{node['rsyslog']['config_prefix']}/rsyslog.d/49-remote.conf" do
source "49-#{remote_type}.conf.erb"
owner node['rsyslog']['config_files']['owner']
group node['rsyslog']['config_files']['group']
mode node['rsyslog']['config_files']['mode']
variables(servers: rsyslog_servers)
notifies :run, 'execute[validate_config]'
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
only_if { node['rsyslog']['remote_logs'] }
action rsyslog_servers.empty? ? :delete : :create
end

file "#{node['rsyslog']['config_prefix']}/rsyslog.d/server.conf" do
action :delete
notifies :run, 'execute[validate_config]'
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
end

46 changes: 30 additions & 16 deletions resources/file_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,37 @@
property :template_source, String, default: 'file-input.conf.erb'

action :create do
log_name = new_resource.name
template "/etc/rsyslog.d/#{new_resource.priority}-#{new_resource.name}.conf" do
mode '0664'
owner node['rsyslog']['user']
group node['rsyslog']['group']
source new_resource.template_source
cookbook new_resource.cookbook_source
variables 'file_name' => new_resource.file,
'tag' => log_name,
'state_file' => log_name,
'severity' => new_resource.severity,
'facility' => new_resource.facility
notifies :restart, "service[#{node['rsyslog']['service_name']}]", :delayed
create_template(:create)
end

action :delete do
create_template(:delete)
end

action_class do
def log_name
new_resource.name
end

service node['rsyslog']['service_name'] do
supports restart: true, status: true
action [:enable, :start]
def create_template(create_action)
template "/etc/rsyslog.d/#{new_resource.priority}-#{new_resource.name}.conf" do
mode '0664'
owner node['rsyslog']['user']
group node['rsyslog']['group']
Comment on lines +42 to +43
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @bish0polis

Taking another look at this these would be much better as properties on the resource which default to these values for now.

Thanks

source new_resource.template_source
cookbook new_resource.cookbook_source
variables 'file_name' => new_resource.file,
'tag' => log_name,
'state_file' => log_name,
'severity' => new_resource.severity,
'facility' => new_resource.facility
action create_action
notifies :restart, "service[#{node['rsyslog']['service_name']}]", :delayed
end

service node['rsyslog']['service_name'] do
supports restart: true, status: true
action [:enable, :start]
end
end
end