diff --git a/data/common.yaml b/data/common.yaml index e623008..d0b59e0 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -1,25 +1,52 @@ --- +# - munin::master # Controlling puppet munin::master::collect_nodes: "enabled" munin::master::node_definitions: {} # For munin configuration munin::master::host_name: "%{trusted.certname}" munin::master::graph_strategy: "cgi" munin::master::html_strategy: "cgi" munin::master::extra_config: [] munin::master::tls: "disabled" munin::master::tls_certificate: "%{lookup(munin::master::config_root)}/cert.pem" munin::master::tls_private_key: "%{lookup(munin::master::config_root)}/key.pem" munin::master::tls_verify_certificate: "yes" munin::master::dbdir: :undef munin::master::rundir: :undef munin::master::htmldir: :undef munin::master::logdir: :undef # OS support munin::master::config_root: "/etc/munin" munin::master::file_group: "root" munin::master::package_name: "munin" + +# - munin::node +# for puppet +munin::node::purge_configs: false +munin::node::plugins: {} + +# for the exported master config +munin::node::export_node: 'enabled' +munin::node::address: "%{trusted.certname}" +munin::node::mastername: :undef +munin::node::mastergroup: :undef +munin::node::masterconfig: [] + +# service +munin::node::service_ensure: 'running' + +# for munin-node configuration +munin::node::host_name: "%{trusted.certname}" +munin::node::bind_address: '*' +munin::node::bind_port: 4949 +munin::node::allow: [] +munin::node::nodeconfig: [] +munin::node::log_file: 'munin-node.log' +munin::node::log_destination: 'file' +munin::node::syslog_facility: :undef +munin::node::timeout: :undef diff --git a/data/osfamily/ArchLinux.yaml b/data/osfamily/ArchLinux.yaml index a304355..e567ae6 100644 --- a/data/osfamily/ArchLinux.yaml +++ b/data/osfamily/ArchLinux.yaml @@ -1,4 +1,11 @@ --- munin::master::config_root: "/etc/munin" munin::master::file_group: "root" munin::master::package_name: "munin" + +munin::node::config_root: "/etc/munin" +munin::node::file_group: "root" +munin::node::log_dir: "/var/log/munin" +munin::node::package_name: "munin-node" +munin::node::plugin_share_dir: "/usr/lib/munin/plugins" +munin::node::service_name: "munin-node" diff --git a/data/osfamily/Debian.yaml b/data/osfamily/Debian.yaml index a304355..8639340 100644 --- a/data/osfamily/Debian.yaml +++ b/data/osfamily/Debian.yaml @@ -1,4 +1,11 @@ --- munin::master::config_root: "/etc/munin" munin::master::file_group: "root" munin::master::package_name: "munin" + +munin::node::config_root: "/etc/munin" +munin::node::file_group: "root" +munin::node::log_dir: "/var/log/munin" +munin::node::package_name: "munin-node" +munin::node::plugin_share_dir: "/usr/share/munin/plugins" +munin::node::service_name: "munin-node" diff --git a/data/osfamily/DragonFly.yaml b/data/osfamily/DragonFly.yaml index 2bbf593..f73810d 100644 --- a/data/osfamily/DragonFly.yaml +++ b/data/osfamily/DragonFly.yaml @@ -1,4 +1,11 @@ --- munin::master::config_root: '/usr/local/etc/munin' munin::master::file_group: 'wheel' munin::master::package_name: 'munin-master' + +munin::node::config_root: "/usr/local/etc/munin" +munin::node::file_group: "wheel" +munin::node::log_dir: "/var/log/munin" +munin::node::package_name: "munin-node" +munin::node::plugin_share_dir: "/usr/local/share/munin/plugins" +munin::node::service_name: "munin-node" diff --git a/data/osfamily/FreeBSD.yaml b/data/osfamily/FreeBSD.yaml index 2bbf593..f73810d 100644 --- a/data/osfamily/FreeBSD.yaml +++ b/data/osfamily/FreeBSD.yaml @@ -1,4 +1,11 @@ --- munin::master::config_root: '/usr/local/etc/munin' munin::master::file_group: 'wheel' munin::master::package_name: 'munin-master' + +munin::node::config_root: "/usr/local/etc/munin" +munin::node::file_group: "wheel" +munin::node::log_dir: "/var/log/munin" +munin::node::package_name: "munin-node" +munin::node::plugin_share_dir: "/usr/local/share/munin/plugins" +munin::node::service_name: "munin-node" diff --git a/data/osfamily/OpenBSD.yaml b/data/osfamily/OpenBSD.yaml new file mode 100644 index 0000000..03b8f6d --- /dev/null +++ b/data/osfamily/OpenBSD.yaml @@ -0,0 +1,7 @@ +--- +munin::node::config_root: "/etc/munin" +munin::node::log_dir: "/var/log/munin" +munin::node::service_name: "munin_node" +munin::node::package_name: "munin-node" +munin::node::plugin_share_dir: "/usr/local/libexec/munin/plugins" +munin::node::file_group: "wheel" diff --git a/data/osfamily/RedHat.yaml b/data/osfamily/RedHat.yaml index a0cdc4a..78c777a 100644 --- a/data/osfamily/RedHat.yaml +++ b/data/osfamily/RedHat.yaml @@ -1,4 +1,11 @@ --- munin::master::config_root: '/etc/munin' munin::master::file_group: 'root' munin::master::package_name: 'munin' + +munin::node::config_root: "/etc/munin" +munin::node::file_group: "root" +munin::node::log_dir: "/var/log/munin-node" +munin::node::package_name: "munin-node" +munin::node::plugin_share_dir: "/usr/share/munin/plugins" +munin::node::service_name: "munin-node" diff --git a/data/osfamily/Solaris.yaml b/data/osfamily/Solaris.yaml index 8fa4846..40d130a 100644 --- a/data/osfamily/Solaris.yaml +++ b/data/osfamily/Solaris.yaml @@ -1,4 +1,11 @@ --- munin::master::config_root: '/opt/local/etc/munin' munin::master::file_group: 'root' munin::master::package_name: 'munin' + +munin::node::config_root: "/opt/local/etc/munin" +munin::node::file_group: "root" +munin::node::log_dir: "/var/opt/log/munin" +munin::node::package_name: "munin-node" +munin::node::plugin_share_dir: "/opt/local/share/munin/plugins" +munin::node::service_name: "smf:/munin-node" diff --git a/manifests/master.pp b/manifests/master.pp index 9915ad5..b228239 100644 --- a/manifests/master.pp +++ b/manifests/master.pp @@ -1,133 +1,133 @@ # @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: # # @param node_definitions [Hash] A hash of node definitions used by # create_resources to make static node definitions. # # @param host_name [String] A host name for this munin master, matched # with munin::node::mastername for collecting nodes. Defaults to # $::fqdn # # @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) # # @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) # # @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. # # @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. # # @param dbdir [String] Path to the munin dbdir, where munin stores # everything. # # @param htmldir [String] Path to where munin will generate HTML # documents and graphs, used if graph_strategy is cron. # # @param rundir [String] Path to directory munin uses for pid and lock # files. # # @param logdir [String] Path to directory munin uses for log files. # # @param package_name [String] The package name used for installing # the munin master. # # @param tls [Enum['enabled','disabled']] 'enabled' or 'disabled' # (default). Controls the use of TLS globally for master to node # communications. # # @param tls_certificate [String] Path to a file containing a TLS # certificate. No default. Required if tls is enabled. # # @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 ( Hash $node_definitions, Enum['cgi', 'cron'] $graph_strategy, Enum['cgi', 'cron'] $html_strategy, Stdlib::Absolutepath $config_root, Enum['enabled', 'disabled', 'mine', 'unclaimed'] $collect_nodes, Optional[Stdlib::Absolutepath] $dbdir, Optional[Stdlib::Absolutepath] $htmldir, Optional[Stdlib::Absolutepath] $logdir, Optional[Stdlib::Absolutepath] $rundir, Enum['enabled', 'disabled'] $tls, Stdlib::Absolutepath $tls_certificate, Stdlib::Absolutepath $tls_private_key, Enum['yes','no'] $tls_verify_certificate, Stdlib::Host $host_name, String $file_group, Variant[String,Array[String]] $package_name, Array[String] $extra_config, ) { package { $package_name: ensure => installed, } 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 $settings::storeconfigs == 'true' { + if ($settings::storeconfigs == 'true' and $collect_nodes == 'enabled') { 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/node.pp b/manifests/node.pp index c521150..cf612f2 100644 --- a/manifests/node.pp +++ b/manifests/node.pp @@ -1,207 +1,189 @@ # @summary configure a munin node # # Configure a munin node, and export configuration a munin master can # collect. # # @see http://guide.munin-monitoring.org/en/latest/ # # @example Basic usage # include munin::node # # @param allow [Array] List of IPv4 and IPv6 addresses and networks to # allow to connect. # # @param config_root [String] Root directory for munin configuration. # # @param nodeconfig [Array[String]] List of lines to append to the # munin node configuration. # # @param host_name [String] The host name munin node identifies # as. Defaults to the $::fqdn fact. # # @param log_dir [String] The log directory for the munin node # process. Defaults change according to osfamily, see # munin::params::node for details. # # @param log_file [String] File name for the log file, this is # appended to "log_dir". Defaults to "munin-node.log". # # @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. # # @param purge_configs [Boolean] Removes all other munin plugins and # munin plugin configuration files. Boolean, defaults to false. # # @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. # # @param masterconfig [Array[String]] List of configuration lines to # append to the munin master node definitinon # # @param mastername [String] The name of the munin master server which # will collect the 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. # # @param plugins [Hash] A hash used by create_resources to create # munin::plugin instances. # # @param address [String] The address used in the munin master node # definition. # # @param bind_address [String] The IP address the munin-node process # listens on. Defaults: *. # # @param bind_port [String] The port number the munin-node process # listens on. # # @param package_name [String] The name of the munin node package to # install. # # @param service_name [String] The name of the munin node service. # -# @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. +# @param service_ensure Used as parameter "ensure" for the munin node +# service. # # @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) } + String $address, + Array $allow = $munin::params::node::allow, + Variant[Enum['*'],Stdlib::Host] $bind_address = $munin::params::node::bind_address, + Stdlib::Port $bind_port, + Stdlib::Absolutepath $config_root = $munin::params::node::config_root, + Stdlib::Host $host_name, + Stdlib::Absolutepath $log_dir = $munin::params::node::log_dir, + String $log_file, + Array $masterconfig, + Optional[String] $mastergroup, + Optional[Stdlib::Host] $mastername, + Array $nodeconfig, + String $package_name = $munin::params::node::package_name, # TODO: Array? + Hash $plugins, + Boolean $purge_configs = $munin::params::node::purge_configs, + Enum['running','stopped'] $service_ensure, + String $service_name = $munin::params::node::service_name, + Enum['enabled','disabled'] $export_node, + String $file_group = $munin::params::node::file_group, + Enum['file','syslog'] $log_destination, + Optional[ + Variant[ + Integer[0,23], + Enum[ + 'kern','user','mail','daemon','auth','syslog','lpr','news','uucp', + 'authpriv','ftp','cron','local0','local1','local2','local3','local4', + 'local5','local6','local7' + ]]] $syslog_facility, + Optional[Integer[0]] $timeout = $munin::params::node::timeout, # Integer? +) { 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' { + if ($settings::storeconfigs == 'true' and $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/params/node.pp b/manifests/params/node.pp deleted file mode 100644 index b273409..0000000 --- a/manifests/params/node.pp +++ /dev/null @@ -1,85 +0,0 @@ -# Parameters for the munin::node class. Add support for new OS -# families here. -class munin::params::node { - - $message = "Unsupported osfamily: ${::osfamily}" - - $address = $::fqdn - $host_name = $::fqdn - $bind_address = '*' - $bind_port = 4949 - $allow = [] - $masterconfig = [] - $mastergroup = undef - $mastername = undef - $nodeconfig = [] - $plugins = {} - $service_ensure = undef - $export_node = 'enabled' - $log_file = 'munin-node.log' - $log_destination = 'file' - $syslog_facility = undef - $purge_configs = false - $timeout = undef - - case $::osfamily { - 'Archlinux': { - $config_root = '/etc/munin' - $log_dir = '/var/log/munin' - $service_name = 'munin-node' - $package_name = 'munin-node' - $plugin_share_dir = '/usr/lib/munin/plugins' - $file_group = 'root' - } - 'RedHat': { - $config_root = '/etc/munin' - $log_dir = '/var/log/munin-node' - $service_name = 'munin-node' - $package_name = 'munin-node' - $plugin_share_dir = '/usr/share/munin/plugins' - $file_group = 'root' - } - 'Debian': { - $config_root = '/etc/munin' - $log_dir = '/var/log/munin' - $service_name = 'munin-node' - $package_name = 'munin-node' - $plugin_share_dir = '/usr/share/munin/plugins' - $file_group = 'root' - } - 'Solaris': { - case $::operatingsystem { - 'SmartOS': { - $config_root = '/opt/local/etc/munin' - $log_dir = '/var/opt/log/munin' - $service_name = 'smf:/munin-node' - $package_name = 'munin-node' - $plugin_share_dir = '/opt/local/share/munin/plugins' - $file_group = 'root' - } - default: { - fail("Unsupported operatingsystem ${::operatingsystem} for osfamily ${::osfamily}") - } - } - } - 'FreeBSD', 'DragonFly': { - $config_root = '/usr/local/etc/munin' - $log_dir = '/var/log/munin' - $service_name = 'munin-node' - $package_name = 'munin-node' - $plugin_share_dir = '/usr/local/share/munin/plugins' - $file_group = 'wheel' - } - 'OpenBSD': { - $config_root = '/etc/munin' - $log_dir = '/var/log/munin' - $service_name = 'munin_node' - $package_name = 'munin-node' - $plugin_share_dir = '/usr/local/libexec/munin/plugins' - $file_group = 'wheel' - } - default: { - fail($message) - } - } -} diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 3b705d3..5b3813d 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 ( - $ensure='', - $source=undef, - $target='', - $config=undef, - $config_label=undef, + Enum['','present','absent','link'] $ensure = '', + Optional[String] $source=undef, + String $target='', + Optional[Array[String]] $config = undef, + String $config_label = $title, ) { - include ::munin::node + include munin::node - $plugin_share_dir=$munin::node::plugin_share_dir - validate_absolute_path($plugin_share_dir) + $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[$munin::node::package_name], - notify => Service[$munin::node::service_name], + require => Package[$node_package_name], + notify => Service[$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 = "${plugin_share_dir}/${title}" } /^\//: { $plugin_target = $target } default: { - $plugin_target = "${munin::node::plugin_share_dir}/${target}" + $plugin_target = "${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}": + file {"${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": + file{ "${node_config_root}/plugin-conf.d/${name}.conf": ensure => $config_ensure, content => template('munin/plugin_conf.erb'), } - } diff --git a/spec/classes/munin_node_spec.rb b/spec/classes/munin_node_spec.rb index cd2ac9e..42e6a30 100644 --- a/spec/classes/munin_node_spec.rb +++ b/spec/classes/munin_node_spec.rb @@ -1,182 +1,170 @@ require 'spec_helper' t_conf_dir = {} t_conf_dir.default = '/etc/munin' t_conf_dir['DragonFly'] = '/usr/local/etc/munin' t_conf_dir['FreeBSD'] = '/usr/local/etc/munin' t_conf_dir['Solaris'] = '/opt/local/etc/munin' describe 'munin::node' do on_supported_os.each do |os, facts| # Avoid testing on distributions similar to RedHat and Debian next if os =~ %r{^(ubuntu|centos|scientific|oraclelinux)-} context "on #{os}" do let(:facts) { facts } it { is_expected.to compile.with_all_deps } it { is_expected.to contain_package('munin-node') } munin_confdir = t_conf_dir[facts[:osfamily]] munin_node_conf = "#{munin_confdir}/munin-node.conf" munin_plugin_dir = "#{munin_confdir}/plugins" munin_plugin_conf_dir = "#{munin_confdir}/plugin-conf.d" munin_node_service = case facts[:osfamily] when 'Solaris' then 'smf:/munin-node' else 'munin-node' end log_dir = case facts[:osfamily] when 'Solaris' then '/var/opt/log/munin' when 'RedHat' then '/var/log/munin-node' else '/var/log/munin' end it { is_expected.to contain_service(munin_node_service) } it { is_expected.to contain_file(munin_node_conf) } context 'with no parameters' do it { is_expected.to compile.with_all_deps } - it do - is_expected.to contain_service(munin_node_service) - .without_ensure - end + it { is_expected.to contain_service(munin_node_service) } it do is_expected.to contain_file(munin_node_conf) - .with_content(%r{host_name\s+foo.example.com}) + .with_content(%r{host_name\s+\S+$}) .with_content(%r{log_file\s+#{log_dir}/munin-node.log}) end end context 'with parameter allow' do let(:params) do { allow: ['2001:db8:1::', '2001:db8:2::/64', '192.0.2.129', '192.0.2.0/25', '192\.0\.2'] } end it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file(munin_node_conf) .with_content(%r{^cidr_allow 192\.0\.2\.0/25$}) .with_content(%r{^cidr_allow 2001:db8:2::/64$}) .with_content(%r{^allow \^192\\\.0\\\.2\\\.129\$$}) .with_content(%r{^allow 192\\.0\\.2$}) .with_content(%r{^allow \^2001:db8:1::\$$}) end end context 'with parameter host_name' do let(:params) do { host_name: 'something.example.com' } end it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file(munin_node_conf) .with_content(%r{host_name\s+something.example.com}) end end context 'with parameter service_ensure' do let(:params) do { service_ensure: 'running' } end it { is_expected.to compile.with_all_deps } it do is_expected.to contain_service('munin-node') .with_ensure('running') end end context 'logging to syslog' do context 'defaults' do let(:params) do { log_destination: 'syslog' } end it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file(munin_node_conf) .with_content(%r{log_file\s+Sys::Syslog}) end end context 'with syslog options' do let(:params) do { log_destination: 'syslog', syslog_facility: 'local1' } end it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file(munin_node_conf) .with_content(%r{log_file\s+Sys::Syslog}) .with_content(%r{syslog_facility\s+local1}) end end - - context 'with syslog_facility set to wrong value ' do - let(:params) do - { log_destination: 'syslog', - syslog_facility: 'wrong' } - end - - it { expect { is_expected.to compile.with_all_deps }.to raise_error(%r{validate_re}) } - end end context 'purge_configs' do context 'set' do let(:params) { { purge_configs: true } } it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file(munin_plugin_dir) .with_ensure('directory') .with_recurse(true) .with_purge(true) end it do is_expected.to contain_file(munin_plugin_conf_dir) .with_ensure('directory') .with_recurse(true) .with_purge(true) end end context 'unset' do it { is_expected.to compile.with_all_deps } it { is_expected.not_to contain_file(munin_plugin_dir) } it { is_expected.not_to contain_file(munin_plugin_conf_dir) } end end context 'timeout' do context 'set' do let(:params) { { timeout: 123 } } it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file(munin_node_conf) .with_content(%r{^timeout 123}) end end context 'unset' do it { is_expected.to compile.with_all_deps } it do is_expected.to contain_file(munin_node_conf) .without_content(%r{^timeout}) end end end end end end diff --git a/spec/defines/munin_plugin_spec.rb b/spec/defines/munin_plugin_spec.rb index ffa07cf..19b55f3 100644 --- a/spec/defines/munin_plugin_spec.rb +++ b/spec/defines/munin_plugin_spec.rb @@ -1,139 +1,136 @@ require 'spec_helper' t_conf_dir = {} t_conf_dir.default = '/etc/munin' t_conf_dir['Solaris'] = '/opt/local/etc/munin' t_conf_dir['FreeBSD'] = '/usr/local/etc/munin' t_share_dir = {} t_share_dir.default = '/usr/share/munin' t_share_dir['Solaris'] = '/opt/local/share/munin' t_share_dir['FreeBSD'] = '/usr/local/share/munin' t_share_dir['Archlinux'] = '/usr/lib/munin' describe 'munin::plugin', type: 'define' do let(:title) { 'testplugin' } on_supported_os.each do |os, facts| # Avoid testing on distributions similar to RedHat and Debian next if os =~ %r{^(ubuntu|centos|scientific|oraclelinux)-} context "on #{os}" do let(:facts) do facts end conf_dir = t_conf_dir[facts[:osfamily]] plugin_share_dir = "#{t_share_dir[facts[:osfamily]]}/plugins" context 'with no parameters' do - it do - expect { is_expected.to contain_file("#{conf_dir}/plugins/testplugin") } - .to raise_error("expected that the catalogue would contain File[#{conf_dir}/plugins/testplugin]") - end + it { is_expected.not_to contain_file("#{conf_dir}/plugins/testplugin") } it do is_expected.to contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('absent') end end context 'with ensure=link parameter' do let(:params) { { ensure: 'link' } } it do is_expected.to contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('link') .with_target("#{plugin_share_dir}/testplugin") end it do is_expected.to contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('absent') end end context 'with ensure=link and target parameters' do let(:title) { 'test_foo' } let(:params) do { ensure: 'link', target: 'test_' } end it do is_expected.to contain_file("#{conf_dir}/plugins/test_foo") .with_ensure('link') .with_target("#{plugin_share_dir}/test_") end it do is_expected.to contain_file("#{conf_dir}/plugin-conf.d/test_foo.conf") .with_ensure('absent') end end context 'with ensure=present and source parameters' do let(:params) do { ensure: 'present', source: 'puppet:///modules/munin/plugins/testplugin' } end it do is_expected.to contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('present') .with_source('puppet:///modules/munin/plugins/testplugin') end it do is_expected.to contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('absent') end end context 'with ensure=present, source and config parameters' do let(:params) do { ensure: 'present', source: 'puppet:///modules/munin/plugins/testplugin', config: ['something wonderful'] } end it do is_expected.to contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('present') .with_source('puppet:///modules/munin/plugins/testplugin') end it do is_expected.to contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('present') .with_content(%r{something wonderful}) end end context 'only configuration' do let(:params) do { config: ['env.rootdn cn=admin,dc=example,dc=org'], config_label: 'slapd_*' } end it do is_expected.to contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('present') .with_content(%r{env.rootdn}) end it do expect { is_expected.to contain_file("#{conf_dir}/plugins/testplugin") } .to raise_error("expected that the catalogue would contain File[#{conf_dir}/plugins/testplugin]") end end context 'with absolute target' do let(:params) do { ensure: 'link', target: '/full/path/to/testplugin' } end it do is_expected.to contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('link') .with_target('/full/path/to/testplugin') end end end end end