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