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