Skip to content

Commit

Permalink
New utils parameter to install collectdctl
Browse files Browse the repository at this point in the history
On some operating systems `collectdctl`, `collectd-nagios`
is contained in a seperate sub package, typically `collectd-utils`

Setting `utils` to `true` will install this sub package if it exists
for an operating system.
  • Loading branch information
traylenator committed Mar 10, 2020
1 parent eb8cfee commit d4d70dd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
7 changes: 7 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# @summary installs and configures collectd
# @example Install collectd utilities
# class{'collectd':
# utils => true,
# }
#
# @param utils Install collectd utilities package containing collectdctl, collectd-nagios
class collectd (
Boolean $autoloadplugin = $collectd::params::autoloadplugin,
String $collectd_hostname = $collectd::params::collectd_hostname,
Expand Down Expand Up @@ -36,6 +42,7 @@
Optional[Integer] $write_queue_limit_high = $collectd::params::write_queue_limit_high,
Optional[Integer] $write_queue_limit_low = $collectd::params::write_queue_limit_low,
Integer[1] $write_threads = $collectd::params::write_threads,
Boolean $utils = $collectd::params::utils,
) inherits collectd::params {

$collectd_version_real = pick_default($facts['collectd_version'], $minimum_version)
Expand Down
11 changes: 10 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#
# @summary installs collectd
# @api private
class collectd::install {

assert_private()
Expand All @@ -10,4 +11,12 @@
install_options => $collectd::package_install_options,
}
}

if $collectd::utils and ( $facts['os']['family'] == 'Debian' or
( $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'],'8') >= 0 )) {
package{'collectd-utils':
ensure => $collectd::package_ensure,
}
}

}
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
$plugin_conf_dir_mode = '0750'
$ci_package_repo = undef
$package_keyserver = 'keyserver.ubuntu.com'
$utils = false

case $facts['kernel'] {
'OpenBSD': { $has_wordexp = false }
Expand Down
13 changes: 5 additions & 8 deletions spec/acceptance/class_plugin_python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ class { 'collectd::plugin::csv':}
context 'trivial pip module connect-time' do
it 'works idempotently with no errors' do
pp = <<-EOS
if $facts['os']['family'] == 'Debian' or ( $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8' ) {
# for collectdctl command
package{'collectd-utils':
ensure => present,
}
}
if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8' {
$_python_pip_package = 'python3-pip'
$_pip_provider = 'pip3'
Expand All @@ -49,6 +43,9 @@ class { 'collectd::plugin::csv':}
require => Package[$_python_pip_package],
before => Service['collectd'],
}
class{'collectd':
utils => true,
}
class{'collectd::plugin::python':
logtraces => true,
interactive => false,
Expand Down Expand Up @@ -84,8 +81,7 @@ class { 'collectd::plugin::csv':}
it 'works idempotently with no errors' do
pp = <<-EOS
if $facts['os']['family'] == 'Debian' {
# for collectdctl command
package{['collectd-utils','python-dbus']:
package{'python-dbus':
ensure => present,
}
}
Expand Down Expand Up @@ -116,6 +112,7 @@ class { 'collectd::plugin::csv':}
before => Service['collectd'],
}
class{'collectd':
utils => true,
typesdb => ['/usr/share/collectd/types.db'],
}
class{'collectd::plugin::python':
Expand Down
17 changes: 17 additions & 0 deletions spec/classes/collectd_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@
end
end

context 'when utils false' do
let(:params) { { utils: false } }

it { is_expected.not_to contain_package('collectd-utils') }
end

context 'when utils true' do
let(:params) { { utils: true } }

case "#{facts[:os]['family']}-#{facts[:os]['release']['major']}"
when %r{^Debian-.+}, 'RedHat-8'
it { is_expected.to contain_package('collectd-utils') }
else
it { is_expected.not_to contain_package('collectd-utils') }
end
end

context 'when purge_config is enabled' do
let(:params) { { purge_config: true } }

Expand Down

0 comments on commit d4d70dd

Please sign in to comment.