klammerfehler
[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: {       
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     include munin::plugin::paths
133
134         case $operatingsystem {
135                 centos: {               
136                     file {
137                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
138                                 source => "puppet://$servername/munin/empty",
139                                 ensure => directory, checksum => mtime,
140                                 recurse => true, purge => true, force => true, 
141                                 mode => 0755, owner => root, group => 0;
142                         "/etc/munin/plugin-conf.d/munin-node":
143                                 ensure => present, 
144                                 mode => 0644, owner => root, group => 0;
145                     }
146                 }
147
148                 default: {
149                     file {
150                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
151                                 source => "puppet://$servername/munin/empty",
152                                 ensure => directory, checksum => mtime,
153                                 recurse => true, purge => true, force => true, 
154                                 mode => 0755, owner => root, group => 0,
155                                 notify => Service["$munin_node_service"];
156                         "/etc/munin/plugin-conf.d/munin-node":
157                                 ensure => present, 
158                                 mode => 0644, owner => root, group => 0,
159                                 notify => Service[$munin_node_service];
160                     }
161                 }
162         }
163 }
164
165 # handle if_ and if_err_ plugins
166 class munin::plugins::interfaces inherits munin::plugins::base {
167
168         $ifs = gsub(split($interfaces, " "), "(.+)", "if_\\1")
169         $if_errs = gsub(split($interfaces, " "), "(.+)", "if_err_\\1")
170         plugin {
171                 $ifs: ensure => "if_";
172                 $if_errs: ensure => "if_err_";
173         }
174 }
175
176 class munin::plugins::linux inherits munin::plugins::base {
177
178         plugin {
179                 [ df_abs, forks, iostat, memory, processes, cpu, df_inode, irqstats,
180                   netstat, open_files, swap, df, entropy, interrupts, load, open_inodes,
181                   vmstat
182                 ]:
183                         ensure => present;
184                 acpi: 
185                         ensure => $acpi_available;
186         }
187
188         include munin::plugins::interfaces
189 }
190
191 class munin::plugins::debian inherits munin::plugins::base {
192
193         plugin { apt_all: ensure => present; }
194
195 }
196
197 class munin::plugins::vserver inherits munin::plugins::base {
198
199         plugin {
200                 [ netstat, processes ]:
201                         ensure => present;
202         }
203
204 }
205
206 class munin::plugins::gentoo inherits munin::plugins::base {
207     file { "$script_path/gentoo_lastupdated":
208             source => "puppet://$servername/munin/plugins/gentoo_lastupdated",
209             ensure => file,
210             mode => 0755, owner => root, group => 0;
211     }
212
213     plugin{"gentoo_lastupdated": ensure => present;}
214 }
215
216 class munin::plugins::centos inherits munin::plugins::base {
217 }
218
219 class munin::plugins::selinux inherits munin::plugins::base {
220     file { "$script_path/selinuxenforced":
221             source => "puppet://$servername/munin/plugins/selinuxenforced",
222             ensure => file,
223             mode => 0755, owner => root, group => 0;
224     }
225
226     plugin{"selinuxenforced": ensure => present;}
227 }
228
229 class munin::plugins::dom0 inherits munin::plugins::base {
230     file {
231         [ "$script_path/xen" ]:
232             source => "puppet://$servername/munin/plugins/xen",
233             ensure => file, 
234             mode => 0755, owner => root, group => 0;
235         [ "$script_path/xen-cpu" ]:
236             source => "puppet://$servername/munin/plugins/xen-cpu",
237             ensure => file,
238             mode => 0755, owner => root, group => 0;
239         [ "$script_path/xen_memory" ]:
240             source => "puppet://$servername/munin/plugins/xen_memory",
241             ensure => file,
242             mode => 0755, owner => root, group => 0;
243         [ "$script_path/xen_vbd" ]:
244             source => "puppet://$servername/munin/plugins/xen_vbd",
245             ensure => file,
246             mode => 0755, owner => root, group => 0;
247     }
248
249     plugin {
250         [ xen, xen-cpu, xen_memory, xen_vbd ]:
251             ensure => present;
252     }
253 }
254
255 class munin::plugins::domU inherits munin::plugins::base {
256     plugin { if_eth0: ensure => "if_" }
257 }
258
259 class munin::plugins::djbdns inherits munin::plugins::base {
260     file {
261         [ "$script_path/tinydns" ]:
262             source => "puppet://$servername/munin/plugins/tinydns",
263             ensure => file,
264             mode => 0755, owner => root, group => 0;
265     }
266     plugin {
267         [ tinydns ]:
268             ensure => present;
269     }
270 }
271
272 class munin::plugins::postgres inherits munin::plugins::base {
273     file {
274         [ "$script_path/pg_conn" ]:
275             source => "puppet://$servername/munin/plugins/pg_conn",
276             ensure => file, 
277             mode => 0755, owner => root, group => 0;
278         [ "$script_path/pg__connections" ]:
279             source => "puppet://$servername/munin/plugins/pg__connections",
280             ensure => file,
281             mode => 0755, owner => root, group => 0;
282         [ "$script_path/pg__locks" ]:
283             source => "puppet://$servername/munin/plugins/pg__locks",
284             ensure => file,
285             mode => 0755, owner => root, group => 0;
286     }
287 }