diff --git a/.gitignore b/.gitignore index 8c0d25d..73da533 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -spec/fixtures \ No newline at end of file +spec/fixtures +vendor +.ruby-version +.bundle +Gemfile.lock diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..8c18f1a --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format documentation +--color diff --git a/.travis.yml b/.travis.yml index 668ef16..a344ecf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,23 @@ +--- language: ruby +bundler_args: --without development +before_install: rm Gemfile.lock || true rvm: - 1.9.3 - 2.1.0 -script: "rake spec" +env: + - PUPPET_VERSION="~> 3.2.0" + - PUPPET_VERSION="~> 3.3.0" + - PUPPET_VERSION="~> 3.4.0" + - PUPPET_VERSION="~> 3.5.0" + - PUPPET_VERSION="~> 3.6.0" + - PUPPET_VERSION="~> 3.7.0" +matrix: + exclude: + - rvm: 2.1.0 + env: PUPPET_VERSION="~> 3.2.0" + - rvm: 2.1.0 + env: PUPPET_VERSION="~> 3.3.0" + - rvm: 2.1.0 + env: PUPPET_VERSION="~> 3.4.0" +script: bundle exec rake spec diff --git a/CHANGELOG b/CHANGELOG index 85e34ae..84768f1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,79 +1,117 @@ # Changelog +## 0.0.6 - 2014-12-05 + +This release adds support for DragonFly BSD, FreeBSD, OpenBSD. + +Other changes listed below, per component. + +Contributors to this release: Alex Hornung, Chris Roddy, Frank +Groeneveld, Fredrik Thulin, Julien Pivotto, Martin Jackson, Sebastian +Wiesinger, Stig Sandbeck Mathisen + +### munin::node + +* Add "host_name" parameter to override the host name of the munin + node. + +* Add "file_group" parameter, used for configuration and log files. + +* Add "log_dir" parameter. + +* Improved handling of "allow" ACL parameter. + +### munin::master + +* Improved collection logic. Set "collect_nodes" to "mine" to collect + nodes which are targeted for this master, or "unclaimed" to pick up + nodes not aimed a specific master. + +* Add global tls_* parameters for connecting to nodes. + +* Add "dbdir", "htmldir", "rundir" parameters. + +* Add "extra_config" parameter, which takes an array of extra + configuration lines for munin.conf. + +### munin::plugin + +* Support absolute paths as target for a plugin. + ## 0.0.5 - 2014-03-19 * Support multiple masters with different nodes (Thanks: Cristian Gae) * Support older (1.4.6) munin versions (Thanks: Sergio Oliveira) - + * Update for compatibility with puppet 3.4 (Thanks: Harald Skoglund) * Easier configuration with more parameters. All parameters have trivial validation. ### munin::master - new parameter "config_root". Defaults should match supported operating systems. ### munin::plugin - new parameter "config_root". Defaults should match supported operating systems. ### munin::node - new parameter "address". Default is $::fqdn. This will be used as the "address" when registering with the munin master. - new parameter "config_root". Defaults should match supported operating systems. - new parameter "package_name". Default should match supported operating systems. - new parameter "service_name". Default should match supported operating systems. - new parameter "service_ensure". Default is "". Possible values: "", "running" or "stopped". ### munin::params - new class ## 0.0.4 - 2013-08-13 Bugfix for the munin::plugin define. - Bugfix: Ensure that we can run tests on ruby 1.8. - Bugfix: No longer requires the class `Munin::Plugins`, which does not exist in this module. ([#3](https://github.com/ssm/ssm-munin/issues/3)) - The `ensure` attribute no longer defaults to "link". If not set, a potentially existing plugin with the same name is not touched. - Plugin and configuration directories are now configurable. - Improved rspec tests, which now actually match the documentation. ## 0.0.2 - 2013-06-31 A few pull requests - Bugfix: Install munin package before creating munin-conf.d directory ([#1](https://github.com/ssm/ssm-munin/pull/1)) - Make graph strategy configurable ([#2](https://github.com/ssm/ssm-munin/pull/2)) - Improve documentation ## 0.0.1 - 2013-06-02 Initial release diff --git a/Gemfile b/Gemfile index 342d25f..3e72d45 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,17 @@ -source :rubygems -puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7'] - -gem 'puppet', puppetversion - +source 'https://rubygems.org' + group :test do - gem 'rake', '>= 0.9.0' - gem 'rspec', '>= 2.8.0' - gem 'rspec-puppet', '>= 0.1.1' + gem 'rake' + gem 'puppet', ENV['PUPPET_VERSION'] || '~> 3.7.0' + gem 'rspec-puppet', :git => 'https://github.com/rodjek/rspec-puppet.git', :ref => 'v2.0.0' gem 'puppetlabs_spec_helper' - gem 'puppet-lint' +end + +group :development do + gem 'travis' + gem 'travis-lint' + gem 'vagrant-wrapper' + gem 'puppet-blacksmith' + gem 'guard-rake' + gem 'metadata-json-lint' end diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..2cd45cb --- /dev/null +++ b/Guardfile @@ -0,0 +1,11 @@ +notification :off + +guard 'rake', :task => 'test' do + watch('Rakefile') + watch(%r{^manifests\/(.+)\.pp$}) + watch(%r{^templates\/(.+)\.erb$}) +end + +guard 'rake', :task => 'metadata' do + watch('metadata.json') +end diff --git a/Modulefile b/Modulefile deleted file mode 100644 index fbfc824..0000000 --- a/Modulefile +++ /dev/null @@ -1,7 +0,0 @@ -name 'ssm/munin' -version '0.0.5' -summary "Configure munin master, node and plugins" -description "A module for configuring munin master, node and plugins. - If puppetdb is used, node definitions are exported by munin::node, and automatically collected by munin::master. - Hiera can be used to define munin nodes." -dependency 'puppetlabs/stdlib', '>= 2.3.0' diff --git a/Rakefile b/Rakefile index 520801b..0db5abd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,37 @@ require 'puppetlabs_spec_helper/rake_tasks' - require 'puppet-lint/tasks/puppet-lint' -PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.send('disable_2sp_soft_tabs') -PuppetLint.configuration.send('disable_documentation') +require 'puppet-syntax/tasks/puppet-syntax' -desc "Validate manifests, templates, and ruby files" -task :validate do - Dir['manifests/**/*.pp'].each do |manifest| - sh "puppet parser validate --noop #{manifest}" - end - Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file| - sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ - end - Dir['templates/**/*.erb'].each do |template| - sh "erb -P -x -T '-' #{template} | ruby -c" - end +# Optional gems, used for development +begin + require 'puppet_blacksmith/rake_tasks' +rescue LoadError end + +# workaround for https://github.com/rodjek/puppet-lint/issues/331 +Rake::Task[:lint].clear + +PuppetLint.configuration.relative = true +PuppetLint.configuration.send("disable_80chars") +PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" +PuppetLint.configuration.fail_on_warnings = true + +exclude_paths = [ + 'pkg/**/*', + 'vendor/**/*', + 'spec/**/*', +] +PuppetLint.configuration.ignore_paths = exclude_paths +PuppetSyntax.exclude_paths = exclude_paths + +task :metadata do + sh 'metadata-json-lint metadata.json' +end + +desc 'Run syntax, lint, and spec tests.' +task :test => [ + :syntax, + :lint, + :spec, + :metadata, +] diff --git a/manifests/master.pp b/manifests/master.pp index dceadc8..287677a 100644 --- a/manifests/master.pp +++ b/manifests/master.pp @@ -1,95 +1,147 @@ # munin::master - Define a munin master # # 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 # 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 +# # - 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) # # - html_strategy: '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. # -# - collect_nodes: 'enabled' or 'disabled' default 'enabled'. -# Makes puppetmaster collect exported node_definitions. +# - collect_nodes: '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 +# +# - htmldir: 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. +# +# - tls: 'enabled' or 'disabled' (default). Controls the use of TLS +# globally for master to node communications. +# +# - tls_certificate: Path to a file containing a TLS certificate. No +# default. Required if tls is enabled. +# +# - tls_private_key: Path to a file containing a TLS key. No default. +# Required if tls is enabled. +# +# - tls_verify_certificate: 'yes' (default) or 'no'. +# +# - extra_config: Extra lines of config to put in munin.conf. class munin::master ( $node_definitions = $munin::params::master::node_defintions, $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, + $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$' ]) + 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_array($extra_config) + # The munin package and configuration package { 'munin': ensure => latest, } File { owner => 'root', group => 'root', mode => '0644', require => Package['munin'], } 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 == 'enabled' { - # Collect all exported node definitions - Munin::Master::Node_definition <<| mastername == $::fqdn or mastername == '' |>> + 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 + } } # Create static node definitions if $node_definitions { create_resources(munin::master::node_definition, $node_definitions, {}) } } diff --git a/manifests/master/node_definition.pp b/manifests/master/node_definition.pp index e272f94..dbf4755 100644 --- a/manifests/master/node_definition.pp +++ b/manifests/master/node_definition.pp @@ -1,32 +1,35 @@ # munin::master::node_definition - A node definition for the munin # master. # # - title: The title of the defined resource should be a munin FQN, -# ('hostname', 'group;hostname', 'group;subgroup;hostname') +# ('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 # # - address: The address of the munin node. A hostname, an IP address, # or a ssh:// uri for munin-async node. Required. # -# - mastername: 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. # define munin::master::node_definition ( $address, $mastername='', $config=[], ) { validate_string($address) validate_array($config) $filename=sprintf('/etc/munin/munin-conf.d/node.%s.conf', 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 512c2ac..85eaadf 100644 --- a/manifests/node.pp +++ b/manifests/node.pp @@ -1,114 +1,127 @@ # munin::node - Configure a munin node, and export configuration a # munin master can collect. # # Parameters: # # allow: List of IPv4 and IPv6 addresses and networks to allow to connect. # # config_root: Root directory for munin configuration. # # nodeconfig: List of lines to append to the munin node configuration. # +# host_name: The host name munin node identifies as. Defaults to +# the $::fqdn fact. +# +# log_dir: The log directory for the munin node process. Defaults +# change according to osfamily, see munin::params::node for details. +# # masterconfig: List of configuration lines to append to the munin # master node definitinon # # mastername: The name of the munin master server which will collect # the node definition. # +# 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. +# # plugins: A hash used by create_resources to create munin::plugin # instances. # # address: The address used in the munin master node definition. # # package_name: The name of the munin node package to install. # # service_name: The name of the munin node service. # # service_ensure: Defaults to "". If set to "running" or "stopped", it # is used as parameter "ensure" for the munin node service. # # export_node: "enabled" or "disabled". Defaults to "enabled". # Causes the node config to be exported to puppetmaster. # # file_group: The UNIX group name owning the configuration files, # log files, etc. class munin::node ( $address = $munin::params::node::address, $allow = $munin::params::node::allow, $config_root = $munin::params::node::config_root, + $host_name = $munin::params::node::host_name, $log_dir = $munin::params::node::log_dir, $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, $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, ) inherits munin::params::node { validate_array($allow) validate_array($nodeconfig) validate_array($masterconfig) validate_string($mastergroup) validate_string($mastername) validate_hash($plugins) validate_string($address) validate_absolute_path($config_root) validate_string($package_name) validate_string($service_name) validate_re($service_ensure, '^(|running|stopped)$') validate_re($export_node, '^(enabled|disabled)$') validate_absolute_path($log_dir) validate_string($file_group) if $mastergroup { - $fqn = "${mastergroup};${::fqdn}" + $fqn = "${mastergroup};${host_name}" } else { - $fqn = $::fqdn + $fqn = $host_name } # Defaults File { ensure => present, owner => 'root', group => $file_group, mode => '0444', } package { $package_name: ensure => installed, } service { $service_name: ensure => $service_ensure ? { '' => undef, default => $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 if $export_node == 'enabled' { @@munin::master::node_definition{ $fqn: address => $address, mastername => $mastername, config => $masterconfig, + tag => [ "munin::master::${mastername}" ] } } # Generate plugin resources from hiera or class parameter. create_resources(munin::plugin, $plugins, {}) } diff --git a/manifests/params/master.pp b/manifests/params/master.pp index 69724f2..30b4c9e 100644 --- a/manifests/params/master.pp +++ b/manifests/params/master.pp @@ -1,29 +1,31 @@ class munin::params::master { $message = "Unsupported osfamily ${::osfamily}" $graph_strategy = 'cgi' $html_strategy = 'cgi' $node_definitions = '' $collect_nodes = 'enabled' $dbdir = undef $htmldir = undef $logdir = undef $rundir = undef $tls = 'disabled' $tls_certificate = undef $tls_private_key = undef $tls_verify_certificate = 'yes' + $extra_config = [] + $host_name = $::fqdn case $::osfamily { 'Debian', 'RedHat': { $config_root = '/etc/munin' } 'Solaris': { $config_root = '/opt/local/etc/munin' } default: { fail($message) } } } diff --git a/manifests/params/node.pp b/manifests/params/node.pp index 0c0e30f..0f736d5 100644 --- a/manifests/params/node.pp +++ b/manifests/params/node.pp @@ -1,69 +1,70 @@ class munin::params::node { $message = "Unsupported osfamily: ${::osfamily}" $address = $::fqdn + $host_name = $::fqdn $allow = [] $masterconfig = [] $mastergroup = '' $mastername = '' $nodeconfig = [] $plugins = {} $service_ensure = '' $export_node = 'enabled' case $::osfamily { 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/metadata.json b/metadata.json index 7016764..82b09b3 100644 --- a/metadata.json +++ b/metadata.json @@ -1,69 +1,52 @@ { "name": "ssm/munin", - "version": "0.0.5", - "source": "UNKNOWN", + "version": "0.0.6", "author": "ssm", "license": "Apache License, Version 2.0", "summary": "Configure munin master, node and plugins", - "description": "A module for configuring munin master, node and plugins.\n If puppetdb is used, node definitions are exported by munin::node, and automatically collected by munin::master.\n Hiera can be used to define munin nodes.", - "project_page": "UNKNOWN", + "source": "https://github.com/ssm/ssm-munin", "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": ">= 2.3.0" } ], - "types": [ - - ], - "checksums": { - "CHANGELOG": "d26396b76fddd33440773f042a9b07e6", - "Gemfile": "6ce44488b00c2048dc62d35ddafb469c", - "Modulefile": "61d579669c9ef4c86b61d7ec58107730", - "README.md": "77e7962522c109140fef33b8e4dc8c22", - "Rakefile": "f867886eba95b4499e33f45d47bd5f48", - "manifests/master/node_definition.pp": "3a2d3120c2b0eec1656a01ee16aff8db", - "manifests/master.pp": "06db25c44a07da3976e0eb58e02be77d", - "manifests/node.pp": "6b24c42e367f669a721814879d30fba5", - "manifests/params/master.pp": "6e01da1a6a989662583912d10c65cadd", - "manifests/params/node.pp": "726c0854bb828f4f3cd5b141abe14395", - "manifests/plugin.pp": "3c32040eb393ed529768b68e0a8a9e06", - "spec/classes/munin_master_spec.rb": "6c421f7ad080a5e21ca594711d300e92", - "spec/classes/munin_node_spec.rb": "4f07d45733fb9bb0b1d58dc16355e81b", - "spec/defines/munin_plugin_spec.rb": "a4cc55424cd905a7dc28705caac9f492", - "spec/spec_helper.rb": "b464b19795b877cf0f64622c0fac5b25", - "templates/master/node.definition.conf.erb": "b321f84d2118f489b7c2e27518ee51e7", - "templates/munin-node.conf.erb": "57c669aa8b4aa15825e8bfe1bae1ce53", - "templates/munin.conf.erb": "87a06c1eee3e6c924c6ee7466b1275d7", - "templates/plugin_conf.erb": "2bfe6a3d09e26d36df77a68981576f0b" - }, + "project_page": "https://forge.puppetlabs.com/ssm/munin", + "issues_url": "https://github.com/ssm/ssm-munin/issues", "operatingsystem_support": [ { "operatingsystem": "CentOS" }, { "operatingsystem": "Debian" }, { "operatingsystem": "RedHat" }, { "operatingsystem": "Scientific" }, { "operatingsystem": "SmartOS" }, { "operatingsystem": "Ubuntu" }, { "operatingsystem": "FreeBSD" }, { "operatingsystem": "DragonFly" }, { "operatingsystem": "OpenBSD" } + ], + "tags": [ + "munin", + "monitoring", + "graphing", + "performance", + "trending" ] } diff --git a/spec/classes/munin_master_spec.rb b/spec/classes/munin_master_spec.rb index a7c2069..f8728e5 100644 --- a/spec/classes/munin_master_spec.rb +++ b/spec/classes/munin_master_spec.rb @@ -1,109 +1,155 @@ require 'spec_helper' describe 'munin::master' do [ :CentOS, :Debian, :RedHat, :Ubuntu ].each do |sc| context "Check for supported operatingsystem #{sc}" do include_context sc it { should compile } it { should contain_class('munin::master') } it { should contain_package('munin') should contain_file('/etc/munin/munin.conf') should contain_file('/etc/munin/munin-conf.d') .with_ensure('directory') } end end [ :SmartOS ].each do |sc| context "Check for supported operatingsystem #{sc}" do include_context sc it { should compile } it { should contain_class('munin::master') } it { should contain_package('munin') should contain_file('/opt/local/etc/munin/munin.conf') should contain_file('/opt/local/etc/munin/munin-conf.d') .with_ensure('directory') } end end context 'with default params' do it { should contain_file('/etc/munin/munin.conf') .with_content(/graph_strategy\s+cgi/) .with_content(/html_strategy\s+cgi/) } end context 'with html_strategy => cron' do let (:params) { { :html_strategy => 'cron' } } it { should contain_file('/etc/munin/munin.conf') .with_content(/html_strategy\s+cron/) } end context 'with graph_strategy => cron' do let (:params) { { :graph_strategy => 'cron' } } it { should contain_file('/etc/munin/munin.conf') .with_content(/graph_strategy\s+cron/) } end context 'with dbdir => /var/lib/munin' do let (:params) { { :dbdir => '/var/lib/munin' } } it { should contain_file('/etc/munin/munin.conf') .with_content(/dbdir\s+\/var\/lib\/munin/) } end context 'with htmldir => /var/www/munin' do let (:params) { { :htmldir => '/var/www/munin' } } it { should contain_file('/etc/munin/munin.conf') .with_content(/htmldir\s+\/var\/www\/munin/) } end context 'with logdir => /var/log/munin' do let (:params) { { :dbdir => '/var/log/munin' } } it { should contain_file('/etc/munin/munin.conf') .with_content(/dbdir\s+\/var\/log\/munin/) } end context 'with rudir => /var/run/munin' do let (:params) { { :dbdir => '/var/run/munin' } } it { should contain_file('/etc/munin/munin.conf') .with_content(/dbdir\s+\/var\/run\/munin/) } end context 'with tls => enabled' do let(:params) { { :tls => 'enabled', :tls_certificate => '/path/to/certificate.pem', :tls_private_key => '/path/to/key.pem', :tls_verify_certificate => 'yes', } } it { should compile } it { should contain_file('/etc/munin/munin.conf') .with_content(/tls = enabled/) .with_content(/tls_certificate = \/path\/to\/certificate\.pem/) .with_content(/tls_private_key = \/path\/to\/key\.pem/) .with_content(/tls_verify_certificate = yes/) } end + context 'with extra_config' do + token = '1b7febce-bb2d-4c18-b889-84c73538a900' + let(:params) do + { :extra_config => [ token ] } + end + it { should compile } + it do + should contain_file('/etc/munin/munin.conf') + .with_content(/#{token}/) + end + end + + context 'with extra_config set to a string' do + token = '1b7febce-bb2d-4c18-b889-84c73538a900' + let(:params) do + { :extra_config => token } + end + it { should raise_error(Puppet::Error, /is not an Array/) } + end + + ['test.example.com', 'invalid/hostname.example.com'].each do |param| + context "with host_name => #{param}" do + let(:params) do + { :host_name => param } + end + if param =~ /invalid/ + it { should raise_error(Puppet::Error, /valid domain name/) } + else + it { should compile } + end + end + end + + %w( enabled disabled mine unclaimed invalid ).each do |param| + context "with collect_nodes => #{param}" do + let(:params) do + { :collect_nodes => param } + end + if param == 'invalid' + it { should raise_error(Puppet::Error, /validate_re/) } + else + it { should compile } + end + end + end + end diff --git a/spec/classes/munin_node_spec.rb b/spec/classes/munin_node_spec.rb index da3c37e..9e8d0db 100644 --- a/spec/classes/munin_node_spec.rb +++ b/spec/classes/munin_node_spec.rb @@ -1,60 +1,79 @@ require 'spec_helper' describe 'munin::node' do [ :CentOS, :Debian, :RedHat, :Ubuntu ].each do |sc| context "Check for supported operatingsystem #{sc}" do include_context sc it { should compile } it { should contain_class('munin::node') } it { should contain_package('munin-node') should contain_service('munin-node') should contain_file('/etc/munin/munin-node.conf') } end end [ :SmartOS ].each do |sc| context "Check for supported operatingsystem #{sc}" do include_context sc it { should compile } it { should contain_class('munin::node') } it { should contain_package('munin-node') should contain_service('smf:/munin-node') should contain_file('/opt/local/etc/munin/munin-node.conf') } end end context 'unsupported' do include_context :unsupported it { expect { should contain_class('munin::node') }.to raise_error(Puppet::Error, /Unsupported osfamily/) } end context 'acl with ipv4 and ipv6 addresses' do include_context :Debian 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 do should contain_file('/etc/munin/munin-node.conf') .with_content(/^cidr_allow 192.0.2.0\/25$/) .with_content(/^cidr_allow 2001:db8:2::\/64$/) .with_content(/^allow \^192\\.0\\.2\\.129\$$/) .with_content(/^allow 192\\.0\\.2$/) .with_content(/^allow \^2001:db8:1::\$$/) end end + context 'with host_name unset' do + include_context :Debian + it do + should contain_file('/etc/munin/munin-node.conf') + .with_content(/host_name\s+testnode.example.com/) + end + end + + context 'with host_name set' do + include_context :Debian + let(:params) do + { host_name: 'something.example.com' } + end + it do + should contain_file('/etc/munin/munin-node.conf') + .with_content(/host_name\s+something.example.com/) + end + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b551090..c0b921b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,35 +1,34 @@ -require 'rubygems' require 'puppetlabs_spec_helper/module_spec_helper' RSpec.configure do |c| c.default_facts = { :operatingsystem => 'Debian', :osfamily => 'Debian', :fqdn => 'testnode.example.com', } end shared_context :unsupported do let(:facts) { { :osfamily => 'Unsupported', } } end shared_context :Debian do end shared_context :Ubuntu do let(:facts) { { :operatingsystem => 'Ubuntu', } } end shared_context :CentOS do let(:facts) { { :operatingsystem => 'CentOS', :osfamily => 'RedHat', } } end shared_context :RedHat do let(:facts) { { :osfamily => 'RedHat', } } end shared_context :SmartOS do let(:facts) { { :operatingsystem => 'SmartOS', :osfamily => 'Solaris', } } end diff --git a/templates/munin-node.conf.erb b/templates/munin-node.conf.erb index c2edb1c..187acd8 100644 --- a/templates/munin-node.conf.erb +++ b/templates/munin-node.conf.erb @@ -1,61 +1,61 @@ # /etc/munin/munin-node.conf - config-file for munin-node # # This file is handled by puppet, any local changes will be lost # <% require 'ipaddr' addresses = [] unrecognized = [] Array(@allow).flatten.each do |line| begin a = IPAddr.new(line) if a.ipv4? or a.ipv6? addresses << line end rescue ArgumentError, IPAddr::InvalidAddressError # Treat invalid addresses as "allow" arguments, as they can be # regular expressions. unrecognized << line end end -%> -host_name <%= scope.lookupvar('::fqdn') %> +host_name <%= @host_name %> log_level 4 log_file <%= @log_dir %>/munin-node.log port 4949 pid_file /var/run/munin/munin-node.pid background 1 setsid 1 # Which port to bind to; user root group <%= @file_group %> # Regexps for files to ignore ignore_file ~$ ignore_file \.bak$ ignore_file %$ ignore_file \.dpkg-(tmp|new|old|dist)$ ignore_file \.rpm(save|new)$ ignore_file \.puppet-bak$ # Hosts to allow <% addresses.each do |line| -%> <% if line.match(/\//) -%> cidr_allow <%= line %> <% else -%> allow ^<%= Regexp.quote(line) %>$ <% end -%> <% end -%> <% unrecognized.each do |line| -%> allow <%= line %> <% end -%> <% Array(@nodeconfig).each do |line| -%> <%= line %> <% end -%> diff --git a/templates/munin.conf.erb b/templates/munin.conf.erb index a0bab83..29f47de 100644 --- a/templates/munin.conf.erb +++ b/templates/munin.conf.erb @@ -1,31 +1,37 @@ # /etc/munin/munin.conf - Configuration file for the munin master # # This file is handled by puppet, all local modifications will be lost <% if @dbdir -%> dbdir <%= @dbdir %> <% end -%> <% if @htmldir -%> htmldir <%= @htmldir %> <% end -%> <% if @logdir -%> logdir <%= @logdir %> <% end -%> <% if @rundir -%> rundir <%= @rundir %> <% end -%> <% if @html_strategy -%> html_strategy <%= @html_strategy %> <% end -%> <% if @graph_strategy -%> graph_strategy <%= @graph_strategy %> <% end -%> <% if @tls == 'enabled' -%> tls = <%= @tls %> tls_certificate = <%= @tls_certificate %> tls_private_key = <%= @tls_private_key %> tls_verify_certificate = <%= @tls_verify_certificate %> <% end -%> +<% if @extra_config -%> + +<% @extra_config.each do |this| -%> +<%= this %> +<% end -%> +<% end -%> # Where to look for puppet generated munin master configuration. includedir /etc/munin/munin-conf.d