diff --git a/README.md b/README.md index 9dbe10c3f..0a861f8a5 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ documentation for each plugin for configurable attributes. * `logfile` (see [collectd::plugin::logfile](#class-collectdpluginlogfile) below) * `virt` (see [collectd::plugin::virt](#class-collectdpluginvirt) below) * `lvm` (see [collectd::plugin::lvm](#class-collectdpluginlvm) below) +* `mcelog` (see [collectd::plugin::mcelog](#class-collectdpluginmcelog) below) * `memcached`(see [collectd::plugin::memcached](#class-collectdpluginmemcached) below ) * `memory`(see [collectd::plugin::memory](#class-collectdpluginmemory) below ) @@ -894,6 +895,16 @@ class { 'collectd::plugin::intel_pmu': } ``` +#### Class: `collectd::plugin::mcelog` + +```puppet +class { 'collectd::plugin::mcelog': + mceloglogfile => '/var/log/mcelog' + memory => true + mcelogclientsocket => '/var/run/mcelog-client' + persistentnotification => true +} +``` #### Class: `collectd::plugin::intel_rdt` ```puppet class { 'collectd::plugin::intel_rdt': diff --git a/manifests/plugin/mcelog.pp b/manifests/plugin/mcelog.pp new file mode 100644 index 000000000..248e0c10e --- /dev/null +++ b/manifests/plugin/mcelog.pp @@ -0,0 +1,18 @@ +# https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_mcelog +class collectd::plugin::mcelog ( + Enum['present', 'absent'] $ensure = 'present', + # Log file option and memory option are mutualy exclusive. + Optional[String] $mceloglogfile = undef, + Optional[Collectd::MCELOG::Memory] $memory = undef +) { + + include collectd + + collectd::plugin { 'mcelog': + ensure => $ensure, + content => epp('collectd/plugin/mcelog.conf.epp', { + 'mceloglogfile' => $mceloglogfile, + 'memory' => $memory + }), + } +} diff --git a/spec/classes/collectd_plugin_mcelog_spec.rb b/spec/classes/collectd_plugin_mcelog_spec.rb new file mode 100644 index 000000000..23e9bbc53 --- /dev/null +++ b/spec/classes/collectd_plugin_mcelog_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe 'collectd::plugin::mcelog', type: :class do + on_supported_os(baseline_os_hash).each do |os, facts| + context "on #{os} " do + let :facts do + facts + end + + it { is_expected.to compile.with_all_deps } + + options = os_specific_options(facts) + context ':ensure => present, default params' do + it "Will create #{options[:plugin_conf_dir]}/10-mcelog.conf" do + is_expected.to contain_file('mcelog.load').with( + ensure: 'present', + path: "#{options[:plugin_conf_dir]}/10-mcelog.conf" + ) + end + end + + context ':ensure => :mceloglogfile => true' do + let :params do + { + mceloglogfile: '/var/log/mcelog' + } + end + + it "Will create #{options[:plugin_conf_dir]}/10-mcelog.conf" do + is_expected.to contain_file('mcelog.load').with( + ensure: 'present', + path: "#{options[:plugin_conf_dir]}/10-mcelog.conf" + ) + end + it { is_expected.to contain_file('mcelog.load').with(content: %r{McelogLogfile "/var/log/mcelog"}) } + end + + context ':ensure => :memory => true' do + let :params do + { + memory: { + 'mcelogclientsocket' => '/var/run/mcelog-client', + 'persistentnotification' => true + } + } + end + + it "Will create #{options[:plugin_conf_dir]}/10-mcelog.conf" do + is_expected.to contain_file('mcelog.load').with( + ensure: 'present', + path: "#{options[:plugin_conf_dir]}/10-mcelog.conf" + ) + end + it { is_expected.to contain_file('mcelog.load').with(content: %r{}) } + it { is_expected.to contain_file('mcelog.load').with(content: %r{McelogClientSocket "/var/run/mcelog-client"}) } + it { is_expected.to contain_file('mcelog.load').with(content: %r{PersistentNotification true}) } + end + end + end +end diff --git a/templates/plugin/mcelog.conf.epp b/templates/plugin/mcelog.conf.epp new file mode 100644 index 000000000..4cfa4c70b --- /dev/null +++ b/templates/plugin/mcelog.conf.epp @@ -0,0 +1,20 @@ +<%- | Optional[String] $mceloglogfile = undef, + Optional $memory = undef, +| -%> + +<% if $mceloglogfile { %> +McelogLogfile "<%= $mceloglogfile %>" +<% } -%> +<% if $collectd::plugin::mcelog::memory { %> + +<% $collectd::plugin::mcelog::memory.keys.sort.each |$key| { -%> +<% if $key == 'mcelogclientsocket' { -%> +McelogClientSocket "<%= $collectd::plugin::mcelog::memory[$key] %>" +<% } -%> +<% if $key == 'persistentnotification' { -%> +PersistentNotification <%= $collectd::plugin::mcelog::memory[$key] %> +<% } -%> +<% } -%> + +<% } -%> + diff --git a/types/mcelog/memory.pp b/types/mcelog/memory.pp new file mode 100644 index 000000000..360c9a39c --- /dev/null +++ b/types/mcelog/memory.pp @@ -0,0 +1,5 @@ +# https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_mcelog +type Collectd::MCELOG::Memory = Struct[{ + NotUndef['mcelogclientsocket'] => String[1], + NotUndef['persistentnotification'] => Boolean, +}]