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