diff --git a/.fixtures.yml b/.fixtures.yml index bc768264..17b78b07 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -63,6 +63,9 @@ fixtures: 'fluentd': repo: 'git://github.com/enovance/puppet-fluentd.git' ref: 'd073a97002c569d8bfc38ac814ee33ed2cb13ca6' + 'logrotate': + repo: 'git://github.com/enovance/puppet-logrotate.git' + ref: 'f4d12356301fa2992f51dc7225037bb07556cb28' 'haproxy': repo: 'git://github.com/enovance/puppetlabs-haproxy.git' ref: 'fc1166f28d411dfd4f59d4bfd6936595c014a11b' diff --git a/Puppetfile b/Puppetfile index 8ba8330b..743b0bd8 100644 --- a/Puppetfile +++ b/Puppetfile @@ -113,6 +113,9 @@ mod 'kwalify', mod 'libvirt', :git => 'git://github.com/enovance/puppetlabs-libvirt.git', :ref => '05808874715ca3e899861a0af139e6a48255d3cb' +mod 'logrotate', + :git => 'git://github.com/enovance/puppet-logrotate.git', + :ref => 'f4d12356301fa2992f51dc7225037bb07556cb28' mod 'memcached', :git => 'git://github.com/enovance/puppet-memcached.git', :ref => 'd009260de3c7623003318555ec5ca61217ea3ca1' diff --git a/manifests/logging/agent.pp b/manifests/logging/agent.pp index 94c184bc..167caf7c 100644 --- a/manifests/logging/agent.pp +++ b/manifests/logging/agent.pp @@ -35,12 +35,17 @@ # (optional) Fluentd plugins to install # Defaults to empty hash # +# [*logrotate_rule*] +# (optional) A log rotate rule for the logging agent +# Defaults to empty hash +# class cloud::logging::agent( - $syslog_enable = false, - $sources = {}, - $matches = {}, - $plugins = {}, -){ + $syslog_enable = false, + $sources = {}, + $matches = {}, + $plugins = {}, + $logrotate_rule = $cloud::params::logging_agent_logrotate_rule, +) inherits cloud::params { include cloud::logging @@ -63,5 +68,6 @@ class cloud::logging::agent( create_resources('fluentd::source', $sources, {'require' => 'File[/var/db/td-agent]', 'notify' => 'Service[td-agent]'}) create_resources('fluentd::match', $matches, {'notify' => 'Service[td-agent]'}) create_resources('fluentd::install_plugin', $plugins) + create_resources('logrotate::rule', $logrotate_rule) } diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 00000000..6091dbe1 --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,39 @@ +# +# Copyright (C) 2014 eNovance SAS +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# == Class: cloud::params +# +# Configure set of default parameters +# +class cloud::params { + + # cloud::logging::agent + $logging_agent_logrotate_rule = { + 'td-agent' => { + 'path' => '/var/log/td-agent/td-agent.log', + 'rotate' => 30, + 'compress' => true, + 'delaycompress' => true, + 'ifempty' => false, + 'create' => true, + 'create_mode' => '640', + 'create_owner' => 'td-agent', + 'create_group' => 'td-agent', + 'sharedscripts' => true, + 'postrotate' => ['pid=/var/run/td-agent/td-agent.pid', 'test -s $pid && kill -USR1 "$(cat $pid)"'], + } + } + +} diff --git a/spec/classes/cloud_logging_agent.rb b/spec/classes/cloud_logging_agent.rb index 22d9d105..79600b89 100644 --- a/spec/classes/cloud_logging_agent.rb +++ b/spec/classes/cloud_logging_agent.rb @@ -28,11 +28,19 @@ describe 'cloud::logging::agent' do end let :common_params do { - :server => '127.0.0.1', - :sources => { + :plugins => {}, + :matches => {}, + :sources => { 'apache' => {'type' => 'tail', 'configfile' => 'apache'}, 'syslog' => {'type' => 'tail', 'configfile' => 'syslog'} - } + }, + :logrotate_rule => { + 'td-agent' => { + 'path' => '/var/log/td-agent/td-agent.log', + 'rotate' => '30', + 'compress' => 'true', + } + }, } end @@ -80,6 +88,42 @@ describe 'cloud::logging::agent' do :group => 'td-agent', }) end + + it 'has a logrotate rule for td-agent.log' do + it should contain_logrotate__rule('td-agent').with({ + :path => '/var/log/td-agent/td-agent.log', + :rotate => '30', + :compress => 'true', + }) + end + + end + + context 'logrotate rule with default parameters' do + + it 'has a logrotate rule for td-agent.log' do + it should contain_logrotate__rule('td-agent').with({ + :path => '/var/log/td-agent/td-agent.log', + :rotate => '30', + :compress => 'true', + }) + end + + end + + context 'logrotate rule with custom parameters' do + let :params do + common_params.merge!( {:logrotate_rule => { 'td-agent' => { 'path' => '/foo/bar', 'rotate' => '5', 'compress' => 'false'} }} ) + end + + it 'has a logrotate rule for td-agent.log' do + it should contain_logrotate__rule('td-agent').with({ + :path => '/foo/bar', + :rotate => '5', + :compress => 'false', + }) + end + end end