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