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