summaryrefslogtreecommitdiff
path: root/manifests/client.pp
blob: 7894e2fb42266d93f1e6b0ec1b5cbe9f3fc8fe94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# client.pp - configure a munin node
# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at>
# See LICENSE for the full license granted to you.
# Adapted and improved by admin(at)immerda.ch

class munin::client {

	$munin_port_real = $munin_port ? { '' => 4949, default => $munin_port } 
	$munin_host_real = $munin_host ? {
		'' => '*',
		'fqdn' => '*',
		default => $munin_host
	}

    case $operatingsystem {
        openbsd: { include munin::client::openbsd }
        darwin: { include munin::client::darwin }
        debian,ubuntu: { include munin::client::debian }
        centos: { include munin::client::centos }
        gentoo: { include munin::client::gentoo }
        default: { include munin::client::base }
    }
    if $use_shorewall {
        include shorewall::rules::munin
    }
}

define munin::register()
{
	$munin_port_real = $munin_port ? { '' => 4949, default => $munin_port } 
	$munin_host_real = $munin_host ? {
		'' => $fqdn,
		'fqdn' => $fqdn,
		default => $munin_host
	}

	@@file { "${NODESDIR}/${name}_${munin_port_real}":
		ensure => present,
		content => template("munin/defaultclient.erb"),
		tag => 'munin',
	}
}

# snmp_testplugin: the plugin we use to test if it's set
define munin::register_snmp(
    $snmpd_testplugin = 'load'
)
{
	$munin_port_real = $munin_port ? { '' => 4949, default => $munin_port } 
	$munin_host_real = $munin_host ? {
		'' => '*',
		'fqdn' => '*',
		default => $munin_host
    }
    exec{"register_snmp_munin_for_${name}":
        command => "munin-node-configure-snmp ${name} | sh",
        unless => "test -e /etc/munin/plugins/snmp_${name}_${snmpd_testplugin}",
    }
    @@file { "munin_snmp_${name}": path => "${NODESDIR}/${name}",
        ensure => present,
        content => template("munin/snmpclient.erb"),
        tag => 'munin',
    }
}

class munin::client::base {
    service { 'munin-node':
        ensure => running, 
        enable => true,
        hasstatus => true,
        hasrestart => true,
    }
    file {'/etc/munin/':
        ensure => directory,
        mode => 0755, owner => root, group => 0;
    }
    $real_munin_allow = $munin_allow ? {
        '' => '127.0.0.1',
        default => $munin_allow
    }
    file {'/etc/munin/munin-node.conf':
	    content => template("munin/munin-node.conf.$operatingsystem"),
        notify => Service['munin-node'],
		mode => 0644, owner => root, group => 0,
	}
	munin::register { $fqdn: }
	include munin::plugins::base
}

# currently we install munin on openbsd by targz
# :(
class munin::client::openbsd inherits munin::client::base {
    file{'/usr/src/munin_openbsd.tar.gz':
        source => "puppet://$server/munin/openbsd/package/munin_openbsd.tar.gz",
        owner => root, group => 0, mode => 0600;
    }
    package{ [ 'p5-Compress-Zlib', 'p5-Crypt-SSLeay', 'p5-HTML-Parser', 
                'p5-HTML-Tagset', 'p5-HTTP-GHTTP', 'p5-LWP-UserAgent-Determined',
                'p5-Net-SSLeay', 'p5-Net-Server', 'p5-URI', 'p5-libwww', 'pcre', 'curl' ]:
        ensure => installed,
        before => File['/var/run/munin'],
    }
    exec{'extract_openbsd':
        command => 'cd /;tar xzf /usr/src/munin_openbsd.tar.gz',
        unless => 'test -d /opt/munin',
        require => File['/usr/src/munin_openbsd.tar.gz'],
    }
    file{[ '/var/run/munin', '/var/log/munin' ]:
        ensure => directory,
        require => Exec['extract_openbsd'],
        owner => root, group  => 0, mode => 0755;
    }
    openbsd::add_to_rc_local{'munin-node':
        binary => '/opt/munin/sbin/munin-node',
        require => File['/var/run/munin'],
    }
    Service['munin-node']{
        restart => '/bin/kill -HUP `/bin/cat /var/run/munin/munin-node.pid`',
        stop => '/bin/kill `/bin/cat /var/run/munin/munin-node.pid`',
        start => '/opt/munin/sbin/munin-node',
        hasstatus => false,
        hasrestart => false,
        require => [ File['/var/run/munin'], File['/var/log/munin'] ],
    }

    cron{'clean_munin_logfile':
        command => 'rm /var/log/munin/munin-node.log; kill -HUP `cat /var/run/munin/munin-node.pid`',
        minute => 0,
        hour => 2,
        weekday => 0,
    }
}

class munin::client::darwin {
	file { "/usr/share/snmp/snmpd.conf": 
		mode => 744,
		content => template("munin/darwin_snmpd.conf.erb"),
		group  => 0,
		owner  => root,
	}
	delete_matching_line{"startsnmpdno":
		file => "/etc/hostconfig",
		pattern => "SNMPSERVER=-NO-",
	}
	line { "startsnmpdyes":
		file => "/etc/hostconfig",
		line => "SNMPSERVER=-YES-",
		notify => Exec["/sbin/SystemStarter start SNMP"],
	}
	exec{"/sbin/SystemStarter start SNMP":
		noop => false,
	} 
	munin::register_snmp { $fqdn: }
}

class munin::client::package inherits munin::client::base {
	package { 'munin-node': ensure => installed }
    Service['munin-node']{
        require => Package[munin-node],
    }
    File['/etc/munin/munin-node.conf']{
    	# this has to be installed before the package, so the postinst can
    	# boot the munin-node without failure!
	    before => Package['munin-node'],
    }
}

class munin::client::debian inherits munin::client::package {
    # the plugin will need that
	package { "iproute": ensure => installed }

	Service["munin-node"]{
		# sarge's munin-node init script has no status
		hasstatus => $lsbdistcodename ? { sarge => false, default => true }
	}
    File["/etc/munin/munin-node.conf"]{
			content => template("munin/munin-node.conf.$operatingsystem.$lsbdistcodename"),
    }
	# workaround bug in munin_node_configure
	plugin { "postfix_mailvolume": ensure => absent }
	include munin::plugins::debian
}

class munin::client::gentoo inherits munin::client::package {
    Package['munin-node'] {
        name => 'munin',
        category => 'net-analyzer',
    }
    

	include munin::plugins::gentoo
}

class munin::client::centos inherits munin::client::package {
	include munin::plugins::centos
}