diff --git a/logrotate/jobs.sls b/logrotate/jobs.sls index eb2b9ab..17da253 100644 --- a/logrotate/jobs.sls +++ b/logrotate/jobs.sls @@ -6,16 +6,20 @@ include: - logrotate {% for key, value in jobs.items() %} + {% set contents = value.get('contents', False) %} logrotate-{{ key }}: file.managed: - name: {{ logrotate.include_dir }}/{{ key.split("/")[-1] }} - - source: salt://logrotate/templates/job.tmpl - - template: jinja - user: {{ salt['pillar.get']('logrotate:config:user', logrotate.user) }} - group: {{ salt['pillar.get']('logrotate:config:group', logrotate.group) }} - mode: {{ salt['pillar.get']('logrotate:config:mode', '644') }} - require: - pkg: logrotate-pkg + {% if contents %} + - contents: {{ contents | yaml_encode }} + {% else %} + - source: salt://logrotate/templates/job.tmpl + - template: jinja - context: {% if value is mapping %} path: {{ value.get('path', []) }} @@ -24,4 +28,6 @@ logrotate-{{ key }}: path: {{ key }} data: {{ value }} {% endif %} + {% endif %} {%- endfor -%} + diff --git a/pillar.example b/pillar.example index 7108c36..4786d99 100644 --- a/pillar.example +++ b/pillar.example @@ -47,3 +47,23 @@ logrotate: - postrotate - /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true - endscript + nginx: + contents: | + /var/log/nginx/*.log{ + weekly + missingok + compress + delaycompress + notifempty + create 0640 www-data adm + sharedscripts + prerotate + if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ + run-parts /etc/logrotate.d/httpd-prerotate; \ + fi \ + endscript + postrotate + invoke-rc.d nginx rotate >/dev/null 2>&1 + endscript + } + diff --git a/test/integration/default/controls/logrotate.rb b/test/integration/default/controls/base.rb similarity index 100% rename from test/integration/default/controls/logrotate.rb rename to test/integration/default/controls/base.rb diff --git a/test/integration/default/controls/jobs.rb b/test/integration/default/controls/jobs.rb new file mode 100644 index 0000000..dc59bde --- /dev/null +++ b/test/integration/default/controls/jobs.rb @@ -0,0 +1,71 @@ +# encoding: utf-8 + +title 'Test logrotate jobs configuration' + +describe file('/etc/logrotate.d/error') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } + # FIXME + #its('content') { should include '/tmp/var/log/mysql/error' } + its('content') { should include 'weekly' } + its('content') { should include 'missingok' } + its('content') { should include 'rotate 52' } + its('content') { should include 'compress' } + its('content') { should include 'delaycompress' } + its('content') { should include 'notifempty' } + its('content') { should include 'create 640 root adm' } + its('content') { should include 'sharedscripts' } +end + +describe file('/etc/logrotate.d/mysql') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } + its('content') { should include '/tmp/var/log/mysql/*.log' } + its('content') { should include 'weekly' } + its('content') { should include 'missingok' } + its('content') { should include 'rotate 52' } + its('content') { should include 'compress' } + its('content') { should include 'delaycompress' } + its('content') { should include 'notifempty' } + its('content') { should include 'create 640 root adm' } + its('content') { should include 'sharedscripts' } +end + +describe file('/etc/logrotate.d/syslog') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } + its('content') { should include '/var/log/cron' } + its('content') { should include '/var/log/maillog' } + its('content') { should include '/var/log/messages' } + its('content') { should include '/var/log/secure' } + its('content') { should include '/var/log/spooler' } + its('content') { should include '/var/log/slapd.log' } + its('content') { should include 'sharedscripts' } + its('content') { should include 'postrotate' } + its('content') { should include 'sharedscripts' } +end + +describe file('/etc/logrotate.d/nginx') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } + its('content') { should include '/var/log/nginx/*.log' } + its('content') { should include 'weekly' } + its('content') { should include 'missingok' } + its('content') { should include 'compress' } + its('content') { should include 'delaycompress' } + its('content') { should include 'prerotate' } + its('content') { should include 'if [ -d /etc/logrotate.d/httpd-prerotate ]; then \\' } + its('content') { should include ' run-parts /etc/logrotate.d/httpd-prerotate; \\' } + its('content') { should include ' fi \\' } + its('content') { should include 'postrotate' } + its('content') { should include ' invoke-rc.d nginx rotate >/dev/null 2>&1' } + +end diff --git a/test/integration/default/inspec.yml b/test/integration/default/inspec.yml index b062685..1096184 100644 --- a/test/integration/default/inspec.yml +++ b/test/integration/default/inspec.yml @@ -1,5 +1,5 @@ -name: shorewall -title: Shorewall Profile +name: logrotate +title: Logrotate Profile maintainer: Eric Veiras Galisson copyright: Eric Veiras Galisson copyright_email: eric AT sietch-tabr DOT com