From 9ed54ac1c4c3cc9e95ed49af30474322991c5cb1 Mon Sep 17 00:00:00 2001 From: "ricardo@cropalato.com.br" Date: Wed, 26 Nov 2014 07:51:44 -0500 Subject: [PATCH] Adding FileLogger object. #7229. --- README.md | 16 ++++++++++ manifests/object/filelogger.pp | 45 ++++++++++++++++++++++++++++ templates/object_filelogger.conf.erb | 18 +++++++++++ 3 files changed, 79 insertions(+) create mode 100644 manifests/object/filelogger.pp create mode 100644 templates/object_filelogger.conf.erb diff --git a/README.md b/README.md index 3773d04..81051aa 100644 --- a/README.md +++ b/README.md @@ -401,6 +401,7 @@ Object types: * [icinga2::object::endpoint](#icinga2objectendpoint) * [icinga2::object::eventcommand](#icinga2objecteventcommand) * [icinga2::object::externalcommandlistener](#icinga2objectexternalcommandlistener) +* [icinga2::object::filelogger](#icinga2objectfilelogger) * [icinga2::object::host](#icinga2objecthost) * [icinga2::object::hostgroup](#icinga2objecthostgroup) * [icinga2::object::icingastatuswriter](#icinga2objecticingastatuswriter) @@ -608,6 +609,21 @@ icinga2::object::externalcommandlistener { 'external': See [ExternalCommandListener](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-externalcommandlistener) on [docs.icinga.org](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc) for a full list of parameters. +####[`icinga2::object::filelogger`](id:object_filelogger) + +This defined type creates file logger objects. + +Example: + +
+icinga2::object::filelogger { 'debug-file':
+  severity => 'debug',
+  path     => '/var/log/icinga2/debug.log',
+}
+
+ +See [FileLogger](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-filelogger) on [docs.icinga.org](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc) for a full list of parameters. + ####[`icinga2::object::host`](id:object_host) This defined type creates host objects. diff --git a/manifests/object/filelogger.pp b/manifests/object/filelogger.pp new file mode 100644 index 0000000..43e0154 --- /dev/null +++ b/manifests/object/filelogger.pp @@ -0,0 +1,45 @@ +# == Defined type: icinga2::object::filelogger +# +# This is a defined type for Icinga 2 apply objects that create File Logger +# See the following Icinga 2 doc page for more info: +# http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-filelogger +# +# === Parameters +# +# See the inline comments. +# + +define icinga2::object::filelogger ( + $ensure = 'file', + $object_name = $name, + $path = undef, + $severity = undef, + $target_dir = '/etc/icinga2/conf.d', + $target_file_name = "${object_name}.conf", + $target_file_owner = 'root', + $target_file_group = 'root', + $target_file_mode = '0644' +) { + + if $object_name { + validate_string($object_name) + } + validate_string($path) + if $severity { + validate_string($severity) + } + validate_string($target_dir) + validate_string($target_file_name) + validate_string($target_file_owner) + validate_string($target_file_group) + validate_re($target_file_mode, '^\d{4}$') + + file {"${target_dir}/${target_file_name}": + ensure => $ensure, + owner => $target_file_owner, + group => $target_file_group, + mode => $target_file_mode, + content => template('icinga2/object_filelogger.conf.erb'), + notify => Service['icinga2'] + } +} diff --git a/templates/object_filelogger.conf.erb b/templates/object_filelogger.conf.erb new file mode 100644 index 0000000..aab83ef --- /dev/null +++ b/templates/object_filelogger.conf.erb @@ -0,0 +1,18 @@ +/** +* WARNING: This FileLogger is automatically generated by Puppet. +* ANY MANUAL CHANGES TO IT WILL GET OVERWRITTEN! +*/ + +/** +* A FileLogger definition. You can create your own configuration files +* in the conf.d directory (e.g. one per commnand). By default all *.conf +* files in this directory are included. +* +*/ + +object FileLogger "<%= @object_name %>" { + <%- if @severity -%> + severity = "<%= severity -%>" + <%- end -%> + path = "<%= @path -%>" +}