From fd26356c64527a14c8aeffa7195947c9f41016f4 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 22 Sep 2019 15:11:13 +0200 Subject: [PATCH] munin class cleanup --- modules/munin/manifests/check.pp | 38 +++--- modules/munin/manifests/conf.pp | 45 +++---- modules/munin/manifests/init.pp | 150 ++++++++++----------- modules/munin/manifests/ipv6check.pp | 31 +++-- modules/munin/manifests/master.pp | 52 +++---- modules/munin/manifests/master_per_node.pp | 1 + 6 files changed, 152 insertions(+), 165 deletions(-) diff --git a/modules/munin/manifests/check.pp b/modules/munin/manifests/check.pp index b122385b7..0ed10ea57 100644 --- a/modules/munin/manifests/check.pp +++ b/modules/munin/manifests/check.pp @@ -1,23 +1,21 @@ -define munin::check($ensure = present, $script = undef) { +# enable (or disable) a munin check +# @param ensure check enabled/disabled +# @param script check to synclink +define munin::check( + Enum['present','absent'] $ensure = 'present', + String $script = $name +) { + include munin - include munin + $link_target = $ensure ? { + present => link, + absent => absent, + } - if $script { - $link = $script - } else { - $link = $name - } - - $link_target = $ensure ? { - present => link, - absent => absent, - default => fail ( "Unknown ensure value: '$ensure'" ), - } - - file { "/etc/munin/plugins/${name}": - ensure => $link_target, - target => "/usr/share/munin/plugins/${link}", - require => Package['munin-node'], - notify => Service['munin-node'], - } + file { "/etc/munin/plugins/${name}": + ensure => $link_target, + target => "/usr/share/munin/plugins/${script}", + require => Package['munin-node'], + notify => Service['munin-node'], + } } diff --git a/modules/munin/manifests/conf.pp b/modules/munin/manifests/conf.pp index 5413c4349..ad5026c2f 100644 --- a/modules/munin/manifests/conf.pp +++ b/modules/munin/manifests/conf.pp @@ -1,34 +1,19 @@ +# a conf.d snippet +# @param ensure check enabled/disabled +# @param content content to put into plugon-conf.d/ +# @param source file to put into plugon-conf.d/ define munin::conf ( - $ensure=present, - $content=false, - $source=false + Enum['present','absent'] $ensure = 'present', + Optional[String] $content = undef, + Optional[String] $source = undef, ) { + include munin - include munin - - case $ensure { - present: { - if ! ($source or $content) { - fail ( "No configuration found for ${name}" ) - } - } - absent: {} - default: { fail ( "Unknown ensure value: '$ensure'" ) } - } - - if $source { - file { "/etc/munin/plugin-conf.d/${name}": - ensure => $ensure, - source => $source, - require => Package['munin-node'], - notify => Service['munin-node'], - } - } elsif $content { - file { "/etc/munin/plugin-conf.d/${name}": - ensure => $ensure, - content => $content, - require => Package['munin-node'], - notify => Service['munin-node'], - } - } + file { "/etc/munin/plugin-conf.d/${name}": + ensure => $ensure, + source => $source, + content => $content, + require => Package['munin-node'], + notify => Service['munin-node'], + } } diff --git a/modules/munin/manifests/init.pp b/modules/munin/manifests/init.pp index 4f541bfcd..736fd0d21 100644 --- a/modules/munin/manifests/init.pp +++ b/modules/munin/manifests/init.pp @@ -1,89 +1,89 @@ +# our munin class class munin { + package { 'munin-node': + ensure => installed + } - package { 'munin-node': - ensure => installed - } + service { 'munin-node': + ensure => running, + require => Package['munin-node'], + } - service { 'munin-node': - ensure => running, - require => Package['munin-node'], - } + file { '/var/log/munin': + ensure => directory, + owner => root, + group => 'www-data', + mode => '0755', + } - file { '/var/log/munin': - ensure => directory, - owner => root, - group => 'www-data', - mode => '0755', - } + file { '/etc/munin/munin-node.conf': + content => template('munin/munin-node.conf.erb'), + require => Package['munin-node'], + notify => Service['munin-node'], + } - file { '/etc/munin/munin-node.conf': - content => template('munin/munin-node.conf.erb'), - require => Package['munin-node'], - notify => Service['munin-node'], - } + file { '/etc/munin/plugin-conf.d/munin-node': + content => template('munin/munin-node.plugin.conf.erb'), + require => Package['munin-node'], + notify => Service['munin-node'], + } - file { '/etc/munin/plugin-conf.d/munin-node': - content => template('munin/munin-node.plugin.conf.erb'), - require => Package['munin-node'], - notify => Service['munin-node'], - } + file { '/etc/logrotate.d/munin-node': + source => 'puppet:///modules/munin/logrotate', + require => Package['munin-node'], + } - file { '/etc/logrotate.d/munin-node': - source => 'puppet:///modules/munin/logrotate', - require => Package['munin-node'], - } + file { '/etc/munin/plugins/df': + ensure => link, + target => '/usr/share/munin/plugins/df', + require => Package['munin-node'], + notify => Service['munin-node'], + } - file { '/etc/munin/plugins/df': - ensure => link, - target => '/usr/share/munin/plugins/df', - require => Package['munin-node'], - notify => Service['munin-node'], - } + file { '/etc/munin/plugins/df_abs': + ensure => file, + source => 'puppet:///modules/munin/df-wrap', + mode => '0555', + require => Package['munin-node'], + notify => Service['munin-node'], + } - file { '/etc/munin/plugins/df_abs': - ensure => file, - source => 'puppet:///modules/munin/df-wrap', - mode => '0555', - require => Package['munin-node'], - notify => Service['munin-node'], - } + file { '/etc/munin/plugins/df_inode': + ensure => link, + target => '/usr/share/munin/plugins/df_inode', + require => Package['munin-node'], + notify => Service['munin-node'], + } - file { '/etc/munin/plugins/df_inode': - ensure => link, - target => '/usr/share/munin/plugins/df_inode', - require => Package['munin-node'], - notify => Service['munin-node'], - } + ferm::rule { 'dsa-munin-v4': + description => 'Allow munin from munin master', + rule => 'proto tcp mod state state (NEW) dport (munin) @subchain \'munin\' { saddr ($HOST_MUNIN_V4 $HOST_NAGIOS_V4) ACCEPT; }', + notarule => true, + } - ferm::rule { 'dsa-munin-v4': - description => 'Allow munin from munin master', - rule => 'proto tcp mod state state (NEW) dport (munin) @subchain \'munin\' { saddr ($HOST_MUNIN_V4 $HOST_NAGIOS_V4) ACCEPT; }', - notarule => true, - } + ferm::rule { 'dsa-munin-v6': + description => 'Allow munin from munin master', + domain => 'ip6', + rule => 'proto tcp mod state state (NEW) dport (munin) @subchain \'munin\' { saddr ($HOST_MUNIN_V6 $HOST_NAGIOS_V6) ACCEPT; }', + notarule => true, + } - ferm::rule { 'dsa-munin-v6': - description => 'Allow munin from munin master', - domain => 'ip6', - rule => 'proto tcp mod state state (NEW) dport (munin) @subchain \'munin\' { saddr ($HOST_MUNIN_V6 $HOST_NAGIOS_V6) ACCEPT; }', - notarule => true, - } + @@munin::master_per_node { $::fqdn: } - @@munin::master_per_node { $::fqdn: } - - package { 'munin-async': - ensure => installed - } - service { 'munin-async': - ensure => running, - require => Package['munin-async'], - } - dsa_systemd::override { 'munin-async': - content => @("EOF"), - [Service] - RestartSec=10 - | EOF - } - file { '/etc/ssh/userkeys/munin-async': - source => 'puppet:///modules/munin/munin-async-authkeys', - } + package { 'munin-async': + ensure => installed + } + service { 'munin-async': + ensure => running, + require => Package['munin-async'], + } + dsa_systemd::override { 'munin-async': + content => @("EOF"), + [Service] + RestartSec=10 + | EOF + } + file { '/etc/ssh/userkeys/munin-async': + source => 'puppet:///modules/munin/munin-async-authkeys', + } } diff --git a/modules/munin/manifests/ipv6check.pp b/modules/munin/manifests/ipv6check.pp index c8bf1b706..9470325ea 100644 --- a/modules/munin/manifests/ipv6check.pp +++ b/modules/munin/manifests/ipv6check.pp @@ -1,16 +1,19 @@ -define munin::ipv6check($ensure = present) { +# ipv5 check +# @param ensure check enabled/disabled +define munin::ipv6check( + Enum['present','absent'] $ensure = 'present', +) { + include munin - include munin - - if ! ($ensure in [absent,present]) { - fail("unexpected ensure: ${ensure}") - } - - file { "/etc/munin/plugins/${name}": - ensure => $ensure, - content => "#!/bin/bash\n# This file is under puppet control\n. /usr/share/munin/plugins/ip_\n", - mode => '0555', - require => Package['munin-node'], - notify => Service['munin-node'], - } + file { "/etc/munin/plugins/${name}": + ensure => $ensure, + content => @(EOF), + #!/bin/bash + # This file is under puppet control + . /usr/share/munin/plugins/ip_ + | EOF + mode => '0555', + require => Package['munin-node'], + notify => Service['munin-node'], + } } diff --git a/modules/munin/manifests/master.pp b/modules/munin/manifests/master.pp index 6d7d2fdc7..e389f534d 100644 --- a/modules/munin/manifests/master.pp +++ b/modules/munin/manifests/master.pp @@ -1,33 +1,33 @@ +# munin master node class munin::master { + package { 'munin': + ensure => installed + } - package { 'munin': - ensure => installed - } + file { '/etc/munin/munin.conf': + content => template('munin/munin.conf.erb'), + require => Package['munin']; + } - file { '/etc/munin/munin.conf': - content => template('munin/munin.conf.erb'), - require => Package['munin']; - } + ssl::service { 'munin.debian.org': + notify => Exec['service apache2 reload'], + key => true, + } + file { '/etc/munin/munin-conf.d': + ensure => directory, + mode => '0755', + purge => true, + force => true, + recurse => true, + source => 'puppet:///files/empty/', + } - ssl::service { 'munin.debian.org': - notify => Exec['service apache2 reload'], - key => true, - } - file { '/etc/munin/munin-conf.d': - ensure => directory, - mode => '0755', - purge => true, - force => true, - recurse => true, - source => 'puppet:///files/empty/', - } + Munin::Master_per_node<<| |>> - Munin::Master_per_node<<| |>> + file { '/etc/cron.d/puppet-munin-cleanup': ensure => absent; } - file { '/etc/cron.d/puppet-munin-cleanup': ensure => absent; } - - concat::fragment { 'puppet-crontab--munin-master': - target => '/etc/cron.d/puppet-crontab', - source => 'puppet:///modules/munin/master-cleanup-cron', - } + concat::fragment { 'puppet-crontab--munin-master': + target => '/etc/cron.d/puppet-crontab', + source => 'puppet:///modules/munin/master-cleanup-cron', + } } diff --git a/modules/munin/manifests/master_per_node.pp b/modules/munin/manifests/master_per_node.pp index 1d397ee5d..8ae1ee3be 100644 --- a/modules/munin/manifests/master_per_node.pp +++ b/modules/munin/manifests/master_per_node.pp @@ -1,3 +1,4 @@ +# entry per-node to be collected on the master define munin::master_per_node() { $client_fqdn = $name -- 2.20.1