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