diff --git a/README.md b/README.md index ec72361..4d2955b 100644 --- a/README.md +++ b/README.md @@ -389,6 +389,32 @@ icinga2::object::sysloglogger { 'syslog-warning': See [SyslogLogger](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-servicegroup) on [docs.icinga.org](http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/configuring-icinga2#objecttype-sysloglogger) for more info. +####`icinga2::conf` + +This defined type creates custom files in the icinga2/ conf.d directory. + +The content of the file can be managed with two alternative parameters + +`template` is erb tmplate to use for the content (ie: site/icinga2/baseservices.conf.erb) +`source` is the file server source url for a static file (ie: puppet:///modules/site/icinga2/baseservices.conf) + +To dynamically manage the variables of your template use the parameter: +`options_hash` it can be feed by an hash of data that is accessible in the template (<%= @options_hash['groups'] %> + +Example usage: + +
+icinga2::conf { 'baseservices': + template => 'site/icinga2/baseservices.conf.erb', + options_hash => { + enable_notifications => true, + check_interval => '5', + groups => [ 'all-servers' , 'linux-servers' ], + } +} ++ + ## Documentation The latest documentation is also available on https://docs.icinga.org diff --git a/manifests/conf.pp b/manifests/conf.pp new file mode 100644 index 0000000..87c0afa --- /dev/null +++ b/manifests/conf.pp @@ -0,0 +1,60 @@ +# = Define: icinga2::conf +# +# General Apache define to be used to create generic custom .conf files +# Very simple wrapper to a normal file type +# Use source or template to define the source +# +# == Parameters +# +# [*source*] +# Sets the content of source parameter for the dotconf file +# If defined, icinga2 dotconf file will have the param: source => $source +# +# [*template*] +# Sets the path to the template to use as content for dotconf file +# If defined, icinga2 dotconf file has: content => content("$template") +# Note source and template parameters are mutually exclusive: don't use both +# +# [*options_hash*] +# Custom hash with key values to use in custom templates +# +define icinga2::conf ( + $source = '' , + $template = '' , + $options_hash = undef, + $ensure = present, + $target_dir = '/etc/icinga2/conf.d', + $target_file_name = "${name}.conf", + $target_file_owner = 'root', + $target_file_group = 'root', + $target_file_mode = '644' + ) { + + validate_string($target_dir) + validate_string($target_file_name) + validate_string($target_file_owner) + validate_string($target_file_group) + validate_string($target_file_mode) + + $manage_file_source = $source ? { + '' => undef, + default => $source, + } + + $manage_file_content = $template ? { + '' => undef, + default => template($template), + } + + file { "${target_dir}/${target_file_name}": + ensure => $ensure, + owner => $target_file_owner, + group => $target_file_group, + mode => $target_file_mode, + notify => Service['icinga2'], + source => $manage_file_source, + content => $manage_file_content, + } + +} +