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