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