don't require the exec, as the require is exported as well
[puppet_munin.git] / manifests / client.pp
1 # client.pp - configure a munin node
2 # Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
3 # See LICENSE for the full license granted to you.
4 # Adapted and improved by admin(at)immerda.ch
5
6 class munin::client {
7
8         $munin_port_real = $munin_port ? { '' => 4949, default => $munin_port } 
9         $munin_host_real = $munin_host ? {
10                 '' => '*',
11                 'fqdn' => '*',
12                 default => $munin_host
13         }
14
15     case $operatingsystem {
16         darwin: { include munin::client::darwin }
17         debian: { include munin::client::debian }
18         ubuntu: { include munin::client::ubuntu }
19         centos: { include munin::client::centos }
20         gentoo: { include munin::client::gentoo }
21         default: { include munin::client::base }
22     }
23 }
24
25 define munin::register()
26 {
27         $munin_port_real = $munin_port ? { '' => 4949, default => $munin_port } 
28         $munin_host_real = $munin_host ? {
29                 '' => $fqdn,
30                 'fqdn' => $fqdn,
31                 default => $munin_host
32         }
33
34         @@file { "${NODESDIR}/${name}_${munin_port_real}":
35                 ensure => present,
36                 content => template("munin/defaultclient.erb"),
37                 tag => 'munin',
38         }
39 }
40
41 # snmp_testplugin: the plugin we use to test if it's set
42 define munin::register_snmp(
43     $snmpd_testplugin = 'load'
44 )
45 {
46         $munin_port_real = $munin_port ? { '' => 4949, default => $munin_port } 
47         $munin_host_real = $munin_host ? {
48                 '' => '*',
49                 'fqdn' => '*',
50                 default => $munin_host
51     }
52     exec{"register_snmp_munin_for_${name}":
53         command => "munin-node-configure-snmp ${name} | sh",
54         unless => "test -e /etc/munin/plugins/snmp_${name}_${snmpd_testplugin}",
55     }
56     @@file { "munin_snmp_${name}": path => "${NODESDIR}/${name}",
57         ensure => present,
58         content => template("munin/snmpclient.erb"),
59         tag => 'munin',
60     }
61 }
62
63 class munin::client::base {
64         package { "munin-node": ensure => installed }
65         service { "munin-node":
66                 ensure => running, 
67         enable => true,
68         hasstatus => true,
69         hasrestart => true,
70         require => Package[munin-node],
71         }
72         file {"/etc/munin/":
73                         ensure => directory,
74                         mode => 0755, owner => root, group => 0;
75     }
76     $real_munin_allow = $munin_allow ? {
77         '' => '127.0.0.1',
78         default => $munin_allow
79     }
80     file {"/etc/munin/munin-node.conf":
81                         content => template("munin/munin-node.conf.$operatingsystem"),
82                         # this has to be installed before the package, so the postinst can
83                         # boot the munin-node without failure!
84                         before => Package["munin-node"],
85             notify => Service['munin-node'],
86                         mode => 0644, owner => root, group => 0,
87         }
88         munin::register { $fqdn: }
89         include munin::plugins::base
90 }
91
92 class munin::client::darwin {
93         file { "/usr/share/snmp/snmpd.conf": 
94                 mode => 744,
95                 content => template("munin/darwin_snmpd.conf.erb"),
96                 group  => 0,
97                 owner  => root,
98         }
99         delete_matching_line{"startsnmpdno":
100                 file => "/etc/hostconfig",
101                 pattern => "SNMPSERVER=-NO-",
102         }
103         line { "startsnmpdyes":
104                 file => "/etc/hostconfig",
105                 line => "SNMPSERVER=-YES-",
106                 notify => Exec["/sbin/SystemStarter start SNMP"],
107         }
108         exec{"/sbin/SystemStarter start SNMP":
109                 noop => false,
110         } 
111         munin::register_snmp { $fqdn: }
112 }
113
114 class munin::client::debian inherits munin::client::base {
115     # the plugin will need that
116         package { "iproute": ensure => installed }
117
118         Service["munin-node"]{
119                 # sarge's munin-node init script has no status
120                 hasstatus => $lsbdistcodename ? { sarge => false, default => true }
121         }
122     File["/etc/munin/munin-node.conf"]{
123                         content => template("munin/munin-node.conf.$operatingsystem.$lsbdistcodename"),
124     }
125         # workaround bug in munin_node_configure
126         plugin { "postfix_mailvolume": ensure => absent }
127         include munin::plugins::debian
128 }
129
130 class munin::client::ubuntu inherits munin::client::debian {}
131
132 class munin::client::gentoo inherits munin::client::base {
133     Package['munin-node'] {
134         name => 'munin',
135         category => 'net-analyzer',
136     }
137     
138
139         include munin::plugins::gentoo
140 }
141
142 class munin::client::centos inherits munin::client::base {
143         include munin::plugins::centos
144 }