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