diff --git a/manifests/node.pp b/manifests/node.pp index 512c2ac..ac1f4a6 100644 --- a/manifests/node.pp +++ b/manifests/node.pp @@ -1,114 +1,115 @@ # 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. # # 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. # # 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, } } # Generate plugin resources from hiera or class parameter. create_resources(munin::plugin, $plugins, {}) } 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/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/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 -%>