removed unneeded definition
[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-node" 
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         case $operatingsystem {
106                 centos: {               
107                     file {
108                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
109                                 source => "puppet://$servername/munin/empty",
110                                 ensure => directory, checksum => mtime,
111                                 recurse => true, purge => true, force => true, 
112                                 mode => 0755, owner => root, group => 0;
113                         "/etc/munin/plugin-conf.d/munin-node":
114                                 ensure => present, 
115                                 mode => 0644, owner => root, group => 0;
116                     }
117                 }
118
119                 default: {
120                     file {
121                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
122                                 source => "puppet://$servername/munin/empty",
123                                 ensure => directory, checksum => mtime,
124                                 recurse => true, purge => true, force => true, 
125                                 mode => 0755, owner => root, group => 0,
126                                 notify => Service["$munin_node_service"];
127                         "/etc/munin/plugin-conf.d/munin-node":
128                                 ensure => present, 
129                                 mode => 0644, owner => root, group => 0,
130                                 notify => Service[$munin_node_service];
131                     }
132                 }
133         }
134 }
135
136 # handle if_ and if_err_ plugins
137 class munin::plugins::interfaces inherits munin::plugins::base {
138
139         $ifs = gsub(split($interfaces, " "), "(.+)", "if_\\1")
140         $if_errs = gsub(split($interfaces, " "), "(.+)", "if_err_\\1")
141         plugin {
142                 $ifs: ensure => "if_";
143                 $if_errs: ensure => "if_err_";
144         }
145 }
146
147 class munin::plugins::linux inherits munin::plugins::base {
148
149         plugin {
150                 [ df_abs, forks, iostat, memory, processes, cpu, df_inode, irqstats,
151                   netstat, open_files, swap, df, entropy, interrupts, load, open_inodes,
152                   vmstat
153                 ]:
154                         ensure => present;
155                 acpi: 
156                         ensure => $acpi_available;
157         }
158
159         include munin::plugins::interfaces
160 }
161
162 class munin::plugins::debian inherits munin::plugins::base {
163
164         plugin { apt_all: ensure => present; }
165
166 }
167
168 class munin::plugins::vserver inherits munin::plugins::base {
169
170         plugin {
171                 [ netstat, processes ]:
172                         ensure => present;
173         }
174
175 }
176
177 class munin::plugins::gentoo inherits munin::plugins::base {
178     file { "$script_path/gentoo_lastupdated":
179             source => "puppet://$servername/munin/plugins/gentoo_lastupdated",
180             ensure => file,
181             mode => 0755, owner => root, group => 0;
182     }
183
184     plugin{"gentoo_lastupdated": ensure => present;}
185 }
186
187 class munin::plugins::centos inherits munin::plugins::base {
188 }
189
190 class munin::plugins::selinux inherits munin::plugins::base {
191     file { "$script_path/selinuxenforced":
192             source => "puppet://$servername/munin/plugins/selinuxenforced",
193             ensure => file,
194             mode => 0755, owner => root, group => 0;
195     }
196
197     plugin{"selinuxenforced": ensure => present;}
198 }
199
200 class munin::plugins::dom0 inherits munin::plugins::base {
201     file {
202         [ "$script_path/xen" ]:
203             source => "puppet://$servername/munin/plugins/xen",
204             ensure => file, 
205             mode => 0755, owner => root, group => 0;
206         [ "$script_path/xen-cpu" ]:
207             source => "puppet://$servername/munin/plugins/xen-cpu",
208             ensure => file,
209             mode => 0755, owner => root, group => 0;
210         [ "$script_path/xen_memory" ]:
211             source => "puppet://$servername/munin/plugins/xen_memory",
212             ensure => file,
213             mode => 0755, owner => root, group => 0;
214         [ "$script_path/xen_vbd" ]:
215             source => "puppet://$servername/munin/plugins/xen_vbd",
216             ensure => file,
217             mode => 0755, owner => root, group => 0;
218     }
219
220     plugin {
221         [ xen, xen-cpu, xen_memory, xen_vbd ]:
222             ensure => present;
223     }
224 }
225
226 class munin::plugins::domU inherits munin::plugins::base {
227     plugin { if_eth0: ensure => "if_" }
228 }
229
230 class munin::plugins::djbdns inherits munin::plugins::base {
231     file {
232         [ "$script_path/tinydns" ]:
233             source => "puppet://$servername/munin/plugins/tinydns",
234             ensure => file,
235             mode => 0755, owner => root, group => 0;
236     }
237     plugin {
238         [ tinydns ]:
239             ensure => present;
240     }
241 }
242
243 class munin::plugins::postgres inherits munin::plugins::base {
244     file {
245         [ "$script_path/pg_conn" ]:
246             source => "puppet://$servername/munin/plugins/pg_conn",
247             ensure => file, 
248             mode => 0755, owner => root, group => 0;
249         [ "$script_path/pg__connections" ]:
250             source => "puppet://$servername/munin/plugins/pg__connections",
251             ensure => file,
252             mode => 0755, owner => root, group => 0;
253         [ "$script_path/pg__locks" ]:
254             source => "puppet://$servername/munin/plugins/pg__locks",
255             ensure => file,
256             mode => 0755, owner => root, group => 0;
257     }
258 }