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