summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifests/plugin.pp74
-rw-r--r--manifests/plugin/scriptpaths.pp5
-rw-r--r--spec/defines/munin_plugin_spec.rb40
3 files changed, 72 insertions, 47 deletions
diff --git a/manifests/plugin.pp b/manifests/plugin.pp
index 60af877..ef82f90 100644
--- a/manifests/plugin.pp
+++ b/manifests/plugin.pp
@@ -1,55 +1,43 @@
# configure a specific munin plugin
+#
+# We only manage the plugin if it is not set to absent.
+# A plugin (or its config) that should be removed should
+# be purged by the recursively managed plugins- or
+# config-directory. So we can safe a few resources being
+# managed.
define munin::plugin (
$ensure = 'present',
$script_path_in = '',
- $config = ''
+ $config = '',
) {
- include munin::plugin::scriptpaths
- $real_script_path = $script_path_in ? { '' => $munin::plugin::scriptpaths::script_path, default => $script_path_in }
-
- $plugin_src = $ensure ? { 'present' => $name, default => $ensure }
- $plugin = "/etc/munin/plugins/${name}"
- $plugin_conf = "/etc/munin/plugin-conf.d/${name}.conf"
+ if $ensure != 'absent' {
+ include munin::plugin::scriptpaths
+ include munin::plugins::setup
+ $real_script_path = $script_path_in ? {
+ '' => $munin::plugin::scriptpaths::script_path,
+ default => $script_path_in
+ }
+ $plugin_src = $ensure ? {
+ 'present' => $name,
+ default => $ensure
+ }
- include munin::plugins::setup
- case $ensure {
- 'absent': {
- file { $plugin: ensure => absent, }
+ file { "/etc/munin/plugins/${name}":
+ ensure => link,
+ target =>"${real_script_path}/${plugin_src}",
+ notify => Service['munin-node'];
}
- default: {
- $dep = $::kernel ? {
- OpenBSD => File['/var/run/munin'],
- default => Package['munin-node']
- }
- file { $plugin:
- ensure => "${real_script_path}/${plugin_src}",
- require => $dep,
- notify => Service['munin-node'];
+ if (str2bool($::selinux) == true) and (($::operatingsystem != 'CentOS') or ($::operatingsystem == 'CentOS' and $::lsbmajdistrelease != '5')){
+ File["/etc/munin/plugins/${name}"]{
+ seltype => 'munin_etc_t',
}
- if (str2bool($::selinux) == true) and (($::operatingsystem != 'CentOS') or ($::operatingsystem == 'CentOS' and $::lsbmajdistrelease != '5')){
- File[$plugin]{
- seltype => 'munin_etc_t',
- }
- }
- }
- }
- case $config {
- '': {
- file { $plugin_conf: ensure => absent }
}
- default: {
- case $ensure {
- absent: {
- file { $plugin_conf: ensure => absent }
- }
- default: {
- file { $plugin_conf:
- content => "[${name}]\n${config}\n",
- owner => root,
- group => 0,
- mode => '0640',
- }
- }
+ if $config != '' {
+ file { "/etc/munin/plugin-conf.d/${name}.conf":
+ content => "[${name}]\n${config}\n",
+ owner => root,
+ group => 0,
+ mode => '0640',
}
}
}
diff --git a/manifests/plugin/scriptpaths.pp b/manifests/plugin/scriptpaths.pp
index f31f38d..62dd77b 100644
--- a/manifests/plugin/scriptpaths.pp
+++ b/manifests/plugin/scriptpaths.pp
@@ -4,10 +4,7 @@ class munin::plugin::scriptpaths {
gentoo: { $script_path = '/usr/libexec/munin/plugins' }
debian: { $script_path = '/usr/share/munin/plugins' }
centos: { $script_path = '/usr/share/munin/plugins' }
- openbsd: { $script_path = $::operatingsystemrelease ? {
- '4.3' => '/opt/munin/lib/plugins/',
- default => '/usr/local/libexec/munin/plugins/',
- } }
+ openbsd: { $script_path = '/usr/local/libexec/munin/plugins/' }
default: { $script_path = '/usr/share/munin/plugins' }
}
}
diff --git a/spec/defines/munin_plugin_spec.rb b/spec/defines/munin_plugin_spec.rb
new file mode 100644
index 0000000..3d7e9e3
--- /dev/null
+++ b/spec/defines/munin_plugin_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe 'munin::plugin' do
+ let(:title) { 'users' }
+ let(:facts) do
+ { :operatingsystem => 'CentOS' }
+ end
+ context 'present' do
+ it { should contain_file('/etc/munin/plugins/users').with(
+ :ensure => 'link',
+ :target => '/usr/share/munin/plugins/users'
+ ) }
+ it { should_not contain_file('/etc/munin/plugin-conf.d/users.conf') }
+ end
+
+ context 'present and config' do
+ let(:params) do
+ { :config => 'env.user root' }
+ end
+ it { should contain_file('/etc/munin/plugins/users').with(
+ :ensure => 'link',
+ :target => '/usr/share/munin/plugins/users',
+ :notify => 'Service[munin-node]'
+ ) }
+ it { should contain_file('/etc/munin/plugin-conf.d/users.conf').with(
+ :content => "[users]\nenv.user root\n",
+ :owner => 'root',
+ :group => 0,
+ :mode => '0640'
+ ) }
+ end
+
+ context 'absent' do
+ let(:params) do
+ { :ensure => 'absent' }
+ end
+ it { should_not contain_file('/etc/munin/plugins/users') }
+ it { should_not contain_file('/etc/munin/plugin-conf.d/users.conf') }
+ end
+end