, fehler
[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 = "/usr/share/munin/plugins",
8         $config = '')
9 {
10         case $operatingsystem {
11                 debian: {       
12                         $munin_node_service = "munin-node"; 
13                 }
14                 Gentoo: {       
15                         $munin_node_service = "munin",
16                         $script_path = "/usr/libexec/munin/plugins";
17                 }
18         }
19         $plugin_src = $ensure ? { "present" => $name, default => $ensure }
20         debug ( "munin_plugin: name=$name, ensure=$ensure, script_path=$script_path" )
21         $plugin = "/etc/munin/plugins/$name"
22         $plugin_conf = "/etc/munin/plugin-conf.d/$name.conf"
23         case $ensure {
24                 "absent": {
25                         debug ( "munin_plugin: suppressing $plugin" )
26                         file { $plugin: ensure => absent, } 
27                 }
28                 default: {
29                         #$plugin_src = $ensure ? { "present" => $name, default => $ensure }
30                         debug ( "munin_plugin: making $plugin using src: $plugin_src" )
31                         file { $plugin:
32                                 ensure => "$script_path/${plugin_src}",
33                                 require => Package[$munin_node_service],
34                                 notify => Service[$munin_node_service],
35                         }
36                 }
37         }
38         case $config {
39                 '': {
40                         debug("no config for $name")
41                         file { $plugin_conf: ensure => absent }
42                 }
43                 default: {
44                         case $ensure {
45                                 absent: {
46                                         debug("removing config for $name")
47                                         file { $plugin_conf: ensure => absent }
48                                 }
49                                 default: {
50                                         debug("creating $plugin_conf")
51                                         file { $plugin_conf:
52                                                 content => "[${name}]\n$config\n",
53                                                 mode => 0644, owner => root, group => root,
54                                         }
55                                 }
56                         }
57                 }
58         }
59 }
60
61 define munin::remoteplugin($ensure = "present", $source, $config = '') {
62         case $ensure {
63                 "absent": { munin::plugin{ $name: ensure => absent } }
64                 default: {
65                         file {
66                                 "/var/lib/puppet/modules/munin/plugins/${name}":
67                                         source => $source,
68                                         mode => 0755, owner => root, group => root;
69                         }
70                         munin::plugin { $name:
71                                 ensure => $ensure,
72                                 config => $config,
73                                 script_path => "/var/lib/puppet/modules/munin/plugins",
74                         }
75                 }
76         }
77 }
78
79 class munin::plugins::base {
80
81         case $operatingsystem {
82                 gentoo: {       $munin_node_service = "munin" }
83                 debian: {       $munin_node_service = "munin-node" }
84         }
85                 file {
86                         [ "/etc/munin/plugins", "/etc/munin/plugin-conf.d" ]:
87                                 source => "puppet://$servername/munin/empty",
88                                 ensure => directory, checksum => mtime,
89                                 recurse => true, purge => true, force => true, 
90                                 mode => 0755, owner => root, group => root,
91                                 notify => Service["$munin_node_service"];
92                         "/etc/munin/plugin-conf.d/munin-node":
93                                 ensure => present, 
94                                 mode => 0644, owner => root, group => root,
95                                 notify => Service[$munin_node_service];
96                 }
97 }
98
99 # handle if_ and if_err_ plugins
100 class munin::plugins::interfaces inherits munin::plugins::base {
101
102         $ifs = gsub(split($interfaces, " "), "(.+)", "if_\\1")
103         $if_errs = gsub(split($interfaces, " "), "(.+)", "if_err_\\1")
104         plugin {
105                 $ifs: ensure => "if_";
106                 $if_errs: ensure => "if_err_";
107         }
108 }
109
110 class munin::plugins::linux inherits munin::plugins::base {
111
112         plugin {
113                 [ df_abs, forks, iostat, memory, processes, cpu, df_inode, irqstats,
114                   netstat, open_files, swap, df, entropy, interrupts, load, open_inodes,
115                   vmstat
116                 ]:
117                         ensure => present;
118                 acpi: 
119                         ensure => $acpi_available;
120         }
121
122         include munin::plugins::interfaces
123 }
124
125 class munin::plugins::debian inherits munin::plugins::base {
126
127         plugin { apt_all: ensure => present; }
128
129 }
130
131 class munin::plugins::vserver inherits munin::plugins::base {
132
133         plugin {
134                 [ netstat, processes ]:
135                         ensure => present;
136         }
137
138 }
139
140 class munin::plugins::gentoo inherits munin::plugins::base {
141
142 }