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