Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add params to conditionally manage package, install & service #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
56 changes: 29 additions & 27 deletions manifests/agent/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
}
}
}
Expand Down
78 changes: 40 additions & 38 deletions manifests/agent/install.pp
Original file line number Diff line number Diff line change
@@ -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'],
}
}
}
}
6 changes: 1 addition & 5 deletions manifests/agent/mrpe.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
28 changes: 15 additions & 13 deletions manifests/agent/service.pp
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}
}
10 changes: 10 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
}
}
}
4 changes: 2 additions & 2 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
]
}