diff --git a/manifests/master.pp b/manifests/master.pp index 3eec9bc..dceadc8 100644 --- a/manifests/master.pp +++ b/manifests/master.pp @@ -1,91 +1,95 @@ # 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. # # - 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. 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, ) 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_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) } # 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 == '' |>> } # Create static node definitions if $node_definitions { create_resources(munin::master::node_definition, $node_definitions, {}) } } diff --git a/manifests/params/master.pp b/manifests/params/master.pp index da153b4..69724f2 100644 --- a/manifests/params/master.pp +++ b/manifests/params/master.pp @@ -1,25 +1,29 @@ 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' case $::osfamily { 'Debian', 'RedHat': { $config_root = '/etc/munin' } 'Solaris': { $config_root = '/opt/local/etc/munin' } default: { fail($message) } } } diff --git a/spec/classes/munin_master_spec.rb b/spec/classes/munin_master_spec.rb index 8cf6340..a7c2069 100644 --- a/spec/classes/munin_master_spec.rb +++ b/spec/classes/munin_master_spec.rb @@ -1,77 +1,109 @@ 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 end diff --git a/templates/munin.conf.erb b/templates/munin.conf.erb index 54a22a5..a0bab83 100644 --- a/templates/munin.conf.erb +++ b/templates/munin.conf.erb @@ -1,19 +1,31 @@ # /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 -%> # Where to look for puppet generated munin master configuration. includedir /etc/munin/munin-conf.d