Skip to content

Commit

Permalink
write_http expected to be own package on CentOS 8
Browse files Browse the repository at this point in the history
As of CentOS 8 the write_http is in its own subpackage
so must be installed on CentOS 8.
  • Loading branch information
traylenator committed Mar 10, 2020
1 parent d4d70dd commit 4c35c1c
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 5 deletions.
2 changes: 1 addition & 1 deletion manifests/plugin/disk.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 23 additions & 2 deletions manifests/plugin/write_http.pp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
46 changes: 46 additions & 0 deletions spec/acceptance/class_plugin_disk_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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.
# For CentOS 7 it works on my laptop but not in travis.
# disk plugin is probably very sensitive to environment.
if fact('os.family') == 'Redhat' && fact('os.release.major') == '8'
its(:stdout) { is_expected.to match %r{disk_time} }
end
end
end
end
30 changes: 30 additions & 0 deletions spec/acceptance/class_plugin_write_http_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions spec/classes/collectd_plugin_disk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 6 additions & 0 deletions spec/classes/collectd_plugin_write_http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
content: "#\ Generated by Puppet\n<LoadPlugin write_http>\n Globals false\n</LoadPlugin>\n\n<Plugin \"write_http\">\n <URL \"collectd.org.1\">\n\n Format \"JSON\"\n </URL>\n\n</Plugin>\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
Expand Down

0 comments on commit 4c35c1c

Please sign in to comment.