summaryrefslogtreecommitdiff
path: root/manifests/plugin.pp
blob: 60af877475d73a5f4d2ebb938b35a323aae9b7d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# configure a specific munin plugin
define munin::plugin (
  $ensure         = 'present',
  $script_path_in = '',
  $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"

  include munin::plugins::setup
  case $ensure {
    'absent': {
      file { $plugin: ensure => absent, }
    }
    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[$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',
          }
        }
      }
    }
  }
}