diff --git a/manifests/master.pp b/manifests/master.pp index d8cd02c..620565f 100644 --- a/manifests/master.pp +++ b/manifests/master.pp @@ -1,141 +1,168 @@ -# munin::master - Define a munin master +# @summary configure a munin master +# +# @see http://guide.munin-monitoring.org/en/latest/ +# +# @example Basic usage +# include munin::master +# +# @example With TLS +# class { 'munin::master': +# tls => 'enabled', +# tls_certificate => '/path/to/tls/certificate', +# tls_private_key => '/path/to/tls/key', +# } # # The munin master will install munin, and collect all exported munin # node definitions as files into /etc/munin/munin-conf.d/. # # Parameters: # -# - node_definitions: A hash of node definitions used by +# @param node_definitions [Hash] A hash of node definitions used by # create_resources to make static node definitions. # -# - host_name: A host name for this munin master, matched with -# munin::node::mastername for collecting nodes. Defaults to $::fqdn +# @param host_name [String] A host name for this munin master, matched +# with munin::node::mastername for collecting nodes. Defaults to +# $::fqdn # -# - graph_strategy: 'cgi' (default) or 'cron' -# Controls if munin-graph graphs all services ('cron') or if graphing is done -# by munin-cgi-graph (which must configured seperatly) +# @param graph_strategy [Enum['cgi','cron']] 'cgi' (default) or 'cron' +# Controls if munin-graph graphs all services ('cron') or if +# graphing is done by munin-cgi-graph (which must configured +# seperatly) # -# - html_strategy: 'cgi' (default) or 'cron' +# @param html_strategy [Enum['cgi','cron']] 'cgi' (default) or 'cron' # Controls if munin-html will recreate all html pages every run interval # ('cron') or if html pages are generated by munin-cgi-graph (which must # configured seperatly) # -# - config_root: the root directory of the munin master configuration. -# Default: /etc/munin on most platforms. +# @param config_root [String] the root directory of the munin master +# configuration. Default: /etc/munin on most platforms. +# +# @param file_group [String] The group name for configuration file +# permissions. # -# - collect_nodes: 'enabled' (default), 'disabled', 'mine' or +# @param collect_nodes [Enum['enabled','disabled', +# 'mine','unclaimed']] 'enabled' (default), 'disabled', 'mine' or # 'unclaimed'. 'enabled' makes the munin master collect all exported # node_definitions. 'disabled' disables it. 'mine' makes the munin # master collect nodes matching $munin::master::host_name, while # 'unclaimed' makes the munin master collect nodes not tagged with a # host name. # -# - dbdir: Path to the munin dbdir, where munin stores everything +# @param dbdir [String] Path to the munin dbdir, where munin stores +# everything. # -# - htmldir: Path to where munin will generate HTML documents and -# graphs, used if graph_strategy is cron. +# @param htmldir [String] Path to where munin will generate HTML +# documents and graphs, used if graph_strategy is cron. # -# - rundir: Path to directory munin uses for pid and lock files. +# @param rundir [String] Path to directory munin uses for pid and lock +# files. # -# - tls: 'enabled' or 'disabled' (default). Controls the use of TLS -# globally for master to node communications. +# @param logdir [String] Path to directory munin uses for log files. # -# - tls_certificate: Path to a file containing a TLS certificate. No -# default. Required if tls is enabled. +# @param package_name [String] The package name used for installing +# the munin master. # -# - tls_private_key: Path to a file containing a TLS key. No default. -# Required if tls is enabled. +# @param tls [Enum['enabled','disabled']] 'enabled' or 'disabled' +# (default). Controls the use of TLS globally for master to node +# communications. # -# - tls_verify_certificate: 'yes' (default) or 'no'. +# @param tls_certificate [String] Path to a file containing a TLS +# certificate. No default. Required if tls is enabled. # -# - extra_config: Extra lines of config to put in munin.conf. - +# @param tls_private_key [String] Path to a file containing a TLS +# key. No default. Required if tls is enabled. +# +# @param tls_verify_certificate [Enum['yes','no']] 'yes' (default) or +# 'no'. +# +# @param extra_config [Array] Extra lines of config to put in +# munin.conf. class munin::master ( $node_definitions = $munin::params::master::node_definitions, $graph_strategy = $munin::params::master::graph_strategy, $html_strategy = $munin::params::master::html_strategy, $config_root = $munin::params::master::config_root, $collect_nodes = $munin::params::master::collect_nodes, $dbdir = $munin::params::master::dbdir, $htmldir = $munin::params::master::htmldir, $logdir = $munin::params::master::logdir, $rundir = $munin::params::master::rundir, $tls = $munin::params::master::tls, $tls_certificate = $munin::params::master::tls_certificate, $tls_private_key = $munin::params::master::tls_private_key, $tls_verify_certificate = $munin::params::master::tls_verify_certificate, $host_name = $munin::params::master::host_name, $file_group = $munin::params::master::file_group, $package_name = $munin::params::master::package_name, $extra_config = $munin::params::master::extra_config, ) inherits munin::params::master { if $node_definitions { validate_hash($node_definitions) } if $graph_strategy { validate_re($graph_strategy, [ '^cgi$', '^cron$' ]) } if $html_strategy { validate_re($html_strategy, [ '^cgi$', '^cron$' ]) } validate_re($collect_nodes, [ '^enabled$', '^disabled$', '^mine$', '^unclaimed$' ]) validate_absolute_path($config_root) validate_re($tls, [ '^enabled$', '^disabled$' ]) if $tls == 'enabled' { validate_re($tls_verify_certificate, [ '^yes$', '^no$' ]) validate_absolute_path($tls_private_key) validate_absolute_path($tls_certificate) } if $host_name { validate_string($host_name) if ! is_domain_name($host_name) { fail('host_name should be a valid domain name') } } validate_string($file_group) validate_string($package_name) validate_array($extra_config) # The munin package and configuration package { $package_name: ensure => latest, } File { owner => 'root', group => $file_group, mode => '0644', require => Package[$package_name], } file { "${config_root}/munin.conf": content => template('munin/munin.conf.erb'), } file { "${config_root}/munin-conf.d": ensure => directory, recurse => true, purge => true, force => true, } if $collect_nodes != 'disabled' { class { '::munin::master::collect': collect_nodes => $collect_nodes, host_name => $host_name, } } # Create static node definitions if $node_definitions { create_resources(munin::master::node_definition, $node_definitions, {}) } } diff --git a/manifests/master/collect.pp b/manifests/master/collect.pp index 875f07d..149be33 100644 --- a/manifests/master/collect.pp +++ b/manifests/master/collect.pp @@ -1,30 +1,35 @@ -# Class to collect the exported munin nodes. +# @summary Helper class to collect the exported munin nodes. # # This is separated into its own class to avoid warnings about missing # storeconfigs. # - +# @api private +# +# @param collect_nodes[Enum['enabled','mine', 'unclaimed','disabled']] +# +# @param host_name [String] Host named used for selecting exported +# resources to collect. class munin::master::collect ( $collect_nodes, $host_name, ) { case $collect_nodes { 'enabled': { Munin::Master::Node_definition <<| |>> } 'mine': { # Collect nodes explicitly tagged with this master Munin::Master::Node_definition <<| tag == "munin::master::${host_name}" |>> } 'unclaimed': { # Collect all exported node definitions, except the ones tagged # for a specific master Munin::Master::Node_definition <<| tag == 'munin::master::' |>> } 'disabled', default: { # do nothing } } } diff --git a/manifests/master/node_definition.pp b/manifests/master/node_definition.pp index 088fa0f..2a3cee1 100644 --- a/manifests/master/node_definition.pp +++ b/manifests/master/node_definition.pp @@ -1,42 +1,40 @@ -# munin::master::node_definition - A node definition for the munin -# master. +# @summary Configure information about a munin node on the munin +# master # -# - title: 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, +# ('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. # -# Parameters +# @param address [String] The address of the munin node. A hostname, +# an IP address, or a ssh:// uri for munin-async node. # -# - address: The address of the munin node. A hostname, an IP address, -# or a ssh:// uri for munin-async node. Required. +# @param mastername [String] The name of the munin master server which +# will collect the node definition. # -# - mastername: The name of the munin master server which will collect -# the node definition. -# -# - config: An array of configuration lines to be added to the node -# definition. Default is an empty array. +# @param config [Array[String]] An array of configuration lines to be +# added to the node definition. # define munin::master::node_definition ( $address, $mastername='', $config=[], ) { include ::munin::params::master $config_root = $munin::params::master::config_root validate_string($address) validate_array($config) validate_string($config_root) $filename=sprintf('%s/munin-conf.d/node.%s.conf', $config_root, regsubst($name, '[^[:alnum:]\.]', '_', 'IG')) file { $filename: content => template('munin/master/node.definition.conf.erb'), } } diff --git a/manifests/node.pp b/manifests/node.pp index 423d5b9..c521150 100644 --- a/manifests/node.pp +++ b/manifests/node.pp @@ -1,190 +1,207 @@ -# munin::node - Configure a munin node, and export configuration a -# munin master can collect. +# @summary configure a munin node # -# Parameters: +# Configure a munin node, and export configuration a munin master can +# collect. # -# allow: List of IPv4 and IPv6 addresses and networks to allow to connect. +# @see http://guide.munin-monitoring.org/en/latest/ # -# config_root: Root directory for munin configuration. +# @example Basic usage +# include munin::node # -# nodeconfig: List of lines to append to the munin node configuration. +# @param allow [Array] List of IPv4 and IPv6 addresses and networks to +# allow to connect. # -# host_name: The host name munin node identifies as. Defaults to -# the $::fqdn fact. +# @param config_root [String] Root directory for munin configuration. # -# log_dir: The log directory for the munin node process. Defaults -# change according to osfamily, see munin::params::node for details. +# @param nodeconfig [Array[String]] List of lines to append to the +# munin node configuration. # -# log_file: Appended to "log_dir". Defaults to "munin-node.log". +# @param host_name [String] The host name munin node identifies +# as. Defaults to the $::fqdn fact. # -# log_destination: "file" or "syslog". Defaults to "file". If log_destination -# is "syslog", the "log_file" and "log_dir" parameters are ignored, and the -# "syslog_*" parameters are used if set. +# @param log_dir [String] The log directory for the munin node +# process. Defaults change according to osfamily, see +# munin::params::node for details. # -# purge_configs: Removes all other munin plugins and munin plugin -# configuration files. Boolean, defaults to false. +# @param log_file [String] File name for the log file, this is +# appended to "log_dir". Defaults to "munin-node.log". # -# syslog_facility: Defaults to undef, which makes munin-node use the -# perl Net::Server module default of "daemon". Possible values are any -# syslog facility by number, or lowercase name. +# @param log_destination [Enum['file','syslog']]: "file" or "syslog". +# Defaults to "file". If log_destination is "syslog", the +# "log_file" and "log_dir" parameters are ignored, and the +# "syslog_*" parameters are used if set. # -# masterconfig: List of configuration lines to append to the munin -# master node definitinon +# @param purge_configs [Boolean] Removes all other munin plugins and +# munin plugin configuration files. Boolean, defaults to false. # -# mastername: The name of the munin master server which will collect -# the node definition. +# @param syslog_facility [Optional[String]]: Defaults to undef, which +# makes munin-node use the perl Net::Server module default of +# "daemon". Possible values are any syslog facility by number, or +# lowercase name. # -# mastergroup: The group used on the master to construct a FQN for -# this node. Defaults to "", which in turn makes munin master use the -# domain. Note: changing this for a node also means you need to move -# rrd files on the master, or graph history will be lost. +# @param masterconfig [Array[String]] List of configuration lines to +# append to the munin master node definitinon # -# plugins: A hash used by create_resources to create munin::plugin -# instances. +# @param mastername [String] The name of the munin master server which +# will collect the node definition. # -# address: The address used in the munin master node definition. +# @param mastergroup [String] The group used on the master to +# construct a FQN for this node. Defaults to "", which in turn makes +# munin master use the domain. Note: changing this for a node also +# means you need to move rrd files on the master, or graph history +# will be lost. # -# bind_address: The IP address the munin-node process listens on. Defaults: *. +# @param plugins [Hash] A hash used by create_resources to create +# munin::plugin instances. # -# bind_port: The port number the munin-node process listens on. +# @param address [String] The address used in the munin master node +# definition. # -# package_name: The name of the munin node package to install. +# @param bind_address [String] The IP address the munin-node process +# listens on. Defaults: *. # -# service_name: The name of the munin node service. +# @param bind_port [String] The port number the munin-node process +# listens on. # -# service_ensure: Defaults to "". If set to "running" or "stopped", it -# is used as parameter "ensure" for the munin node service. +# @param package_name [String] The name of the munin node package to +# install. # -# export_node: "enabled" or "disabled". Defaults to "enabled". -# Causes the node config to be exported to puppetmaster. +# @param service_name [String] The name of the munin node service. # -# file_group: The UNIX group name owning the configuration files, -# log files, etc. +# @param service_ensure [Enum['','running','stopped']] Defaults to +# "". If set to "running" or "stopped", it is used as parameter +# "ensure" for the munin node service. # -# timeout: Used to set the global plugin runtime timeout for this -# node. Integer. Defaults to undef, which lets munin-node use its -# default of 10 seconds. - +# @param export_node [Enum['enabled','disabled']]: "enabled" or +# "disabled". Defaults to "enabled". Causes the node config to be +# exported to puppetmaster. +# +# @param file_group [String] The UNIX group name owning the +# configuration files, log files, etc. +# +# @param timeout [Optional[Integer]] Used to set the global plugin +# runtime timeout for this node. Defaults to undef, which lets +# munin-node use its default of 10 seconds. class munin::node ( $address = $munin::params::node::address, $allow = $munin::params::node::allow, $bind_address = $munin::params::node::bind_address, $bind_port = $munin::params::node::bind_port, $config_root = $munin::params::node::config_root, $host_name = $munin::params::node::host_name, $log_dir = $munin::params::node::log_dir, $log_file = $munin::params::node::log_file, $masterconfig = $munin::params::node::masterconfig, $mastergroup = $munin::params::node::mastergroup, $mastername = $munin::params::node::mastername, $nodeconfig = $munin::params::node::nodeconfig, $package_name = $munin::params::node::package_name, $plugins = $munin::params::node::plugins, $purge_configs = $munin::params::node::purge_configs, $service_ensure = $munin::params::node::service_ensure, $service_name = $munin::params::node::service_name, $export_node = $munin::params::node::export_node, $file_group = $munin::params::node::file_group, $log_destination = $munin::params::node::log_destination, $syslog_facility = $munin::params::node::syslog_facility, $timeout = $munin::params::node::timeout, ) inherits munin::params::node { validate_array($allow) validate_array($nodeconfig) validate_array($masterconfig) if $mastergroup { validate_string($mastergroup) } if $mastername { validate_string($mastername) } validate_hash($plugins) validate_string($address) validate_absolute_path($config_root) validate_string($package_name) validate_string($service_name) if $service_ensure { validate_re($service_ensure, '^(running|stopped)$') } validate_re($export_node, '^(enabled|disabled)$') validate_absolute_path($log_dir) validate_re($log_destination, '^(?:file|syslog)$') validate_string($log_file) validate_string($file_group) validate_bool($purge_configs) if $timeout { validate_integer($timeout) } case $log_destination { 'file': { $_log_file = "${log_dir}/${log_file}" validate_absolute_path($_log_file) } 'syslog': { $_log_file = 'Sys::Syslog' if $syslog_facility { validate_string($syslog_facility) validate_re($syslog_facility, '^(?:\d+|(?:kern|user|mail|daemon|auth|syslog|lpr|news|uucp|authpriv|ftp|cron|local[0-7]))$') } } default: { fail('log_destination is not set') } } if $mastergroup { $fqn = "${mastergroup};${host_name}" } else { $fqn = $host_name } if $service_ensure { $_service_ensure = $service_ensure } else { $_service_ensure = undef } # Defaults File { ensure => present, owner => 'root', group => $file_group, mode => '0444', } package { $package_name: ensure => installed, } service { $service_name: ensure => $_service_ensure, enable => true, require => Package[$package_name], } file { "${config_root}/munin-node.conf": content => template('munin/munin-node.conf.erb'), require => Package[$package_name], notify => Service[$service_name], } # Export a node definition to be collected by the munin master. # (Separated into its own class to prevent warnings about "missing # storeconfigs", even if $export_node is not enabled) if $export_node == 'enabled' { class { '::munin::node::export': address => $address, fqn => $fqn, mastername => $mastername, masterconfig => $masterconfig, } } # Generate plugin resources from hiera or class parameter. create_resources(munin::plugin, $plugins, {}) # Purge unmanaged plugins and plugin configuration files. if $purge_configs { file { ["${config_root}/plugins", "${config_root}/plugin-conf.d" ]: ensure => directory, recurse => true, purge => true, require => Package[$package_name], notify => Service[$service_name], } } } diff --git a/manifests/node/export.pp b/manifests/node/export.pp index f0c7ce0..66d78e2 100644 --- a/manifests/node/export.pp +++ b/manifests/node/export.pp @@ -1,25 +1,43 @@ -# Class to export the munin node. +# @summary Helper class to export the munin node. +# +# This class exports a munin::master::node_definition to PuppetDB, +# where one or more munin masters can collect it. # # This is separated into its own class to avoid warnings about missing # storeconfigs. # +# @api private +# +# @param address [String] +# +# @param fqn [String] A munin Fully Qualified Name +# +# @param masterconfig [Array[String]] List of lines used for +# configuring the master when connecting to this node +# +# @param mastername [String] The name of the munin master which will +# collect these exported munin nodes. This is used for tagging the +# exported resources. +# +# @param node_definitions [Hash] A hash of extra +# Munin::Master::Node_definitions to export from this node class munin::node::export ( $address, $fqn, $masterconfig, $mastername, $node_definitions = {}, ) { Munin::Master::Node_definition { mastername => $mastername, tag => "munin::master::${mastername}", } @@munin::master::node_definition{ $fqn: address => $address, config => $masterconfig, } if ! empty($node_definitions) { create_resources('@@munin::master::node_definition', $node_definitions) } } diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 091385e..3b705d3 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -1,89 +1,120 @@ -# munin::plugin +# @summary Install and configure munin plugins # -# Parameters: +# @example Activate a packaged plugin +# munin::plugin { 'cpu': +# ensure => link, +# } # -# - ensure: "link", "present", "absent" or "". Default is "". The -# ensure parameter is mandatory for installing a plugin. -# - source: when ensure => present, source file -# - target: 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. -# - config: array of lines for munin plugin config -# - config_label: label for munin plugin config - +# @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 ( $ensure='', $source=undef, $target='', $config=undef, $config_label=undef, ) { include ::munin::node $plugin_share_dir=$munin::node::plugin_share_dir validate_absolute_path($plugin_share_dir) File { require => Package[$munin::node::package_name], notify => Service[$munin::node::service_name], } validate_re($ensure, '^(|link|present|absent)$') case $ensure { 'present', 'absent': { $handle_plugin = true $plugin_ensure = $ensure $plugin_target = undef } 'link': { $handle_plugin = true $plugin_ensure = 'link' case $target { '': { $plugin_target = "${munin::node::plugin_share_dir}/${title}" } /^\//: { $plugin_target = $target } default: { $plugin_target = "${munin::node::plugin_share_dir}/${target}" } } validate_absolute_path($plugin_target) } default: { $handle_plugin = false } } if $config { $config_ensure = $ensure ? { 'absent'=> absent, default => present, } } else { $config_ensure = absent } if $handle_plugin { # Install the plugin file {"${munin::node::config_root}/plugins/${name}": ensure => $plugin_ensure, source => $source, target => $plugin_target, mode => '0755', } } # Config file{ "${munin::node::config_root}/plugin-conf.d/${name}.conf": ensure => $config_ensure, content => template('munin/plugin_conf.erb'), } }