tried to make munin-node installable and runable on openbsd
[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         openbsd: { include munin::client::openbsd }
17         darwin: { include munin::client::darwin }
18         debian,ubuntu: { include munin::client::debian }
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         service { 'munin-node':
52                 ensure => running, 
53         enable => true,
54         hasstatus => true,
55         hasrestart => true,
56         }
57         file {'/etc/munin/':
58                         ensure => directory,
59                         mode => 0755, owner => root, group => 0;
60     }
61     $real_munin_allow = $munin_allow ? {
62         '' => '127.0.0.1',
63         default => $munin_allow
64     }
65     file {'/etc/munin/munin-node.conf':
66             content => template("munin/munin-node.conf.$operatingsystem"),
67         notify => Service['munin-node'],
68                 mode => 0644, owner => root, group => 0,
69         }
70         munin::register { $fqdn: }
71         include munin::plugins::base
72 }
73
74 # currently we install munin on openbsd by hand
75 # :(
76 class munin::openbsd inherits openbsd::base {
77     file{'/usr/src/munin_openbsd.tar.gz':
78         source => "puppet://$server/munin/openbsd/package/munin_openbsd.tar.gz",
79         owner => root, group => 0, mode => 0600;
80     }
81     package{ [ 'p5-Compress-Zlib', 'p5-Crypt-SSLeay', 'p5-HTML-Parser', 
82                 'p5-HTML-Tagset', 'p5-HTTP-GHTTP', 'p5-LWP-UserAgent-Determined',
83                 'p5-Net-SSLeay', 'p5-Net-Server', 'p5-URI', 'p5-libwww', 'pcre', 'curl' ]:
84         ensure => installed,
85         before => File['/var/run/munin'],
86     }
87     exec{'extract_openbsd':
88         command => 'tar xzf /usr/src/munin_openbsd.tar.gz',
89         unless => 'test -d /opt/munin',
90         require => File['/usr/src/munin_openbsd.tar.gz'],
91     }
92     file{'/var/run/munin':
93         ensure => directory,
94         require => File['/usr/src/munin_openbsd.tar.gz'],
95         owner => root, group  => 0, mode => 0755;
96     }
97     exec{'enable_munin_on_boot':
98         command => 'echo "if [ -x /opt/munin/sbin/munin-node ]; then echo -n \' munin\'; /opt/munin/sbin/munin-node; fi" >> /etc/rc.local',
99         unless => 'grep -q "if [ -x /opt/munin/sbin/munin-node ]; then echo -n \' munin\'; /opt/munin/sbin/munin-node; fi" >> /etc/rc.local',
100         require => File['/var/run/munin'],
101     }
102     Service['munin-node']{
103         restart => '/bin/kill -HUP `/bin/cat /var/run/munin/munin-node.pid`',
104         stopt => '/bin/kill `/bin/cat /var/run/munin/munin-node.pid`',
105         start => '/opt/munin/sbin/munin-node',
106         hasstatus => false,
107         hasrestart => false,
108         require => File['/var/run/munin'],
109     }
110 }
111
112 class munin::client::darwin {
113         file { "/usr/share/snmp/snmpd.conf": 
114                 mode => 744,
115                 content => template("munin/darwin_snmpd.conf.erb"),
116                 group  => 0,
117                 owner  => root,
118         }
119         delete_matching_line{"startsnmpdno":
120                 file => "/etc/hostconfig",
121                 pattern => "SNMPSERVER=-NO-",
122         }
123         line { "startsnmpdyes":
124                 file => "/etc/hostconfig",
125                 line => "SNMPSERVER=-YES-",
126                 notify => Exec["/sbin/SystemStarter start SNMP"],
127         }
128         exec{"/sbin/SystemStarter start SNMP":
129                 noop => false,
130         } 
131         munin::register_snmp { $fqdn: }
132 }
133
134 class munin::client::package inherits munin::client::base {
135         package { 'munin-node': ensure => installed }
136     Service['munin-node']{
137         require => Package[munin-node],
138     }
139     File['/etc/munin/munin-node.conf']{
140         # this has to be installed before the package, so the postinst can
141         # boot the munin-node without failure!
142             before => Package['munin-node'],
143     }
144 }
145
146 class munin::client::debian inherits munin::client::package {
147     # the plugin will need that
148         package { "iproute": ensure => installed }
149
150         Service["munin-node"]{
151                 # sarge's munin-node init script has no status
152                 hasstatus => $lsbdistcodename ? { sarge => false, default => true }
153         }
154     File["/etc/munin/munin-node.conf"]{
155                         content => template("munin/munin-node.conf.$operatingsystem.$lsbdistcodename"),
156     }
157         # workaround bug in munin_node_configure
158         plugin { "postfix_mailvolume": ensure => absent }
159         include munin::plugins::debian
160 }
161
162 class munin::client::gentoo inherits munin::client::package {
163     Package['munin-node'] {
164         name => 'munin',
165         category => 'net-analyzer',
166     }
167     
168
169         include munin::plugins::gentoo
170 }
171
172 class munin::client::centos inherits munin::client::package {
173         include munin::plugins::centos
174 }