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