scheint einigermassen ne lösung zu sein ... ausser dem was er dann nicht macht ...
[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 => root,
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 => root;
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 => root;
127                         "/etc/munin/plugin-conf.d/munin-node":
128                                 ensure => present, 
129                                 mode => 0644, owner => root, group => root;
130                     }
131                         }
132                 default: {
133                     file {
134                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
135                                 source => "puppet://$servername/munin/empty",
136                                 ensure => directory, checksum => mtime,
137                                 recurse => true, purge => true, force => true, 
138                                 mode => 0755, owner => root, group => root,
139                                 notify => Service["$munin_node_service"];
140                         "/etc/munin/plugin-conf.d/munin-node":
141                                 ensure => present, 
142                                 mode => 0644, owner => root, group => root,
143                                 notify => Service[$munin_node_service];
144                     }
145                 }
146 }
147
148 # handle if_ and if_err_ plugins
149 class munin::plugins::interfaces inherits munin::plugins::base {
150
151         $ifs = gsub(split($interfaces, " "), "(.+)", "if_\\1")
152         $if_errs = gsub(split($interfaces, " "), "(.+)", "if_err_\\1")
153         plugin {
154                 $ifs: ensure => "if_";
155                 $if_errs: ensure => "if_err_";
156         }
157 }
158
159 class munin::plugins::linux inherits munin::plugins::base {
160
161         plugin {
162                 [ df_abs, forks, iostat, memory, processes, cpu, df_inode, irqstats,
163                   netstat, open_files, swap, df, entropy, interrupts, load, open_inodes,
164                   vmstat
165                 ]:
166                         ensure => present;
167                 acpi: 
168                         ensure => $acpi_available;
169         }
170
171         include munin::plugins::interfaces
172 }
173
174 class munin::plugins::debian inherits munin::plugins::base {
175
176         plugin { apt_all: ensure => present; }
177
178 }
179
180 class munin::plugins::vserver inherits munin::plugins::base {
181
182         plugin {
183                 [ netstat, processes ]:
184                         ensure => present;
185         }
186
187 }
188
189 class munin::plugins::gentoo inherits munin::plugins::base {
190 }
191
192 class munin::plugins::centos inherits munin::plugins::base {
193 }
194