munin-node only on debian/etc...
[puppet_munin.git] / manifests / plugin.pp
1 # plugin.pp - configure a specific munin plugin
2 # Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
3 # See LICENSE for the full license granted to you.
4
5 define munin::plugin (
6         $ensure = "present",
7         $script_path = "/usr/share/munin/plugins",
8         $config = '')
9 {
10         debug ( "munin_plugin: name=$name, ensure=$ensure, script_path=$script_path" )
11         $plugin = "/etc/munin/plugins/$name"
12         $plugin_conf = "/etc/munin/plugin-conf.d/$name.conf"
13         case $ensure {
14                 "absent": {
15                         debug ( "munin_plugin: suppressing $plugin" )
16                         file { $plugin: ensure => absent, } 
17                 }
18                 default: {
19                         case $operatingsystem {
20                                 debian: {       
21                                         $plugin_src = $ensure ? { "present" => $name, default => $ensure }
22                                         debug ( "munin_plugin: making $plugin using src: $plugin_src" )
23                                         file { $plugin:
24                                                 ensure => "$script_path/${plugin_src}",
25                                                 require => Package["munin-node"],
26                                                 notify => Service["munin-node"],
27                                 }
28                                 }
29                         }
30                 }
31         }
32         case $config {
33                 '': {
34                         debug("no config for $name")
35                         file { $plugin_conf: ensure => absent }
36                 }
37                 default: {
38                         case $ensure {
39                                 absent: {
40                                         debug("removing config for $name")
41                                         file { $plugin_conf: ensure => absent }
42                                 }
43                                 default: {
44                                         debug("creating $plugin_conf")
45                                         file { $plugin_conf:
46                                                 content => "[${name}]\n$config\n",
47                                                 mode => 0644, owner => root, group => root,
48                                         }
49                                 }
50                         }
51                 }
52         }
53 }
54
55 define munin::remoteplugin($ensure = "present", $source, $config = '') {
56         case $ensure {
57                 "absent": { munin::plugin{ $name: ensure => absent } }
58                 default: {
59                         file {
60                                 "/var/lib/puppet/modules/munin/plugins/${name}":
61                                         source => $source,
62                                         mode => 0755, owner => root, group => root;
63                         }
64                         munin::plugin { $name:
65                                 ensure => $ensure,
66                                 config => $config,
67                                 script_path => "/var/lib/puppet/modules/munin/plugins",
68                         }
69                 }
70         }
71 }
72
73 class munin::plugins::base {
74
75         file {
76                 [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
77                         source => "puppet://$servername/munin/empty",
78                         ensure => directory, checksum => mtime,
79                         recurse => true, purge => true, force => true, 
80                         mode => 0755, owner => root, group => root,
81                         notify => Service[munin-node];
82                 "/etc/munin/plugin-conf.d/munin-node":
83                         ensure => present, 
84                         mode => 0644, owner => root, group => root,
85                         notify => Service[munin-node];
86         }
87
88 }
89
90 # handle if_ and if_err_ plugins
91 class munin::plugins::interfaces inherits munin::plugins::base {
92
93         $ifs = gsub(split($interfaces, " "), "(.+)", "if_\\1")
94         $if_errs = gsub(split($interfaces, " "), "(.+)", "if_err_\\1")
95         plugin {
96                 $ifs: ensure => "if_";
97                 $if_errs: ensure => "if_err_";
98         }
99
100
101 }
102
103 class munin::plugins::linux inherits munin::plugins::base {
104
105         plugin {
106                 [ df_abs, forks, iostat, memory, processes, cpu, df_inode, irqstats,
107                   netstat, open_files, swap, df, entropy, interrupts, load, open_inodes,
108                   vmstat
109                 ]:
110                         ensure => present;
111                 acpi: 
112                         ensure => $acpi_available;
113         }
114
115         include munin::plugins::interfaces
116 }
117
118 class munin::plugins::debian inherits munin::plugins::base {
119
120         plugin { apt_all: ensure => present; }
121
122 }
123
124 class munin::plugins::vserver inherits munin::plugins::base {
125
126         plugin {
127                 [ netstat, processes ]:
128                         ensure => present;
129         }
130
131 }
132
133 class munin::plugins::gentoo inherits munin::plugins::base {
134
135 }