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