summaryrefslogtreecommitdiff
path: root/manifests/plugin.pp
blob: 8d739a82dd254f3910dd802c5772b524daf84ea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# plugin.pp - configure a specific munin plugin
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
# adapted and improved by admin(at)immerda.ch


### configpaths

class munin::plugin::scriptpaths {
    case $operatingsystem {
    	gentoo: { $script_path =  "/usr/libexec/munin/plugins" }
    	debian: { $script_path =  "/usr/share/munin/plugins" }
    	centos: { $script_path =  "/usr/share/munin/plugins" }
    	openbsd: { $script_path =  "/opt/munin/lib/plugins/" }
    	default: { $script_path =  "/usr/share/munin/plugins" }
    }
}

### defines

define munin::plugin (
    $ensure = "present",
    $script_path_in = '',
    $config = '')
{

    include munin::plugin::scriptpaths
    $real_script_path = $script_path_in ? { '' => $munin::plugin::scriptpaths::script_path, default => $script_path_in }

    $plugin_src = $ensure ? { "present" => $name, default => $ensure }
    $plugin = "/etc/munin/plugins/$name"
    $plugin_conf = "/etc/munin/plugin-conf.d/$name.conf"
    case $ensure {
    	"absent": {
    		file { $plugin: ensure => absent, }
    	}
    	default: {
            case $kernel {
                openbsd: { $basic_require = File['/var/run/munin'] }
                default: { $basic_require = Package['munin-node'] }
            }
            if $require {
                $real_require = [ $require, $basic_require ]
            } else {
                $real_require = $basic_require
            }
    		file { $plugin:
    		    ensure => "${real_script_path}/${plugin_src}",
    			require => $real_require,
    			notify => Service['munin-node'];
    		}

    	}
    }
    case $config {
    	'': {
    		file { $plugin_conf: ensure => absent }
    	}
    	default: {
    		case $ensure {
    			absent: {
    				file { $plugin_conf: ensure => absent }
    			}
    			default: {
    				file { $plugin_conf:
    					content => "[${name}]\n$config\n",
    					mode => 0644, owner => root, group => 0,
    				}
                    if $require {
                        File[$plugin_conf]{
                            require +> $require,
                        }
                    }
    			}
    		}
    	}
    }
}

define munin::remoteplugin($ensure = "present", $source, $config = '') {
    case $ensure {
    	"absent": { munin::plugin{ $name: ensure => absent } }
    	default: {
    		file {
    			"/var/lib/puppet/modules/munin/plugins/${name}":
    				source => $source,
    				mode => 0755, owner => root, group => 0;
    		}
    		munin::plugin { $name:
    			ensure => $ensure,
    			config => $config,
    			script_path_in => "/var/lib/puppet/modules/munin/plugins",
    		}
    	}
    }
}
define munin::plugin::deploy ($source = '', $ensure = 'present', $config = '') {
    $plugin_src = $ensure ? {
        'present' => $name,
        'absent' => $name,
        default => $ensure
    }
    $real_source = $source ? {
        ''  =>  "munin/plugins/$plugin_src",
        default => $source
    }
    include munin::plugin::scriptpaths
    file { "munin_plugin_${name}":
            path => "$munin::plugin::scriptpaths::script_path/${name}",
            source => "puppet://$server/$real_source",
            mode => 0755, owner => root, group => 0;
    }

    case $kernel {
        openbsd: { $basic_require = File['/var/run/munin'] }
        default: { $basic_require = Package['munin-node'] }
    }
    if $require {
        File["munin_plugin_${name}"]{
            require => [ $basic_require, $require ],
        }
    } else {
        File["munin_plugin_${name}"]{
            require => $basic_require,
        }
    }
    # register the plugin
    if $require {
        munin::plugin{$name: ensure => $ensure, config => $config, require => $require }
    } else {
        munin::plugin{$name: ensure => $ensure, config => $config }
    }
}

### clases for plugins

class munin::plugins::base {
    file {
        [ '/etc/munin/plugins', '/etc/munin/plugin-conf.d' ]:
            source => "puppet://$server/common/empty",
            ignore => [ '\.ignore', 'snmp_*' ],
            ensure => directory, checksum => mtime,
            recurse => true, purge => true, force => true,
            mode => 0755, owner => root, group => 0,
            notify => Service['munin-node'];
        '/etc/munin/plugin-conf.d/munin-node':
            ensure => present,
            mode => 0644, owner => root, group => 0,
            notify => Service['munin-node'],
    }

    munin::plugin {
        [ df, cpu, interrupts, load, memory, netstat, open_files,
            processes, swap, uptime, users, vmstat
        ]:
            ensure => present,
    }
    include munin::plugins::interfaces

    case $kernel {
        openbsd: {
            File['/etc/munin/plugin-conf.d/munin-node']{
                before => File['/var/run/munin'],
            }
        }
        default: {
            File['/etc/munin/plugin-conf.d/munin-node']{
                before => Package['munin-node'],
            }
        }
    }
    case $kernel {
        linux: {
            case $vserver {
                guest: { include munin::plugins::vserver }
                default: {
                    include munin::plugins::linux
                }
            }
        }
    }
    case $virtual {
        physical: { include munin::plugins::physical }
        xen0: { include munin::plugins::dom0 }
        xenu: { include munin::plugins::domU }
    }
}

# handle if_ and if_err_ plugins
class munin::plugins::interfaces inherits munin::plugins::base {

    $ifs = gsub(split($interfaces, " |,"), "(.+)", "if_\\1")
    munin::plugin {
    $ifs: ensure => "if_";
    }
    case $operatingsystem {
        openbsd: {
            $if_errs = gsub(split($interfaces, " |,"), "(.+)", "if_errcoll_\\1")
    	      munin::plugin{
            $if_errs: ensure => "if_errcoll_";
          }
        }
        default: {
            $if_errs = gsub(split($interfaces, " |,"), "(.+)", "if_err_\\1")
    	      munin::plugin{
    	        $if_errs: ensure => "if_err_";
          }
        }
    }
}

class munin::plugins::linux inherits munin::plugins::base {
    munin::plugin {
    	[ df_abs, forks, df_inode, irqstats, entropy, open_inodes ]:
    		ensure => present;
    	acpi:
    		ensure => $acpi_available;
    }

    include munin::plugins::interfaces
}

class munin::plugins::debian inherits munin::plugins::base {
    munin::plugin { apt_all: ensure => present; }
}

class munin::plugins::openbsd inherits munin::plugins::base {
    munin::plugin {
        [ df, cpu, interrupts, load, memory, netstat, open_files,
            processes, swap, users, vmstat
        ]:
            ensure => present,
    }
    munin::plugin {
        [ memory_pools, memory_types ]:
            ensure => present,
    }

}

class munin::plugins::vserver inherits munin::plugins::base {
    munin::plugin {
    	[ netstat, processes ]:
    		ensure => present;
    }
}

class munin::plugins::gentoo inherits munin::plugins::base {
    munin::plugin::deploy { "gentoo_lastupdated": config => "user portage\nenv.logfile /var/log/emerge.log\nenv.tail        /usr/bin/tail\nenv.grep        /bin/grep"}
}

class munin::plugins::centos inherits munin::plugins::base {
}



class munin::plugins::dom0 inherits munin::plugins::physical {
    munin::plugin::deploy { "xen": config => "user root"}
    munin::plugin::deploy { "xen-cpu": config => "user root"}
    munin::plugin::deploy { "xen_memory": config => "user root"}
    munin::plugin::deploy { "xen_vbd": config => "user root"}
    munin::plugin::deploy { "xen_traffic_all": config => "user root"}
}

class munin::plugins::physical inherits munin::plugins::base {
    case $kernel {
        linux: { munin::plugin { iostat: } }
    }
}

class munin::plugins::muninhost inherits munin::plugins::base {
    munin::plugin { munin_update: }
    munin::plugin { munin_graph: }
}

class munin::plugins::domU inherits munin::plugins::base { }

class munin::plugins::djbdns inherits munin::plugins::base {
    munin::plugin::deploy { "tinydns": }
}

class munin::plugins::apache inherits munin::plugins::base {
    munin::plugin{ "apache_accesses": }
    munin::plugin{ "apache_processes": }
    munin::plugin{ "apache_volume": }
    munin::plugin::deploy { "apache_activity": }
}

class munin::plugins::selinux inherits munin::plugins::base {
    munin::plugin::deploy { "selinuxenforced": }
    munin::plugin::deploy { "selinux_avcstats": }
}

class munin::plugins::nagios inherits munin::plugins::base {
    munin::plugin::deploy {
        nagios_hosts: config => 'user root';
        nagios_svc: config => 'user root';
        nagios_perf_hosts: ensure => nagios_perf_, config => 'user root';
        nagios_perf_svc: ensure => nagios_perf_, config => 'user root';
    }
}