pfad nicht richtig def
[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::scriptpaths {
6         case $operatingsystem {
7                 gentoo: {       
8             $script_path =  "/usr/libexec/munin/plugins"
9                         }
10                 debian: {               
11             $script_path =  "/usr/share/munin/plugins"
12                         }
13                 centos: {               
14             $script_path =  "/usr/share/munin/plugins"
15                         }
16                 default: {
17             $script_path =  "/usr/share/munin/plugins"
18                 }
19         }
20 }
21
22
23 define munin::plugin (
24         $ensure = "present",
25         $script_path_in = '',
26         $config = '')
27 {
28
29     include munin::plugin::scriptpaths
30         #$script_path = $script_path_in ? { '' => $script_path, default => $script_path_in }
31
32         $plugin_src = $ensure ? { "present" => $name, default => $ensure }
33         debug ( "munin_plugin: name=$name, ensure=$ensure, script_path=$script_path" )
34         $plugin = "/etc/munin/plugins/$name"
35         $plugin_conf = "/etc/munin/plugin-conf.d/$name.conf"
36         case $ensure {
37                 "absent": {
38                         debug ( "munin_plugin: suppressing $plugin" )
39                         file { $plugin: ensure => absent, } 
40                 }
41                 default: {
42                         debug ( "munin_plugin: making $plugin using src: $plugin_src" )
43                         case $operatingsystem {
44                                 centos, gentoo: {       
45                                         file { $plugin:
46                                                 ensure => "$script_path/${plugin_src}",
47                                                 require => Package['munin-node'];
48                                         }
49                                 }
50                                 default: {
51                                         file { $plugin:
52                                                 ensure => "$script_path/${plugin_src}",
53                                                 require => Package['munin-node'],
54                                                 notify => Service['munin-node'];
55                                         }
56                                 }
57                         }
58                 }
59         }
60         case $config {
61                 '': {
62                         debug("no config for $name")
63                         file { $plugin_conf: ensure => absent }
64                 }
65                 default: {
66                         case $ensure {
67                                 absent: {
68                                         debug("removing config for $name")
69                                         file { $plugin_conf: ensure => absent }
70                                 }
71                                 default: {
72                                         debug("creating $plugin_conf")
73                                         file { $plugin_conf:
74                                                 content => "[${name}]\n$config\n",
75                                                 mode => 0644, owner => root, group => 0,
76                                         }
77                                 }
78                         }
79                 }
80         }
81 }
82
83 define munin::remoteplugin($ensure = "present", $source, $config = '') {
84         case $ensure {
85                 "absent": { munin::plugin{ $name: ensure => absent } }
86                 default: {
87                         file {
88                                 "/var/lib/puppet/modules/munin/plugins/${name}":
89                                         source => $source,
90                                         mode => 0755, owner => root, group => 0;
91                         }
92                         munin::plugin { $name:
93                                 ensure => $ensure,
94                                 config => $config,
95                                 script_path => "/var/lib/puppet/modules/munin/plugins",
96                         }
97                 }
98         }
99 }
100
101 class munin::plugins::base {
102     include munin::plugin::scriptpaths
103
104         case $operatingsystem {
105                 centos: {               
106                     file {
107                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
108                                 source => "puppet://$servername/munin/empty",
109                                 ensure => directory, checksum => mtime,
110                                 recurse => true, purge => true, force => true, 
111                                 mode => 0755, owner => root, group => 0;
112                         "/etc/munin/plugin-conf.d/munin-node":
113                                 ensure => present, 
114                                 mode => 0644, owner => root, group => 0;
115                     }
116                 }
117
118                 default: {
119                     file {
120                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
121                                 source => "puppet://$servername/munin/empty",
122                                 ensure => directory, checksum => mtime,
123                                 recurse => true, purge => true, force => true, 
124                                 mode => 0755, owner => root, group => 0,
125                                 notify => Service['munin-node'];
126                         "/etc/munin/plugin-conf.d/munin-node":
127                                 ensure => present, 
128                                 mode => 0644, owner => root, group => 0,
129                                 notify => Service['munin-node'],
130                 before => Package['munin-node'];
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 }