b2bad8b0fa41d2b2911a233ac96a27f1113d7b09
[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 define munin::register_snmp()
42 {
43         @@file { "munin_snmp_${name}": path => "${NODESDIR}/${name}",
44                 ensure => present,
45                 content => template("munin/snmpclient.erb"),
46                 tag => 'munin',
47         }
48 }
49
50 class munin::client::base {
51         package { "munin-node": ensure => installed }
52         service { "munin-node":
53                 ensure => running, 
54         hasstatus => true,
55         hasrestart => true,
56         require => Package[munin-node],
57         }
58         file {
59                 "/etc/munin/":
60                         ensure => directory,
61                         mode => 0755, owner => root, group => 0;
62                 "/etc/munin/munin-node.conf":
63                         content => template("munin/munin-node.conf.$operatingsystem"),
64                         mode => 0644, owner => root, group => 0,
65                         # this has to be installed before the package, so the postinst can
66                         # boot the munin-node without failure!
67                         before => Package["munin-node"],
68         }
69         munin::register { $fqdn: }
70         include munin::plugins::base
71 }
72
73 class munin::client::darwin {
74         file { "/usr/share/snmp/snmpd.conf": 
75                 mode => 744,
76                 content => template("munin/darwin_snmpd.conf.erb"),
77                 group  => 0,
78                 owner  => root,
79         }
80         delete_matching_line{"startsnmpdno":
81                 file => "/etc/hostconfig",
82                 pattern => "SNMPSERVER=-NO-",
83         }
84         line { "startsnmpdyes":
85                 file => "/etc/hostconfig",
86                 line => "SNMPSERVER=-YES-",
87                 notify => Exec["/sbin/SystemStarter start SNMP"],
88         }
89         exec{"/sbin/SystemStarter start SNMP":
90                 noop => false,
91         } 
92         munin::register_snmp { $fqdn: }
93 }
94
95 class munin::client::debian inherits munin::client::base {
96     # the plugin will need that
97         package { "iproute": ensure => installed }
98
99         Service["munin-node"]{
100                 # sarge's munin-node init script has no status
101                 hasstatus => $lsbdistcodename ? { sarge => false, default => true }
102         }
103     File["/etc/munin/munin-node.conf"]{
104                         content => template("munin/munin-node.conf.$operatingsystem.$lsbdistcodename"),
105     }
106         # workaround bug in munin_node_configure
107         plugin { "postfix_mailvolume": ensure => absent }
108         include munin::plugins::debian
109 }
110
111 class munin::client::ubuntu inherits munin::client::debian {}
112
113 class munin::client::gentoo inherits munin::client::base {
114     Package['munin-node'] {
115         name => 'munin',
116         category => 'net-analyzer',
117     }
118     
119
120         include munin::plugins::gentoo
121 }
122
123 class munin::client::centos inherits munin::client::base {
124         include munin::plugins::centos
125 }