diff --git a/README.md b/README.md index 3f0c4b49f..9b69a4ef0 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ documentation for each plugin for configurable attributes. * `target_v5upgrade` (see [collectd::plugin::target_v5upgrade](#class-collectdplugintarget_v5upgrade) below) * `tcpconns` (see [collectd::plugin::tcpconns](#class-collectdplugintcpconns) below) +* `thermal` (see [collectd::plugin::thermal](#class-collectdpluginthermal) below) * `unixsock` (see [collectd::plugin::unixsock](#class-collectdpluginunixsock) below) * `uptime` (see [collectd::plugin::uptime](#class-collectdpluginuptime) below) * `users` (see [collectd::plugin::users](#class-collectdpluginusers) below) @@ -1532,7 +1533,16 @@ collectd::plugin::tail::file { 'exim-log': } ``` -#### Class: `collectd::plugin::unixsock` +####Class: `collectd::plugin::thermal` + +```puppet +class { '::collectd::plugin::thermal': + devices => ['foo0'], + ignoreselected => false, +} +``` + +####Class: `collectd::plugin::unixsock` ```puppet class {'collectd::plugin::unixsock': diff --git a/examples/plugins/thermal.pp b/examples/plugins/thermal.pp new file mode 100644 index 000000000..d4278f94e --- /dev/null +++ b/examples/plugins/thermal.pp @@ -0,0 +1,6 @@ +include ::collectd + +class { '::collectd::plugin::thermal': + device => ['foo0'], + ignoreselected => false, +} diff --git a/manifests/plugin/thermal.pp b/manifests/plugin/thermal.pp new file mode 100644 index 000000000..86d6ea500 --- /dev/null +++ b/manifests/plugin/thermal.pp @@ -0,0 +1,19 @@ +# https://collectd.org/wiki/index.php/Plugin:thermal +class collectd::plugin::thermal ( + $devices = [], + $ensure = 'present', + $ignoreselected = false, + $interval = undef, +) { + + include ::collectd + + validate_array($devices) + validate_bool($ignoreselected) + + collectd::plugin { 'thermal': + ensure => $ensure, + content => template('collectd/plugin/thermal.conf.erb'), + interval => $interval, + } +} diff --git a/spec/classes/collectd_plugin_thermal_spec.rb b/spec/classes/collectd_plugin_thermal_spec.rb new file mode 100644 index 000000000..39aa910a1 --- /dev/null +++ b/spec/classes/collectd_plugin_thermal_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe 'collectd::plugin::thermal', type: :class do + on_supported_os.each do |os, facts| + context "on #{os} " do + let :facts do + facts + end + options = os_specific_options(facts) + context ':ensure => present' do + let :params do + { + devices: ['foo0'], + ensure: 'present' + } + end + it { is_expected.to contain_collectd__plugin('thermal') } + it 'Will create 10-thermal.conf' do + is_expected.to contain_file('thermal.load').with( + ensure: 'present', + path: "#{options[:plugin_conf_dir]}/10-thermal.conf", + content: "#\ Generated by Puppet\n\n Globals false\n\n\n\n Device \"foo0\"\n IgnoreSelected false\n\n\n" + ) + end + end + + context ':ensure => absent' do + let :params do + { ensure: 'absent' } + end + it 'Will not create 10-thermal.conf' do + is_expected.to contain_file('thermal.load').with( + ensure: 'absent', + path: "#{options[:plugin_conf_dir]}/10-thermal.conf" + ) + end + end + + context ':devices is not an array' do + let :params do + { devices: 'foo0' } + end + it 'Will raise an error about :devices not being an array' do + is_expected.to compile.and_raise_error(%r{String}) + end + end + end + end +end diff --git a/templates/plugin/thermal.conf.erb b/templates/plugin/thermal.conf.erb new file mode 100644 index 000000000..e0022709f --- /dev/null +++ b/templates/plugin/thermal.conf.erb @@ -0,0 +1,8 @@ +<% if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '4.5']) >= 0) -%> + +<% @devices.each do |device| -%> + Device "<%= device %>" +<% end -%> + IgnoreSelected <%= @ignoreselected %> + +<% end -%>