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