puppet/munin/manifests/init.pp

208 lines
4.9 KiB
Puppet

# Install and configure munin node.
#
class munin::node {
package { "munin-node":
ensure => installed,
}
service { "munin-node":
ensure => running,
enable => true,
require => Package["munin-node"],
}
case $operatingsystem {
OpenBSD: {
Service["munin-node"] {
name => "munin-node",
binary => "/usr/local/sbin/munin-node",
start => "/usr/local/sbin/munin-node",
}
}
}
file { "/etc/munin/munin-node.conf":
ensure => present,
content => template("munin/munin-node.conf.erb"),
owner => root,
group => $operatingsystem ? {
OpenBSD => wheel,
default => root,
},
mode => 0644,
require => Package["munin-node"],
notify => Service["munin-node"],
}
@@file { "/etc/munin/nodes.d/${fqdn}.conf":
content => "[${fqdn}]\n address ${ipaddress}\n use_node_name yes\n",
ensure => present,
tag => "munin",
notify => Exec["generate-munin-conf"],
}
exec { "munin-node-configure":
command => "munin-node-configure ; true",
path => "/bin:/usr/bin:/sbin:/usr/sbin",
user => root,
refreshonly => true,
require => Package["munin-node"],
subscribe => Package["munin-node"],
notify => Service["munin-node"],
}
munin::plugin { "vmware_vms": config => "vmware" }
case $operatingsystem {
OpenBSD: {
munin::plugin { "cpu": }
munin::plugin { "df": }
munin::plugin { "df_inode": }
munin::plugin { "interfaces": }
munin::plugin { "irqstats": }
munin::plugin { "load": }
munin::plugin { "netstat": }
munin::plugin { "open_files": }
munin::plugin { "sensors_temp": }
munin::plugin { "vmstat": }
}
}
}
# Add new custom munin plugin.
#
# === Parameters
#
# $name:
# Plugin name to install.
# $config:
# Configuration file name associated with plugin. Defaults to none.
#
# === Sample usage
#
# munin::plugin { "vmware_vms":
# config => "vmware",
# }
#
define munin::plugin($config = "") {
case $operatingsystem {
OpenBSD: {
file { "/usr/local/lib/munin/plugins/${name}":
ensure => present,
source => "puppet:///munin/plugins/${name}",
owner => root,
group => wheel,
mode => 0755,
require => Package["munin-node"],
}
}
default: {
file { "/usr/share/munin/plugins/${name}":
ensure => present,
source => "puppet:///munin/plugins/${name}",
owner => root,
group => root,
mode => 0755,
require => Package["munin-node"],
}
}
}
if ($config) {
file { "/etc/munin/plugin-conf.d/${config}":
ensure => present,
source => [ "puppet:///files/munin/plugin-conf/${config}.${fqdn}",
"puppet:///files/munin/plugin-conf/${config}",
"puppet:///munin/plugin-conf/${config}", ],
owner => root,
group => $operatingsystem ? {
OpenBSD => wheel,
default => root,
},
mode => 0644,
notify => Service["munin-node"],
require => $operatingsystem ? {
OpenBSD => File["/usr/local/lib/munin/plugins/${name}"],
default => File["/usr/share/munin/plugins/${name}"],
},
}
}
case $operatingsystem {
OpenBSD: {
exec { "munin-enable-${name}":
command => "ln -s /usr/local/lib/munin/plugins/${name} /etc/munin/plugins/${name}",
path => "/bin:/usr/bin:/sbin:/usr/sbin",
user => root,
onlyif => [ "test ! -h /etc/munin/plugins/${name}",
"/usr/local/lib/munin/plugins/${name} autoconf", ],
notify => Service["munin-node"],
require => File["/usr/local/lib/munin/plugins/${name}"],
}
}
default: {
exec { "munin-enable-${name}":
command => "ln -s /usr/share/munin/plugins/${name} /etc/munin/plugins/${name}",
path => "/bin:/usr/bin:/sbin:/usr/sbin",
user => root,
onlyif => [ "test ! -h /etc/munin/plugins/${name}",
"/usr/share/munin/plugins/${name} autoconf", ],
notify => Service["munin-node"],
require => File["/usr/share/munin/plugins/${name}"],
}
}
}
}
# Install and configure munin server.
#
# === Requires
#
# * Storedconfigs
#
class munin::server {
package { "munin":
ensure => installed,
}
file { "/etc/munin/nodes.d":
ensure => directory,
purge => true,
force => true,
recurse => true,
owner => root,
group => root,
mode => 0644,
source => "puppet:///custom/empty",
require => Package["munin"],
}
file { "/etc/munin/munin.conf.in":
ensure => present,
source => "puppet:///munin/munin.conf.in",
owner => root,
group => root,
mode => 0644,
require => Package["munin"],
notify => Exec["generate-munin-conf"],
}
exec { "generate-munin-conf":
command => "cat /etc/munin/munin.conf.in /etc/munin/nodes.d/*.conf > /etc/munin/munin.conf",
path => "/bin:/usr/bin:/sbin:/usr/sbin",
user => root,
refreshonly => true,
require => File["/etc/munin/munin.conf.in"],
}
File <<| tag == "munin" |>>
}