diff --git a/manifests/agent.pp b/manifests/agent.pp index 3a50356..a0aba41 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -1,20 +1,37 @@ +# == Class: check_mk::agent +# +# Manage check_mk agent +# +# === Parameters +# +# @param ensure [present,absent] Ensure, default = 'present' +# @manage_package [Boolean] Wether to manage agent package install +# @manage_config [Boolean] Wether to manage agent config +# @manage_service [Boolean] Wether to manage agent service +# @mrpe_checks [Hash] mrpe checks to add to mrpe.cfg +# class check_mk::agent ( - $filestore = undef, - $host_tags = undef, - $ip_whitelist = undef, - $port = '6556', - $server_dir = '/usr/bin', - $use_cache = false, - $user = 'root', - $version = undef, - $workspace = '/root/check_mk', - $package = undef, - $mrpe_checks = {}, -) { + $ensure = present, + $manage_package = $check_mk::params::agent_manage_package, + $manage_config = $check_mk::params::agent_manage_config, + $manage_service = $check_mk::params::agent_manage_service, + $config_dir = $check_mk::params::agent_config_dir, + $filestore = undef, + $host_tags = undef, + $ip_whitelist = undef, + $port = '6556', + $server_dir = '/usr/bin', + $use_cache = false, + $user = 'root', + $version = undef, + $workspace = '/root/check_mk', + $package = undef, + $mrpe_checks = {}, +) inherits check_mk::params { validate_hash($mrpe_checks) - include check_mk::agent::install - include check_mk::agent::config - include check_mk::agent::service + include ::check_mk::agent::install + include ::check_mk::agent::config + include ::check_mk::agent::service Class['check_mk::agent::install'] -> Class['check_mk::agent::config'] @@check_mk::host { $::fqdn: diff --git a/manifests/agent/config.pp b/manifests/agent/config.pp index dbf7b42..80a8e44 100644 --- a/manifests/agent/config.pp +++ b/manifests/agent/config.pp @@ -31,37 +31,39 @@ $use_cache = $check_mk::agent::use_cache, $user = $check_mk::agent::user, ) inherits check_mk::agent { - if $use_cache { - $server = "${server_dir}/check_mk_caching_agent" - } else { - $server = "${server_dir}/check_mk_agent" - } + if $check_mk::agent::manage_config { + if $use_cache { + $server = "${server_dir}/check_mk_caching_agent" + } else { + $server = "${server_dir}/check_mk_agent" + } - if $ip_whitelist { - $only_from = join($ip_whitelist, ' ') - } else { - $only_from = undef - } + if $ip_whitelist { + $only_from = join($ip_whitelist, ' ') + } else { + $only_from = undef + } - $xinetd_file = $::osfamily ? { - 'RedHat' => '/etc/xinetd.d/check-mk-agent', - default => '/etc/xinetd.d/check_mk', - } + $xinetd_file = $::osfamily ? { + 'RedHat' => '/etc/xinetd.d/check-mk-agent', + default => '/etc/xinetd.d/check_mk', + } - file { $xinetd_file: - ensure => 'file', - owner => 'root', - group => 'root', - mode => '0444', - content => template('check_mk/agent/check_mk.erb'), - require => Package['check_mk-agent'], - notify => Class['check_mk::agent::service'], - } + file { $xinetd_file: + ensure => 'file', + owner => 'root', + group => 'root', + mode => '0444', + content => template('check_mk/agent/check_mk.erb'), + require => Package['check_mk-agent'], + notify => Class['check_mk::agent::service'], + } - # Delete file from older check_mk package version - if $::osfamily == 'RedHat' { - file { '/etc/xinetd.d/check_mk': - ensure => 'absent', + # Delete file from older check_mk package version + if $::osfamily == 'RedHat' { + file { '/etc/xinetd.d/check_mk': + ensure => 'absent', + } } } } diff --git a/manifests/agent/install.pp b/manifests/agent/install.pp index a377e56..afdfb62 100644 --- a/manifests/agent/install.pp +++ b/manifests/agent/install.pp @@ -1,49 +1,51 @@ class check_mk::agent::install ( $version = $check_mk::agent::version, - $filestore = undef, + $filestore = $check_mk::agent::filestore, $workspace = $check_mk::agent::workspace, - $package = undef, + $package = $check_mk::agent::package, ) inherits check_mk::agent { - if ! defined(Package['xinetd']) { - package { 'xinetd': - ensure => present, - } - } - if $filestore { - if ! $version { - fail('version must be specified.') + if $check_mk::agent::manage_package { + if ! defined(Package['xinetd']) { + package { 'xinetd': + ensure => present, + } } + if $filestore { + if ! $version { + fail('version must be specified.') + } - if ! defined(File[$workspace]) { - file { $workspace: - ensure => directory, + if ! defined(File[$workspace]) { + file { $workspace: + ensure => directory, + } + } + file { "${workspace}/check_mk-agent-${version}.noarch.rpm": + ensure => present, + source => "${filestore}/check_mk-agent-${version}.noarch.rpm", + require => Package['xinetd'], + } + package { 'check_mk-agent': + ensure => present, + provider => 'rpm', + source => "${workspace}/check_mk-agent-${version}.noarch.rpm", + require => File["${workspace}/check_mk-agent-${version}.noarch.rpm"], } } - file { "${workspace}/check_mk-agent-${version}.noarch.rpm": - ensure => present, - source => "${filestore}/check_mk-agent-${version}.noarch.rpm", - require => Package['xinetd'], - } - package { 'check_mk-agent': - ensure => present, - provider => 'rpm', - source => "${workspace}/check_mk-agent-${version}.noarch.rpm", - require => File["${workspace}/check_mk-agent-${version}.noarch.rpm"], - } - } - else { - $check_mk_agent = $package ? { - undef => $::osfamily ? { - 'Debian' => 'check-mk-agent', - 'RedHat' => 'check-mk-agent', - default => 'check_mk-agent', - }, - default => $package, - } - package { 'check_mk-agent': - ensure => present, - name => $check_mk_agent, - require => Package['xinetd'], + else { + $check_mk_agent = $package ? { + undef => $::osfamily ? { + 'Debian' => 'check-mk-agent', + 'RedHat' => 'check-mk-agent', + default => 'check_mk-agent', + }, + default => $package, + } + package { 'check_mk-agent': + ensure => present, + name => $check_mk_agent, + require => Package['xinetd'], + } } } } diff --git a/manifests/agent/mrpe.pp b/manifests/agent/mrpe.pp index eb0c80f..8fbfd7d 100644 --- a/manifests/agent/mrpe.pp +++ b/manifests/agent/mrpe.pp @@ -22,11 +22,7 @@ define check_mk::agent::mrpe ( $command, ) { - $mrpe_config_file = $::operatingsystem ? { - centos => '/etc/check-mk-agent/mrpe.cfg', - redhat => '/etc/check-mk-agent/mrpe.cfg', - default => undef, - } + $mrpe_config_file = "${check_mk::agent::config_dir}/mrpe.cfg" if ( $mrpe_config_file ) { if ! defined(Concat[$mrpe_config_file]) { diff --git a/manifests/agent/service.pp b/manifests/agent/service.pp index 0d3ff04..f2f4535 100644 --- a/manifests/agent/service.pp +++ b/manifests/agent/service.pp @@ -1,16 +1,18 @@ -class check_mk::agent::service { - if ! defined(Service['xinetd']) { - if $::operatingsystem == 'Debian' and - versioncmp($::operatingsystemmajrelease, '7') == 0 { - service { 'xinetd': - ensure => 'running', - enable => true, - hasstatus => false, - } - } else { - service { 'xinetd': - ensure => 'running', - enable => true, +class check_mk::agent::service inherits check_mk::agent { + if $check_mk::agent::manage_service { + if ! defined(Service['xinetd']) { + if $::operatingsystem == 'Debian' and + versioncmp($::operatingsystemmajrelease, '7') == 0 { + service { 'xinetd': + ensure => 'running', + enable => true, + hasstatus => false, + } + } else { + service { 'xinetd': + ensure => 'running', + enable => true, + } } } } diff --git a/manifests/init.pp b/manifests/init.pp index acab396..3f1b6c7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -21,7 +21,7 @@ } class { 'check_mk::service': checkmk_service => $checkmk_service, - httpd_service => $httpd_service, - require => Class['check_mk::config'], + httpd_service => $httpd_service, + require => Class['check_mk::config'], } } diff --git a/manifests/params.pp b/manifests/params.pp index edd6028..d222ef8 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -8,13 +8,23 @@ $site = 'monitoring' $workspace = '/root/check_mk' + $agent_manage_package = true + $agent_manage_config = true + $agent_manage_service = true + # OS specific variables case $::osfamily { 'RedHat': { $httpd_service = 'httpd' + $agent_config_dir = '/etc/check-mk-agent/' } 'Debian': { $httpd_service = 'apache2' + $agent_config_dir = '/etc/check_mk/' + } + default: { + $httpd_service = 'httpd' + $agent_config_dir = '/etc/check-mk-agent/' } } } diff --git a/manifests/service.pp b/manifests/service.pp index f21bd51..5494eee 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,9 +1,9 @@ class check_mk::service ( $checkmk_service, - $httpd_service, + $httpd_service, ) { if ! defined(Service[$httpd_service]) { - service { "$httpd_service": + service { $httpd_service: ensure => 'running', enable => true, } diff --git a/metadata.json b/metadata.json index bd549c5..b2f9c23 100644 --- a/metadata.json +++ b/metadata.json @@ -38,7 +38,7 @@ ], "dependencies": [ - { "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 <2.0.0" }, + { "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 <2.2.0" }, { "name": "puppetlabs/stdlib", "version_requirement": ">= 2.3.0 <5.0.0" } ] }