Skip to content

Commit

Permalink
lint fb_syslog; delete uncontrolled files
Browse files Browse the repository at this point in the history
Also fixed some inconsistent syntax around module loading

Signed-off-by: Phil Dibowitz <phil@ipom.com>
  • Loading branch information
jaymzh committed Feb 23, 2025
1 parent 02022b7 commit a18215a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cookbooks/fb_syslog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Attributes
* node['fb_syslog']['rsyslog_use_omprog_force']
* node['fb_syslog']['rsyslog_stats_logging']
* node['fb_syslog']['rsyslog_report_suspension']
* node['fb_syslog']['rsyslog_d_preserve']
* node['fb_syslog']['sysconfig']['vars'][$KEY][$VAL]
* node['fb_syslog']['sysconfig']['extra_lines']

Expand Down Expand Up @@ -244,6 +245,11 @@ Set `node['fb_syslog']['rsyslog_stats_logging']` to true to enable periodic
output of rsyslog internal counters. These will be logged using the `impstats`
module to `/var/log/rsyslog-stats.log`.

### Controlling the syslog.d directory
By default, we will delete everything in the `/etc/rsyslog.d`, as all rsyslog
configuration should be controlled by users of this API. However, if you need
to preserve such files, set `node['fb_syslog']['rsyslog_d_preserve']` to `true`.

### sysconfig settings
On non-systemd systems, `node['fb_syslog']['sysconfig']` can be used
to setup `/etc/sysconfig/rsyslog` (for RedHat machines) or
Expand Down
13 changes: 12 additions & 1 deletion cookbooks/fb_syslog/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
'debian' => '/var/log/syslog',
)

authlog = value_for_platform_family(
['rhel', 'fedora'] => '/var/log/secure',
'default' => '/var/log/auth.log',
)

# Add in some reasonable defaults for all syslog.confs
default['fb_syslog'] = {
'syslog-entries' => {
Expand All @@ -43,9 +48,14 @@
'comment' => 'Log anything info level or higher. A lot ' +
'of things go into their own file.',
'selector' => '*.info;mail,authpriv,cron,' +
'local0,local1,local2,local3,local5,local6,local7.none',
'local0,local1,local2,local3,local4,local5,local6,local7.none',
'action' => "-#{syslog_file}",
},
'authlog' => {
'comment' => 'Log all auth stuff',
'selector' => 'auth,authpriv.*',
'action' => authlog,
},
'mail' => {
'comment' => 'Log all the mail messages in one place.',
'selector' => 'mail.*',
Expand Down Expand Up @@ -88,6 +98,7 @@
'$DirCreateMode 0755',
'$Umask 0002',
],
'rsyslog_d_preserve' => false,
'rsyslog_late_lines' => [],
'rsyslog_additional_sockets' => [],
'rsyslog_facilities_sent_to_remote' => [],
Expand Down
7 changes: 7 additions & 0 deletions cookbooks/fb_syslog/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
notifies :restart, "service[#{service_name}]"
end

directory '/etc/rsyslog.d' do
not_if { node['fb_syslog']['rsyslog_d_preserve'] }
action :delete
recursive true
notifies :restart, "service[#{service_name}]"
end

service service_name do
action :start
subscribes :restart, 'package[rsyslog]'
Expand Down
8 changes: 5 additions & 3 deletions cookbooks/fb_syslog/templates/default/rsyslog.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $PreserveFQDN on

#### MODULES ####
# Provides support for local system logging (e.g. via logger command)
$ModLoad imuxsock
module(load="imuxsock")
<% if node.centos? && !node.centos6? -%>
$OmitLocalLogging off
<% end -%>
Expand All @@ -27,8 +27,10 @@ module(load="omprog")
<% end -%>
<% if node['fb_syslog']['rsyslog_server'] -%>
# UDP / TCP reception
$ModLoad imudp
$ModLoad imtcp
module(load="imtcp")
input(type="imtcp" port="514")
module(load="imudp")
input(type="imudp" port="514")

<% if node['fb_syslog']['rsyslog_server_address'] -%>
$UDPServerAddress <%= node['fb_syslog']['rsyslog_server_address'] %>
Expand Down

0 comments on commit a18215a

Please sign in to comment.