diff --git a/manifests/plugin/disk.pp b/manifests/plugin/disk.pp index 9fadec6ab..7aae1fec1 100644 --- a/manifests/plugin/disk.pp +++ b/manifests/plugin/disk.pp @@ -12,7 +12,7 @@ include collectd - if $facts['os']['family'] == 'RedHat' { + if $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'],'8') >= 0 { if $manage_package != undef { $_manage_package = $manage_package } else { diff --git a/manifests/plugin/write_http.pp b/manifests/plugin/write_http.pp index 49a6d4bea..2057cfd73 100644 --- a/manifests/plugin/write_http.pp +++ b/manifests/plugin/write_http.pp @@ -1,8 +1,14 @@ -# https://collectd.org/wiki/index.php/Plugin:Write_HTTP +# @summary Enable write_http plugin +# +# @see https://collectd.org/wiki/index.php/Plugin:Write_HTTP +# +# @parameter Manage a collectd-write_http package? If undef a suitable value per OS will be chosen. +# class collectd::plugin::write_http ( Enum['present', 'absent'] $ensure = 'present', Hash[String, Hash[String, Scalar]] $nodes = {}, - Hash[String, Hash[String, Scalar]] $urls = {} + Hash[String, Hash[String, Scalar]] $urls = {}, + Optional[Boolean] $manage_package = undef, ) { include collectd @@ -11,6 +17,21 @@ fail('Only one of nodes or urls is supposed to be defined') } + if $manage_package !~ Undef { + $_manage_package = $manage_package + } else { + if $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'],'8') >= 0 { + $_manage_package = true + } else { + $_manage_package = false + } + } + if $_manage_package { + package{'collectd-write_http': + ensure => $ensure, + } + } + $endpoints = merge($nodes, $urls) collectd::plugin { 'write_http': ensure => $ensure, diff --git a/spec/acceptance/class_plugin_disk_spec.rb b/spec/acceptance/class_plugin_disk_spec.rb new file mode 100644 index 000000000..ba07b258b --- /dev/null +++ b/spec/acceptance/class_plugin_disk_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper_acceptance' + +describe 'collectd::plugin::disk class' do + context 'basic parameters' do + # Using puppet_apply as a helper + it 'works idempotently with no errors' do + pp = <<-EOS + class{'collectd': + utils => true, + } + class{'collectd::plugin::disk': } + # Add one write plugin to keep logs quiet + class{'collectd::plugin::csv':} + # Create a socket to query + class{'collectd::plugin::unixsock': + socketfile => '/var/run/collectd-sock', + socketgroup => 'root', + } + + EOS + # Run 3 times since the collectd_version + # fact is impossible until collectd is + # installed. + apply_manifest(pp, catch_failures: false) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + # Wait to get some data + shell('sleep 10') + end + + describe service('collectd') do + it { is_expected.to be_running } + end + + describe command('collectdctl -s /var/run/collectd-sock listval') do + its(:exit_status) { is_expected.to eq 0 } + # the reason debian does not report disk metrics on docker images despite the + # module being loaded is an exercise for the reader. + if fact('osfamily') != 'Debian' + its(:stdout) { is_expected.to match %r{disk_time} } + end + end + end +end diff --git a/spec/acceptance/class_plugin_write_http_spec.rb b/spec/acceptance/class_plugin_write_http_spec.rb new file mode 100644 index 000000000..85c4ddd91 --- /dev/null +++ b/spec/acceptance/class_plugin_write_http_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper_acceptance' + +describe 'collectd::plugin::write_http class' do + context 'basic parameters' do + # Using puppet_apply as a helper + it 'works idempotently with no errors' do + pp = <<-EOS + class{'collectd':} + class { 'collectd::plugin::write_http': + nodes => { + 'collect1' => { 'url' => 'collect1.example.org', 'format' => 'JSON' }, + 'collect2' => { 'url' => 'collect2.example.org'}, + } + } + EOS + # Run 3 times since the collectd_version + # fact is impossible until collectd is + # installed. + apply_manifest(pp, catch_failures: false) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + # Wait to get some data + shell('sleep 10') + end + + describe service('collectd') do + it { is_expected.to be_running } + end + end +end diff --git a/spec/classes/collectd_plugin_disk_spec.rb b/spec/classes/collectd_plugin_disk_spec.rb index 071abd88a..5e795f843 100644 --- a/spec/classes/collectd_plugin_disk_spec.rb +++ b/spec/classes/collectd_plugin_disk_spec.rb @@ -108,8 +108,8 @@ end end - case facts[:os]['family'] - when 'RedHat' + case [facts[:os]['family'], facts[:os]['release']['major']] + when %w[RedHat 8] context ':manage_package => undef with collectd 5.5 and up' do let :facts do facts.merge(collectd_version: '5.5') diff --git a/spec/classes/collectd_plugin_write_http_spec.rb b/spec/classes/collectd_plugin_write_http_spec.rb index ffad3768f..f8686a962 100644 --- a/spec/classes/collectd_plugin_write_http_spec.rb +++ b/spec/classes/collectd_plugin_write_http_spec.rb @@ -29,6 +29,12 @@ content: "#\ Generated by Puppet\n\n Globals false\n\n\n\n \n\n Format \"JSON\"\n \n\n\n\n" ) end + case [facts[:os]['family'], facts[:os]['release']['major']] + when %w[RedHat 8] + it { is_expected.to contain_package('collectd-write_http') } + else + it { is_expected.not_to contain_package('collectd-write_http') } + end end context ':ensure => present and :nodes => { \'collectd\' => { \'url\' => \'collectd.org.1\', \'format\' => \'JSON\'}}' do