9a7b772a8145c3ed150cca4663bbad3ed1221271
[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                         # this has to be installed before the package, so the postinst can
70                         # boot the munin-node without failure!
71                         before => Package["munin-node"],
72             notify => Service['munin-node'],
73                         mode => 0644, owner => root, group => 0,
74         }
75         munin::register { $fqdn: }
76         include munin::plugins::base
77 }
78
79 class munin::client::darwin {
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 inherits munin::client::base {
102     # the plugin will need that
103         package { "iproute": ensure => installed }
104
105         Service["munin-node"]{
106                 # sarge's munin-node init script has no status
107                 hasstatus => $lsbdistcodename ? { sarge => false, default => true }
108         }
109     File["/etc/munin/munin-node.conf"]{
110                         content => template("munin/munin-node.conf.$operatingsystem.$lsbdistcodename"),
111     }
112         # workaround bug in munin_node_configure
113         plugin { "postfix_mailvolume": ensure => absent }
114         include munin::plugins::debian
115 }
116
117 class munin::client::ubuntu inherits munin::client::debian {}
118
119 class munin::client::gentoo inherits munin::client::base {
120     Package['munin-node'] {
121         name => 'munin',
122         category => 'net-analyzer',
123     }
124     
125
126         include munin::plugins::gentoo
127 }
128
129 class munin::client::centos inherits munin::client::base {
130         include munin::plugins::centos
131 }