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