rearranged some munin stuff
[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         $real_script_path = $script_path_in ? { '' => $munin::plugin::scriptpaths::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=$munin::plugin::scriptpaths::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 => "${real_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_in => "/var/lib/puppet/modules/munin/plugins",
86                         }
87                 }
88         }
89 }
90
91 class munin::plugins::base {
92         case $operatingsystem {
93                 centos: {               
94                     file {
95                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
96                                 source => "puppet://$servername/munin/empty",
97                                 ensure => directory, checksum => mtime,
98                                 recurse => true, purge => true, force => true, 
99                                 mode => 0755, owner => root, group => 0;
100                         "/etc/munin/plugin-conf.d/munin-node":
101                                 ensure => present, 
102                                 mode => 0644, owner => root, group => 0;
103                     }
104                 }
105
106                 default: {
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                                 notify => Service['munin-node'];
114                         "/etc/munin/plugin-conf.d/munin-node":
115                                 ensure => present, 
116                                 mode => 0644, owner => root, group => 0,
117                                 notify => Service['munin-node'],
118                 before => Package['munin-node'];
119                     }
120                 }
121         }
122 }
123
124 # handle if_ and if_err_ plugins
125 class munin::plugins::interfaces inherits munin::plugins::base {
126
127         $ifs = gsub(split($interfaces, " "), "(.+)", "if_\\1")
128         $if_errs = gsub(split($interfaces, " "), "(.+)", "if_err_\\1")
129         plugin {
130                 $ifs: ensure => "if_";
131                 $if_errs: ensure => "if_err_";
132         }
133 }
134
135 class munin::plugins::linux inherits munin::plugins::base {
136
137         plugin {
138                 [ df_abs, forks, memory, processes, cpu, df_inode, irqstats,
139                   netstat, open_files, swap, df, entropy, interrupts, load, open_inodes,
140                   vmstat
141                 ]:
142                         ensure => present;
143                 acpi: 
144                         ensure => $acpi_available;
145         }
146
147         include munin::plugins::interfaces
148 }
149
150 class munin::plugins::debian inherits munin::plugins::base {
151
152         plugin { apt_all: ensure => present; }
153
154 }
155
156 class munin::plugins::vserver inherits munin::plugins::base {
157
158         plugin {
159                 [ netstat, processes ]:
160                         ensure => present;
161         }
162
163 }
164
165 class munin::plugins::gentoo inherits munin::plugins::base {
166     munin::plugin::deploy { "gentoo_lastupdated": }
167 }
168
169 class munin::plugins::centos inherits munin::plugins::base {
170 }
171
172 define munin::plugin::deploy ($source = '', $enabled = 'true') {
173     $real_source = $source ? {
174         ''  =>  "munin/plugins/$name",
175         default => $source
176     }
177     include munin::plugin::scriptpaths
178         debug ( "munin_plugin_${name}: name=$name, source=$source, script_path=$munin::plugin::scriptpaths::script_path" )
179     file { "munin_plugin_${name}":
180             path => "$munin::plugin::scriptpaths::script_path/${name}",
181             source => "puppet://$servername/$real_source",
182             ensure => file,
183             mode => 0755, owner => root, group => 0;
184     }
185
186     if $enabled {
187         plugin{$name: ensure => present }
188     }
189 }
190
191 class munin::plugins::dom0 inherits munin::plugins::physical {
192     munin::plugin::deploy { "xen": }
193     munin::plugin::deploy { "xen-cpu": }
194     munin::plugin::deploy { "xen_memory": }
195     munin::plugin::deploy { "xen_vbd": }
196 }
197
198 class munin::plugins::physical inherits munin::plugins::base {
199      munin::plugin { iostat: }
200 }
201
202 class munin::plugins::domU inherits munin::plugins::base {
203     plugin { if_eth0: ensure => "if_" }
204 }
205
206 class munin::plugins::djbdns inherits munin::plugins::base {
207     munin::plugin::deploy { "tinydns": }
208 }
209
210 class munin::plugins::postgres inherits munin::plugins::base {
211     munin::plugin::deploy { "pg_conn": }
212     munin::plugin::deploy { "pg__connections": enabled => false }
213     munin::plugin::deploy { "pg__locks": enabled => false }
214 }