munin script_path nur in plugins-gebraucht
[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/libexec/munin/plugins',
8         $config = '')
9 {
10         case $operatingsystem {
11                 debian: {       
12                         $munin_node_service = "munin-node" 
13                         $munin_node_package = "munin-node" 
14                 }
15                 centos: {       
16                         $munin_node_service = "munin-node" 
17                         $munin_node_package = "munin-node" 
18                 }
19                 gentoo: {       
20                         #$munin_node_service = "munin-node"
21                         $munin_node_service = "munin"
22                         $munin_node_package = "munin" 
23                 $script_path = $script_path_default,
24                 }
25                 default: {
26                         $munin_node_service = "munin-node"
27                         $munin_node_package = "munin-node" 
28                 }
29         }
30
31         $plugin_src = $ensure ? { "present" => $name, default => $ensure }
32         debug ( "munin_plugin: name=$name, ensure=$ensure, script_path=$script_path" )
33         $plugin = "/etc/munin/plugins/$name"
34         $plugin_conf = "/etc/munin/plugin-conf.d/$name.conf"
35         case $ensure {
36                 "absent": {
37                         debug ( "munin_plugin: suppressing $plugin" )
38                         file { $plugin: ensure => absent, } 
39                 }
40                 default: {
41                         debug ( "munin_plugin: making $plugin using src: $plugin_src" )
42                         case $operatingsystem {
43                                 centos: {       
44                                         file { $plugin:
45                                                 ensure => "$script_path/${plugin_src}",
46                                                 require => Package[$munin_node_package];
47                                         }
48                                 }
49                                 default: {
50                                         file { $plugin:
51                                                 ensure => "$script_path/${plugin_src}",
52                                                 require => Package[$munin_node_package],
53                                                 notify => Service[$munin_node_service];
54                                         }
55                                 }
56                         }
57                 }
58         }
59         case $config {
60                 '': {
61                         debug("no config for $name")
62                         file { $plugin_conf: ensure => absent }
63                 }
64                 default: {
65                         case $ensure {
66                                 absent: {
67                                         debug("removing config for $name")
68                                         file { $plugin_conf: ensure => absent }
69                                 }
70                                 default: {
71                                         debug("creating $plugin_conf")
72                                         file { $plugin_conf:
73                                                 content => "[${name}]\n$config\n",
74                                                 mode => 0644, owner => root, group => 0,
75                                         }
76                                 }
77                         }
78                 }
79         }
80 }
81
82 define munin::remoteplugin($ensure = "present", $source, $config = '') {
83         case $ensure {
84                 "absent": { munin::plugin{ $name: ensure => absent } }
85                 default: {
86                         file {
87                                 "/var/lib/puppet/modules/munin/plugins/${name}":
88                                         source => $source,
89                                         mode => 0755, owner => root, group => 0;
90                         }
91                         munin::plugin { $name:
92                                 ensure => $ensure,
93                                 config => $config,
94                                 script_path => "/var/lib/puppet/modules/munin/plugins",
95                         }
96                 }
97         }
98 }
99
100 class munin::plugins::base {
101
102         case $operatingsystem {
103                 gentoo: {       
104                         $munin_node_package = "munin" 
105                         $munin_node_service = "munin" 
106             $script_path_default =  "/usr/libexec/munin/plugins"
107                         }
108                 debian: {               
109                         $munin_node_service = "munin-node" 
110                         $munin_node_package = "munin-node" 
111             $script_path_default =  "/usr/libexec/munin/plugins"
112                         }
113                 centos: {               
114                         $munin_node_service = "munin-node" 
115                         $munin_node_package = "munin-node" 
116             $script_path_default =  "/usr/libexec/munin/plugins"
117                         }
118                 default: {
119                         $munin_node_service = "munin-node"
120                         $munin_node_package = "munin-node" 
121             $script_path_default =  "/usr/libexec/munin/plugins"
122                 }
123         }
124         case $operatingsystem {
125                 centos: {               
126                     file {
127                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
128                                 source => "puppet://$servername/munin/empty",
129                                 ensure => directory, checksum => mtime,
130                                 recurse => true, purge => true, force => true, 
131                                 mode => 0755, owner => root, group => 0;
132                         "/etc/munin/plugin-conf.d/munin-node":
133                                 ensure => present, 
134                                 mode => 0644, owner => root, group => 0;
135                     }
136                 }
137
138                 default: {
139                     file {
140                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
141                                 source => "puppet://$servername/munin/empty",
142                                 ensure => directory, checksum => mtime,
143                                 recurse => true, purge => true, force => true, 
144                                 mode => 0755, owner => root, group => 0,
145                                 notify => Service["$munin_node_service"];
146                         "/etc/munin/plugin-conf.d/munin-node":
147                                 ensure => present, 
148                                 mode => 0644, owner => root, group => 0,
149                                 notify => Service[$munin_node_service];
150                     }
151                 }
152         }
153 }
154
155 # handle if_ and if_err_ plugins
156 class munin::plugins::interfaces inherits munin::plugins::base {
157
158         $ifs = gsub(split($interfaces, " "), "(.+)", "if_\\1")
159         $if_errs = gsub(split($interfaces, " "), "(.+)", "if_err_\\1")
160         plugin {
161                 $ifs: ensure => "if_";
162                 $if_errs: ensure => "if_err_";
163         }
164 }
165
166 class munin::plugins::linux inherits munin::plugins::base {
167
168         plugin {
169                 [ df_abs, forks, iostat, memory, processes, cpu, df_inode, irqstats,
170                   netstat, open_files, swap, df, entropy, interrupts, load, open_inodes,
171                   vmstat
172                 ]:
173                         ensure => present;
174                 acpi: 
175                         ensure => $acpi_available;
176         }
177
178         include munin::plugins::interfaces
179 }
180
181 class munin::plugins::debian inherits munin::plugins::base {
182
183         plugin { apt_all: ensure => present; }
184
185 }
186
187 class munin::plugins::vserver inherits munin::plugins::base {
188
189         plugin {
190                 [ netstat, processes ]:
191                         ensure => present;
192         }
193
194 }
195
196 class munin::plugins::gentoo inherits munin::plugins::base {
197     file { "$script_path_default/gentoo_lastupdated":
198             source => "puppet://$servername/munin/plugins/gentoo_lastupdated",
199             ensure => file,
200             mode => 0755, owner => root, group => 0;
201     }
202
203     plugin{"gentoo_lastupdated": ensure => present;}
204 }
205
206 class munin::plugins::centos inherits munin::plugins::base {
207 }
208
209 class munin::plugins::selinux inherits munin::plugins::base {
210     file { "$script_path_default/selinuxenforced":
211             source => "puppet://$servername/munin/plugins/selinuxenforced",
212             ensure => file,
213             mode => 0755, owner => root, group => 0;
214     }
215
216     plugin{"selinuxenforced": ensure => present;}
217 }
218
219 class munin::plugins::dom0 inherits munin::plugins::base {
220     file {
221         [ "$script_path_default/xen" ]:
222             source => "puppet://$servername/munin/plugins/xen",
223             ensure => file, 
224             mode => 0755, owner => root, group => 0;
225         [ "$script_path_default/xen-cpu" ]:
226             source => "puppet://$servername/munin/plugins/xen-cpu",
227             ensure => file,
228             mode => 0755, owner => root, group => 0;
229         [ "$script_path_default/xen_memory" ]:
230             source => "puppet://$servername/munin/plugins/xen_memory",
231             ensure => file,
232             mode => 0755, owner => root, group => 0;
233         [ "$script_path_default/xen_vbd" ]:
234             source => "puppet://$servername/munin/plugins/xen_vbd",
235             ensure => file,
236             mode => 0755, owner => root, group => 0;
237     }
238
239     plugin {
240         [ xen, xen-cpu, xen_memory, xen_vbd ]:
241             ensure => present;
242     }
243 }
244
245 class munin::plugins::domU inherits munin::plugins::base {
246     plugin { if_eth0: ensure => "if_" }
247 }
248
249 class munin::plugins::djbdns inherits munin::plugins::base {
250     file {
251         [ "$script_path_default/tinydns" ]:
252             source => "puppet://$servername/munin/plugins/tinydns",
253             ensure => file,
254             mode => 0755, owner => root, group => 0;
255     }
256     plugin {
257         [ tinydns ]:
258             ensure => present;
259     }
260 }
261
262 class munin::plugins::postgres inherits munin::plugins::base {
263     file {
264         [ "$script_path_default/pg_conn" ]:
265             source => "puppet://$servername/munin/plugins/pg_conn",
266             ensure => file, 
267             mode => 0755, owner => root, group => 0;
268         [ "$script_path_default/pg__connections" ]:
269             source => "puppet://$servername/munin/plugins/pg__connections",
270             ensure => file,
271             mode => 0755, owner => root, group => 0;
272         [ "$script_path_default/pg__locks" ]:
273             source => "puppet://$servername/munin/plugins/pg__locks",
274             ensure => file,
275             mode => 0755, owner => root, group => 0;
276     }
277 }