818184537699d98870bfbfbcbcd4f40fed52e1c6
[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
5 class munin::client {
6
7         $munin_port_real = $munin_port ? { '' => 4949, default => $munin_port } 
8         $munin_host_real = $munin_host ? {
9                 '' => '*',
10                 'fqdn' => '*',
11                 default => $munin_host
12         }
13
14         case $operatingsystem {
15                 darwin: { include munin::client::darwin }
16                 debian: {
17                         include munin::client::debian
18                         include munin::plugins::debian
19                 }
20                 ubuntu: {
21                         info ( "Trying to configure Ubuntu's munin with Debian class" )
22                         include munin::client::debian
23                         include munin::plugins::debian
24                 }
25                 gentoo: {
26                         include munin::client::gentoo
27                         include munin::plugins::gentoo
28                 }
29                 centos: {
30                         include munin::client::centos
31                         include munin::plugins::centos
32                 }
33                 default: { fail ("Don't know how to handle munin on $operatingsystem") }
34         }
35
36         case $kernel {
37                 linux: {
38                         case $vserver {
39                                 guest: { include munin::plugins::vserver }
40                                 default: {
41                                         include munin::plugins::linux
42                                 }
43                         }
44                 }
45                 default: {
46                         err( "Don't know which munin plugins to install for $kernel" )
47                 }
48         }
49         case $virtual {
50         physical: { include munin::plugins::physical }
51             xen0: { include munin::plugins::dom0 }
52         xenu: { include munin::plugins::domU }
53     }
54
55 }
56
57 define munin::register()
58 {
59         $munin_port_real = $munin_port ? { '' => 4949, default => $munin_port } 
60         $munin_host_real = $munin_host ? {
61                 '' => $fqdn,
62                 'fqdn' => $fqdn,
63                 default => $munin_host
64         }
65
66         @@file { "${NODESDIR}/${name}_${munin_port_real}":
67                 ensure => present,
68                 content => template("munin/defaultclient.erb"),
69         tag => 'munin',
70         }
71 }
72
73 define munin::register_snmp()
74 {
75         @@file { "munin_snmp_${name}": path => "${NODESDIR}/${name}",
76                 ensure => present,
77                 content => template("munin/snmpclient.erb"),
78         tag => 'munin',
79         }
80 }
81
82 class munin::client::darwin 
83 {
84         file { "/usr/share/snmp/snmpd.conf": 
85                 mode => 744,
86                 content => template("munin/darwin_snmpd.conf.erb"),
87                 group  => 0,
88                 owner  => root,
89         }
90         delete_matching_line{"startsnmpdno":
91                 file => "/etc/hostconfig",
92                 pattern => "SNMPSERVER=-NO-",
93         }
94         line { "startsnmpdyes":
95                 file => "/etc/hostconfig",
96                 line => "SNMPSERVER=-YES-",
97                 notify => Exec["/sbin/SystemStarter start SNMP"],
98         }
99         exec{"/sbin/SystemStarter start SNMP":
100                 noop => false,
101         } 
102         munin::register_snmp { $fqdn: }
103 }
104
105 class munin::client::debian 
106 {
107         package { "munin-node": ensure => installed }
108     # the plugin will need that
109         package { "iproute": ensure => installed }
110
111         file {
112                 "/etc/munin/":
113                         ensure => directory,
114                         mode => 0755, owner => root, group => 0;
115                 "/etc/munin/munin-node.conf":
116                         content => template("munin/munin-node.conf.${operatingsystem}.${lsbdistcodename}"),
117                         mode => 0644, owner => root, group => 0,
118                         # this has to be installed before the package, so the postinst can
119                         # boot the munin-node without failure!
120                         before => Package["munin-node"],
121                         notify => Service["munin-node"],
122         }
123
124         service { "munin-node":
125                 ensure => running, 
126                 # sarge's munin-node init script has no status
127                 hasstatus => $lsbdistcodename ? { sarge => false, default => true }
128         }
129
130         munin::register { $fqdn: }
131
132         # workaround bug in munin_node_configure
133         munin::plugin { "postfix_mailvolume": ensure => absent }
134 }
135
136 class munin::client::gentoo 
137 {
138     $acpi_available = "absent"
139     package { 'munin-node':
140                 name => 'munin',
141                 ensure => present,
142                 category => $operatingsystem ? {
143                         gentoo => 'net-analyzer',
144                         default => '',
145                 },
146     }
147
148         file {
149                 "/etc/munin/":
150                         ensure => directory,
151                         mode => 0755, owner => root, group => 0;
152                 "/etc/munin/munin-node.conf":
153                         content => template("munin/munin-node.conf.Gentoo."),
154                         mode => 0644, owner => root, group => 0,
155                         # this has to be installed before the package, so the postinst can
156                         # boot the munin-node without failure!
157                         before => Package["munin-node"],
158             #           notify => Service["munin"],
159         }
160
161         service { "munin-node":
162                 ensure => running, 
163         }
164
165         munin::register { $fqdn: }
166 }
167
168 class munin::client::centos 
169 {
170     package { 'munin-node':
171                 ensure => present,
172     }
173
174
175         file {
176                 "/etc/munin/":
177                         ensure => directory,
178                         mode => 0755, owner => root, group =>0;
179                 "/etc/munin/munin-node.conf":
180                         content => template("munin/munin-node.conf.CentOS."),
181                         mode => 0644, owner => root, group => 0,
182                         # this has to be installed before the package, so the postinst can
183                         # boot the munin-node without failure!
184                         before => Package["munin-node"],
185                         notify => Service["munin-node"],
186         }
187
188         service { "munin-node":
189                 ensure => running, 
190         }
191
192         munin::register { $fqdn: }
193
194 }
195
196