diff --git a/manifests/master/node_definition.pp b/manifests/master/node_definition.pp index 4075ebf..c81c2bb 100644 --- a/manifests/master/node_definition.pp +++ b/manifests/master/node_definition.pp @@ -1,34 +1,46 @@ # @summary Configure information about a munin node on the munin # master # -# The title of the defined resource should be a munin FQN, -# ('hostname', 'group;hostname', 'group;subgroup;hostname'). If a -# group is not set, munin will by default use the domain of the node -# as a group. +# The title of the defined resource should be a munin FQN. See the +# "fqn" parameter # # @param address [String] The address of the munin node. A hostname, # an IP address, or a ssh:// uri for munin-async node. # # @param mastername [String] The name of the munin master server which # will collect the node definition. # # @param config [Array[String]] An array of configuration lines to be # added to the node definition. # +# @param fqn +# (titlevar) The Munin FQN (Fully Qualified Name) of the node. +# This should be 'hostname', 'group;hostname', 'group;subgroup;hostname'). +# +# If a group is not set, munin will by default use the domain of the +# node as a group, if the node name is a fully qualified host name. +# define munin::master::node_definition ( String $address, Optional[String] $mastername='', Array[String] $config=[], + String $fqn = $title, ) { $config_root = lookup('munin::master::config_root', Stdlib::Absolutepath) $filename=sprintf('%s/munin-conf.d/node.%s.conf', $config_root, regsubst($name, '[^[:alnum:]\.]', '_', 'IG')) + $template_vars = { + 'fqn' => $fqn, + 'address' => $address, + 'config' => $config + } + file { $filename: - content => template('munin/master/node.definition.conf.erb'), + content => epp('munin/master/node.definition.conf.epp', $template_vars ), } } diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 5b3813d..0f41d82 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -1,120 +1,120 @@ # @summary Install and configure munin plugins # # @example Activate a packaged plugin # munin::plugin { 'cpu': # ensure => link, # } # # @example Activate a packaged wildcard plugin # munin::plugin { 'foo_bar': # ensure => link, # target => 'foo_', # } # # @example Install and activate a plugin # munin::plugin { 'gazonk': # ensure => present, # source => 'puppet:///modules/profile/foo/monitoring/gazonk', # } # # @example A plugin with configuration # munin::plugin { 'bletch': # ensure => link, # config => ['env.database thing', 'user bletch'], # } # # @example A plugin configuration file, but no plugin # munin::plugin { 'slapd': # config => ['env.rootdn cn=admin,dc=example,dc=org'], # config_label => 'slapd_*', # } # # @param ensure [Enum['link','present','absent','']] The ensure # parameter is mandatory for installing a plugin. # # @param source [String] when ensure => present, path to a source file # # @param target [String] when ensure => link, link target. If target # is an absolute path (starts with "/") it is used directly. If # target is a relative path, $munin::node::plugin_share_dir is # prepended. # # @param config [Array[String]] Lines for the munin plugin config. # # @param config_label [String] Label for munin plugin config define munin::plugin ( Enum['','present','absent','link'] $ensure = '', Optional[String] $source=undef, String $target='', - Optional[Array[String]] $config = undef, + Optional[Array[String]] $config = [], String $config_label = $title, ) { include munin::node $plugin_share_dir = lookup('munin::node::plugin_share_dir', Stdlib::Absolutepath) $node_config_root = lookup('munin::node::config_root', Stdlib::Absolutepath) $node_package_name = lookup('munin::node::package_name', String) $node_service_name = lookup('munin::node::service_name', String) File { require => Package[$node_package_name], notify => Service[$node_service_name], } case $ensure { 'present', 'absent': { $handle_plugin = true $plugin_ensure = $ensure $plugin_target = undef } 'link': { $handle_plugin = true $plugin_ensure = 'link' case $target { '': { $plugin_target = "${plugin_share_dir}/${title}" } /^\//: { $plugin_target = $target } default: { $plugin_target = "${plugin_share_dir}/${target}" } } validate_absolute_path($plugin_target) } default: { $handle_plugin = false } } - if $config { + if ! $config.empty { $config_ensure = $ensure ? { 'absent'=> absent, default => present, } } else { $config_ensure = absent } if $handle_plugin { # Install the plugin file {"${node_config_root}/plugins/${name}": ensure => $plugin_ensure, source => $source, target => $plugin_target, mode => '0755', } } # Config file{ "${node_config_root}/plugin-conf.d/${name}.conf": ensure => $config_ensure, - content => template('munin/plugin_conf.erb'), + content => epp('munin/plugin_conf.epp', { 'label' => $config_label, 'config' => $config }), } } diff --git a/templates/master/node.definition.conf.epp b/templates/master/node.definition.conf.epp new file mode 100644 index 0000000..d521082 --- /dev/null +++ b/templates/master/node.definition.conf.epp @@ -0,0 +1,14 @@ +<% | + String $fqn, + String $address, + Array[String] $config, +| -%> +# Munin master configuration fragment for <%= $fqn %> +# +# This file is handled by puppet, all modifications will be lost + +[<%= $fqn %>] + address <%= $address %> +<% $config.each |String $line| { -%> + <%= $line %> +<% } -%> diff --git a/templates/master/node.definition.conf.erb b/templates/master/node.definition.conf.erb deleted file mode 100644 index 99bd0cf..0000000 --- a/templates/master/node.definition.conf.erb +++ /dev/null @@ -1,9 +0,0 @@ -# Munin master configuration fragment for <%= @title %> -# -# This file is handled by puppet, all modifications will be lost - -[<%= @title %>] - address <%= @address %> -<% Array(@config).each do |line| -%> - <%= line %> -<% end -%> diff --git a/templates/plugin_conf.epp b/templates/plugin_conf.epp new file mode 100644 index 0000000..7930d8e --- /dev/null +++ b/templates/plugin_conf.epp @@ -0,0 +1,6 @@ +<% | + String $label, + Array[String] $config, +| -%> +[<%= $label %>] +<%= $config.join("\n") %> diff --git a/templates/plugin_conf.erb b/templates/plugin_conf.erb deleted file mode 100644 index b827992..0000000 --- a/templates/plugin_conf.erb +++ /dev/null @@ -1,10 +0,0 @@ -<% -# Select label from either config_label or from the namevar -if @config_label == :undef or @config_label.nil? then - label = @name -else - label = @config_label -end --%> -[<%= label %>] -<%= Array(@config).join("\n") %>