Skip to content

Commit

Permalink
plugin: add battery plugin
Browse files Browse the repository at this point in the history
this change adds the battery plugin
  • Loading branch information
sileht committed May 25, 2018
1 parent cd9486e commit bf7fa66
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
17 changes: 17 additions & 0 deletions manifests/plugin/battery.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://collectd.org/wiki/index.php/Plugin:Uptime
class collectd::plugin::battery (
$ensure = 'present',
$interval = undef,
Optional[Boolean] $values_percentage = undef,
Optional[Boolean] $report_degraded = undef,
Optional[Boolean] $query_state_fs = undef,
) {

include ::collectd

collectd::plugin { 'battery':
ensure => $ensure,
interval => $interval,
content => template('collectd/plugin/battery.conf.erb'),
}
}
65 changes: 65 additions & 0 deletions spec/classes/collectd_plugin_battery_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'spec_helper'

describe 'collectd::plugin::battery', type: :class do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
let :facts do
facts
end

options = os_specific_options(facts)
context 'default' do
it 'defaults' do
content = <<EOS
# Generated by Puppet
<LoadPlugin battery>
Globals false
</LoadPlugin>
<Plugin "battery">
</Plugin>
EOS

is_expected.to contain_file('battery.load').with(
content: content,
path: "#{options[:plugin_conf_dir]}/10-battery.conf"
)
end
end

options = os_specific_options(facts)
context 'multiple instances' do
let :params do
{
'values_percentage' => true,
'report_degraded' => false,
'query_state_fs' => true
}
end

it 'overrides defaults' do
content = <<EOS
# Generated by Puppet
<LoadPlugin battery>
Globals false
</LoadPlugin>
<Plugin "battery">
ValuesPercentage true
ReportDegraded false
QueryStateFS true
</Plugin>
EOS

is_expected.to contain_class('collectd')
is_expected.to contain_file('battery.load').with(
content: content,
path: "#{options[:plugin_conf_dir]}/10-battery.conf"
)
end
end
end
end
end
11 changes: 11 additions & 0 deletions templates/plugin/battery.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Plugin "battery">
<% if defined? @values_percentage -%>
ValuesPercentage <%= @values_percentage %>
<% end -%>
<% if defined? @report_degraded -%>
ReportDegraded <%= @report_degraded %>
<% end -%>
<% if defined? @query_state_fs -%>
QueryStateFS <%= @query_state_fs %>
<% end -%>
</Plugin>

0 comments on commit bf7fa66

Please sign in to comment.