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