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

Drop EOL CentOS 6/xinetd support #43

Merged
merged 4 commits into from
Dec 16, 2021
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Originally by [erwbgy](https://forge.puppet.com/erwbgy), then forked by [gnúbil

## Setup
The module has been tested with:
* CentOS 6 and 7;
* CentOS 7;
* Debian 9;
* Puppet version 5 and Puppet 6;
* check_mk version 1.5.x.
Expand Down Expand Up @@ -57,7 +57,7 @@ htpasswd -i ~/etc/passwd cmkadmin
The following example changes the default site name from 'monitoring' to 'differentsitename'
```puppet
class { 'check_mk':
site => 'differentsitename',
monitoring_site => 'differentsitename',
}
```

Expand Down
4 changes: 0 additions & 4 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# @param mrpe_checks A hash containing mrpe command that will be passed to the mrpe defined type.
# @param encryption_secret A secret that will be used to encrypt communication with the master.
# @param config_dir The config directory for the agent.
# @param use_xinetd Configure the service using the older xinetd approach. Defaults to true on systems missing systemd, and false otherwise.
# @param check_mk_xinetd_path The path to the xinetd.d config file for check_mk
# @param ip_whitelist The list of IP addresses that are allowed to retrieve check_mk data. (Note that localhost is always allowed to connect.) By default any IP can connect.
# @param user The user that the agent runs as.
# @param group The group that the agent runs as.
Expand All @@ -26,8 +24,6 @@
Optional[String[1]] $service_name = 'check_mk',
Hash $mrpe_checks = {},
Optional[String[1]] $encryption_secret = undef,
Boolean $use_xinetd = !fact('systemd'),
Stdlib::Absolutepath $check_mk_xinetd_path = '/etc/xinetd.d/check_mk',
Array[Stdlib::IP::Address] $ip_whitelist = [],
Stdlib::Absolutepath $server_dir = '/usr/bin',
Boolean $use_cache = false,
Expand Down
89 changes: 28 additions & 61 deletions manifests/agent/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#
class check_mk::agent::config (
Optional[String] $encryption_secret = $check_mk::agent::encryption_secret,
Boolean $use_xinetd = $check_mk::agent::use_xinetd,
Stdlib::Absolutepath $check_mk_xinetd_path = $check_mk::agent::check_mk_xinetd_path,
Array[Stdlib::IP::Address] $ip_whitelist = $check_mk::agent::ip_whitelist,
Stdlib::Absolutepath $server_dir = $check_mk::agent::server_dir,
Boolean $use_cache = $check_mk::agent::use_cache,
Expand All @@ -16,12 +14,8 @@
Stdlib::Absolutepath $config_dir = $check_mk::agent::config_dir,
String[1] $service_name = $check_mk::agent::service_name,
) inherits check_mk::agent {
if $use_xinetd == false and fact('systemd') == false {
fail('Your system doesn\'t appear to support systemd, you must use xinetd instead')
}

if $use_xinetd == false and versioncmp(fact('systemd_version'),'235') < 0 {
unless $ip_whitelist.empty { fail('ip_whitelist is only supported when using xinetd or systemd version 235 and later') }
if versioncmp(fact('systemd_version'),'235') < 0 {
unless $ip_whitelist.empty { fail('ip_whitelist is only supported when using systemd version 235 and later') }
}

if $encryption_secret {
Expand Down Expand Up @@ -53,59 +47,32 @@
$only_from = ['127.0.0.1'] + $ip_whitelist
}

if $use_xinetd {
$only_from_changes = ['rm service/only_from'] + $only_from.map |$ip| {
"set service/only_from/value[last()+1] ${ip}"
}

$server_changes = ["set service/server ${server}"]
$port_changes = ["set service/port ${port}"]
$user_changes = ["set service/user ${user}", "set service/group ${group}"]
$disable_changes = ['set service/disable no']

# LC_ALL environment variable must be unset to prevent a bash warning ending up in the xinetd stream
# output and breaking the $encryption_secret feature.
$env_changes = ['rm service/env', 'set service/env/value[last()+1] "LC_ALL="']

augeas { 'check_mk xinetd config':
incl => $check_mk_xinetd_path,
lens => 'xinetd.lns',
changes => $only_from_changes + $server_changes + $port_changes + $user_changes + $disable_changes + $env_changes,
}
} else {
augeas { 'Disable check_mk xinetd':
incl => $check_mk_xinetd_path,
lens => 'xinetd.lns',
changes => ['set service/disable yes'],
}

$ip_address_allow = versioncmp(fact('systemd_version'),'235') ? {
-1 => undef, # Don't set the parameter if the version of systemd doesn't support it
default => $only_from,
}
$ip_address_allow = versioncmp(fact('systemd_version'),'235') ? {
-1 => undef, # Don't set the parameter if the version of systemd doesn't support it
default => $only_from,
}

systemd::dropin_file { 'check_mk socket overrides':
filename => 'puppet.conf',
unit => "${service_name}.socket",
content => epp(
'check_mk/agent/check_mk.socket-drop-in.epp',
{
'port' => $port,
'ip_address_allow' => $ip_address_allow,
},
),
}
systemd::dropin_file { 'check_mk unit overrides':
filename => 'puppet.conf',
unit => "${service_name}@.service",
content => epp(
'check_mk/agent/check_mk.service-drop-in.epp',
{
'server' => $server,
'user' => $user,
'group' => $group,
},
),
}
systemd::dropin_file { 'check_mk socket overrides':
filename => 'puppet.conf',
unit => "${service_name}.socket",
content => epp(
'check_mk/agent/check_mk.socket-drop-in.epp',
{
'port' => $port,
'ip_address_allow' => $ip_address_allow,
},
),
}
systemd::dropin_file { 'check_mk unit overrides':
filename => 'puppet.conf',
unit => "${service_name}@.service",
content => epp(
'check_mk/agent/check_mk.service-drop-in.epp',
{
'server' => $server,
'user' => $user,
'group' => $group,
},
),
}
}
41 changes: 3 additions & 38 deletions manifests/agent/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,10 @@
# @api private
#
class check_mk::agent::service (
Boolean $use_xinetd = $check_mk::agent::use_xinetd,
String $service_name = $check_mk::agent::service_name,
) {
if $use_xinetd {
ensure_packages(['xinetd'])
Package['xinetd'] ~> Service['xinetd']

service { "${service_name}.socket":
ensure => 'stopped',
enable => false,
notify => Service['xinetd'],
}

if ! defined(Service['xinetd']) {
service { 'xinetd':
ensure => 'running',
enable => true,
hasrestart => true,
restart => 'kill -USR2 `pidof xinetd`',
}
}
} else {
if ! defined(Service['xinetd']) {
# We need an xinetd service in the catalog that we can notify to reload,
# but we otherwise don't want to manage the state of xinetd when using
# systemd sockets for check-mk-agent
#
# Note, if the service isn't running, (eg. because it's not even installed)
# puppet will skip trying to do a restart.
# This means we don't have to force the doomed `kill` command to return 0.
service { 'xinetd':
hasrestart => true,
restart => 'kill -USR2 `pidof xinetd` && sleep 1',
}
}
service { "${service_name}.socket":
ensure => 'running',
enable => true,
require => Service['xinetd'],
}
service { "${service_name}.socket":
ensure => 'running',
enable => true,
}
}
20 changes: 10 additions & 10 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
#

class check_mk::config (
String $site,
String $monitoring_site,
Optional[Hash] $host_groups = undef,
Optional[Array] $all_hosts_static = undef,
) {
$etc_dir = "/omd/sites/${site}/etc"
$bin_dir = "/omd/sites/${site}/bin"
$etc_dir = "/omd/sites/${monitoring_site}/etc"
$bin_dir = "/omd/sites/${monitoring_site}/bin"
file { "${etc_dir}/nagios/local":
ensure => directory,
owner => $site,
group => $site,
owner => $monitoring_site,
group => $monitoring_site,
}

file_line { 'nagios-add-check_mk-cfg_dir':
Expand All @@ -25,8 +25,8 @@
}

concat { "${etc_dir}/check_mk/main.mk":
owner => $site,
group => $site,
owner => $monitoring_site,
group => $monitoring_site,
mode => '0644',
}

Expand All @@ -42,7 +42,7 @@
content => template('check_mk/all_hosts_static.erb'),
}

# # local list of hosts is in /omd/sites/${site}/etc/check_mk/all_hosts_static and is appended
# # local list of hosts is in /omd/sites/${monitoring_site}/etc/check_mk/all_hosts_static and is appended
concat::fragment { 'all-hosts-static':
source => "${etc_dir}/check_mk/all_hosts_static",
target => "${etc_dir}/check_mk/main.mk",
Expand Down Expand Up @@ -84,7 +84,7 @@
}
}

# # local config is in /omd/sites/${site}/etc/check_mk/main.mk.local and is appended
# # local config is in /omd/sites/${monitoring_site}/etc/check_mk/main.mk.local and is appended
file { "${etc_dir}/check_mk/main.mk.local":
ensure => file,
owner => 'root',
Expand All @@ -99,7 +99,7 @@
}

exec { 'check_mk-reload':
command => "/bin/su -l -c '${bin_dir}/check_mk --reload' ${site}",
command => "/bin/su -l -c '${bin_dir}/check_mk --reload' ${monitoring_site}",
refreshonly => true,
}

Expand Down
16 changes: 8 additions & 8 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
$host_groups = $check_mk::params::host_groups,
$httpd_service = $check_mk::params::httpd_service,
$package = $check_mk::params::package,
$site = $check_mk::params::site,
$monitoring_site = $check_mk::params::monitoring_site,
$workspace = $check_mk::params::workspace,
) inherits check_mk::params {
class { 'check_mk::install':
filestore => $filestore,
package => $package,
site => $site,
workspace => $workspace,
filestore => $filestore,
package => $package,
monitoring_site => $monitoring_site,
workspace => $workspace,
}
class { 'check_mk::config':
host_groups => $host_groups,
site => $site,
require => Class['check_mk::install'],
host_groups => $host_groups,
monitoring_site => $monitoring_site,
require => Class['check_mk::install'],
}
class { 'check_mk::service':
checkmk_service => $checkmk_service,
Expand Down
6 changes: 3 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

class check_mk::install (
String $site,
String $monitoring_site,
Stdlib::Absolutepath $workspace,
Optional[String] $filestore = undef,
Optional[Pattern[/^(check-mk-(\w*))(-|_)(\d*\.\d*\.\d*p\d*).+\.(\w+)$/]] $package = undef,
Expand Down Expand Up @@ -60,9 +60,9 @@
before => Exec['omd-create-site'],
}
}
$etc_dir = "/omd/sites/${site}/etc"
$etc_dir = "/omd/sites/${monitoring_site}/etc"
exec { 'omd-create-site':
command => "/usr/bin/omd create ${site}",
command => "/usr/bin/omd create ${monitoring_site}",
creates => $etc_dir,
}
}
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$package = 'check-mk-raw-1.5.0p7-el7-38.x86_64.rpm'
$filestore = undef
$host_groups= undef
$site = 'monitoring'
$monitoring_site = 'monitoring'
$workspace = '/root/check_mk'

# OS specific variables
Expand Down
2 changes: 0 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
{
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"6",
"7"
]
},
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"6",
"7"
]
},
Expand Down
39 changes: 5 additions & 34 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
describe 'check_mk class' do
packagename = case fact('os.family')
when 'Debian'
'check-mk-raw-1.5.0p15_0.' + fact('os.distro.codename') + '_amd64.deb'
'check-mk-raw-2.0.0p1_0.' + fact('os.distro.codename') + '_amd64.deb'
when 'RedHat'
'check-mk-raw-1.5.0p15-el' + fact('os.release.major') + '-38.x86_64.rpm'
'check-mk-raw-2.0.0p1-el' + fact('os.release.major') + '-38.x86_64.rpm'
end
packagename_agent = case fact('os.family')
when 'Debian'
'check-mk-agent_1.5.0p15-1_all.deb'
'check-mk-agent_2.0.0p1-1_all.deb'
when 'RedHat'
'check-mk-agent-1.5.0p15-1.noarch.rpm'
'check-mk-agent-2.0.0p1-1.noarch.rpm'
end

context 'minimal parameters' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'check_mk':
filestore => 'https://mathias-kettner.de/support/1.5.0p15/',
filestore => 'https://download.checkmk.com/checkmk/2.0.0p1/',
package => '#{packagename}',
}
EOS
Expand Down Expand Up @@ -63,35 +63,6 @@ class { 'check_mk::agent':
its(:stderr) { is_expected.to eq '' }
end
end
context 'force agent to use xinetd' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'check_mk::agent':
use_xinetd => true,
filestore => 'http://127.0.0.1/monitoring/check_mk/agents/',
package => '#{packagename_agent}',
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe service('xinetd') do
it { is_expected.to be_running }
end

describe port(6556) do
it { is_expected.to be_listening }
end

describe command('ncat --recv-only 127.0.0.1 6556') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match %r{<<<check_mk>>>} }
its(:stderr) { is_expected.to eq '' }
end
end
context 'with encryption_secret' do
it 'works idempotently with no errors' do
pp = <<-EOS
Expand Down
Loading