diff options
author | Aaron Hicks <hicksa@landcareresearch.co.nz> | 2014-03-11 10:41:26 +1300 |
---|---|---|
committer | Aaron Hicks <hicksa@landcareresearch.co.nz> | 2014-03-11 10:41:26 +1300 |
commit | 66a9354a3de1e1cf224ee098ed8a7b59f79079ae (patch) | |
tree | 39a9cdfdde5cd0acb13a455e44827f705770ef42 | |
parent | 4d51a536a444ae629743a2c25673b0db1d1d1ef9 (diff) |
Define log templates with $template
Remove and update 'file managed by puppet' comment
-rw-r--r-- | README.md | 20 | ||||
-rw-r--r-- | manifests/client.pp | 2 | ||||
-rw-r--r-- | manifests/snippet.pp | 2 | ||||
-rw-r--r-- | spec/defines/rsyslog_snippet_spec.rb | 140 | ||||
-rw-r--r-- | templates/client.conf.erb | 13 | ||||
-rw-r--r-- | tests/log_templates.pp | 9 |
6 files changed, 110 insertions, 76 deletions
@@ -39,6 +39,23 @@ for read from file ```
+#### Defining custom logging templates
+
+The `log_templates` parameter can be used to set up custom logging templates, which can be used for local and/or remote logging. More detail on template formats can be found in the [rsyslog documentation](http://www.rsyslog.com/doc/rsyslog_conf_templates.html).
+
+The following examples sets up a custom logging template as per [RFC3164fmt](https://www.ietf.org/rfc/rfc3164.txt):
+
+```puppet
+class{'rsyslog::client':
+ log_templates => [
+ {
+ name => 'RFC3164fmt',
+ template => '<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg%',
+ },
+ ]
+}
+```
+
#### Logging to multiple remote servers
The `remote_servers` parameter can be used to set up logging to multiple remote servers which are supplied as a list of key value pairs for each remote. There is an example configuration provided in `./test/multiple_hosts.pp`
@@ -128,7 +145,6 @@ The following lists all the class parameters this module accepts. server_dir STRING Folder where logs will be stored on the server. Defaults to '/srv/log/'
custom_config STRING Specify your own template to use for server config. Defaults to undef. Example usage: custom_config => 'rsyslog/my_config.erb'
high_precision_timestamps true,false Whether or not to use high precision timestamps.
- actionfiletemplate STRING If set this defines the `ActionFileDefaultTemplate` which sets the default logging format for remote and local logging..
remote_servers HASH Provides a hash of multiple remote logging servers. Check documentation.
RSYSLOG::CLIENT CLASS PARAMETERS VALUES DESCRIPTION
@@ -140,6 +156,8 @@ The following lists all the class parameters this module accepts. custom_config STRING Specify your own template to use for client config. Defaults to undef. Example usage: custom_config => 'rsyslog/my_config.erb
server STRING Rsyslog server to log to. Will be used in the client configuration file.
preserve_fqdn true,false Whether or not to preserve the fully qualified domain name when logging.
+ log_templates HASH Provides a has defining custom logging templates using the `$template` configuration parameter.
+ actionfiletemplate STRING If set this defines the `ActionFileDefaultTemplate` which sets the default logging format for remote and local logging.
RSYSLOG::DATABASE CLASS PARAMETERS VALUES DESCRIPTION
-------------------------------------------------------------------
diff --git a/manifests/client.pp b/manifests/client.pp index dfc28e0..3cccff3 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -16,6 +16,7 @@ # [*port*]
# [*remote_servers*]
# [*ssl_ca*]
+# [*log_templates*]
# [*actionfiletemplate*]
#
# === Variables
@@ -36,6 +37,7 @@ class rsyslog::client ( $port = '514',
$remote_servers = false,
$ssl_ca = undef,
+ $log_templates = false,
$actionfiletemplate = false,
$preserve_fqdn = false
) inherits rsyslog {
diff --git a/manifests/snippet.pp b/manifests/snippet.pp index bb0468e..9edf179 100644 --- a/manifests/snippet.pp +++ b/manifests/snippet.pp @@ -26,7 +26,7 @@ define rsyslog::snippet( ensure => $ensure, owner => $rsyslog::run_user, group => $rsyslog::run_group, - content => "# file managed by puppet\n${content}\n", + content => "# This file is managed by Puppet, changes may be overwritten\n${content}\n", require => Class['rsyslog::config'], notify => Class['rsyslog::service'], } diff --git a/spec/defines/rsyslog_snippet_spec.rb b/spec/defines/rsyslog_snippet_spec.rb index a8f2575..4f3d5b8 100644 --- a/spec/defines/rsyslog_snippet_spec.rb +++ b/spec/defines/rsyslog_snippet_spec.rb @@ -1,70 +1,70 @@ -require 'spec_helper' - -describe 'rsyslog::snippet', :type => :define do - context "osfamily = RedHat" do - let :facts do - { - :osfamily => 'RedHat', - :operatingsystemrelease => 6.0, - } - end - - let (:params) { - { - 'content' => 'Random Content', - } - } - - context "default usage (osfamily = RedHat)" do - let(:title) { 'rsyslog-snippet-basic' } - - it 'should compile' do - should contain_file('/etc/rsyslog.d/rsyslog-snippet-basic.conf').with_content("# file managed by puppet\nRandom Content\n") - end - end - end - - context "osfamily = Debian" do - let :facts do - { - :osfamily => 'Debian', - } - end - - let (:params) { - { - 'content' => 'Random Content', - } - } - - context "default usage (osfamily = Debian)" do - let(:title) { 'rsyslog-snippet-basic' } - - it 'should compile' do - should contain_file('/etc/rsyslog.d/rsyslog-snippet-basic.conf').with_content("# file managed by puppet\nRandom Content\n") - end - end - end - - context "osfamily = FreeBSD" do - let :facts do - { - :osfamily => 'freebsd', - } - end - - let (:params) { - { - 'content' => 'Random Content', - } - } - - context "default usage (osfamily = Debian)" do - let(:title) { 'rsyslog-snippet-basic' } - - it 'should compile' do - should contain_file('/etc/syslog.d/rsyslog-snippet-basic.conf').with_content("# file managed by puppet\nRandom Content\n") - end - end - end -end +require 'spec_helper'
+
+describe 'rsyslog::snippet', :type => :define do
+ context "osfamily = RedHat" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => 6.0,
+ }
+ end
+
+ let (:params) {
+ {
+ 'content' => 'Random Content',
+ }
+ }
+
+ context "default usage (osfamily = RedHat)" do
+ let(:title) { 'rsyslog-snippet-basic' }
+
+ it 'should compile' do
+ should contain_file('/etc/rsyslog.d/rsyslog-snippet-basic.conf').with_content("# This file is managed by Puppet, changes may be overwritten\nRandom Content\n")
+ end
+ end
+ end
+
+ context "osfamily = Debian" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ }
+ end
+
+ let (:params) {
+ {
+ 'content' => 'Random Content',
+ }
+ }
+
+ context "default usage (osfamily = Debian)" do
+ let(:title) { 'rsyslog-snippet-basic' }
+
+ it 'should compile' do
+ should contain_file('/etc/rsyslog.d/rsyslog-snippet-basic.conf').with_content("# This file is managed by Puppet, changes may be overwritten\nRandom Content\n")
+ end
+ end
+ end
+
+ context "osfamily = FreeBSD" do
+ let :facts do
+ {
+ :osfamily => 'freebsd',
+ }
+ end
+
+ let (:params) {
+ {
+ 'content' => 'Random Content',
+ }
+ }
+
+ context "default usage (osfamily = Debian)" do
+ let(:title) { 'rsyslog-snippet-basic' }
+
+ it 'should compile' do
+ should contain_file('/etc/syslog.d/rsyslog-snippet-basic.conf').with_content("# This file is managed by Puppet, changes may be overwritten\nRandom Content\n")
+ end
+ end
+ end
+end
diff --git a/templates/client.conf.erb b/templates/client.conf.erb index 42dbccc..8b86ce1 100644 --- a/templates/client.conf.erb +++ b/templates/client.conf.erb @@ -1,4 +1,3 @@ -# file is managed by puppet # An "In-Memory Queue" is created for remote logging. $WorkDirectory <%= scope.lookupvar('rsyslog::spool_dir') -%> # where to place spool files @@ -7,14 +6,20 @@ $ActionQueueMaxDiskSpace <%= scope.lookupvar('rsyslog::client::spool_size') -%> $ActionQueueSaveOnShutdown on # save messages to disk on shutdown $ActionQueueType LinkedList # run asynchronously $ActionResumeRetryCount -1 # infinety retries if host is down +<% if scope.lookupvar('rsyslog::client::log_templates') and ! scope.lookupvar('rsyslog::client::log_templates').empty?-%> +# Define custom logging templates +<% scope.lookupvar('rsyslog::client::log_templates').flatten.compact.each do |log_template| -%> +$template <%= log_template['name'] %>,"<%= log_template['template'] %>" +<% end -%> +<% end -%> <% if scope.lookupvar('rsyslog::client::actionfiletemplate') -%> -# Using specified format for default logging fromat: +# Using specified format for default logging format: $ActionFileDefaultTemplate <%= scope.lookupvar('rsyslog::client::actionfiletemplate') %> <% else -%> -#Using default format for default logging fromat: +#Using default format for default logging format: $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat <% end -%> -<% if scope.lookupvar('rsyslog::client::remote_servers') and ! scope.lookupvar('rsyslog::client::remote_servers').empty? -%> +<% if scope.lookupvar('rsyslog::client::remote_servers') -%> <% scope.lookupvar('rsyslog::client::remote_servers').flatten.compact.each do |server| -%> <% if server['pattern'] and server['pattern'] != ''-%> <% pattern = server['pattern'] -%> diff --git a/tests/log_templates.pp b/tests/log_templates.pp new file mode 100644 index 0000000..79f1e8f --- /dev/null +++ b/tests/log_templates.pp @@ -0,0 +1,9 @@ +class{'rsyslog::client': + log_templates => [ + { + name => 'RFC3164fmt', + template => '<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg%', + }, + ], + actionfiletemplate => 'RFC3164fmt', +}
\ No newline at end of file |