-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#== Class: collectd::plugin::battery | ||
# | ||
# Class to manage battery write plugin for collectd | ||
# | ||
# Documentation: | ||
# https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_battery | ||
# | ||
# === Parameters | ||
# | ||
# [*ensure*] | ||
# Ensure param for collectd::plugin type. | ||
# Defaults to 'ensure' | ||
# | ||
# [*interval*] | ||
# Interval setting for the plugin | ||
# Defaults to undef | ||
# | ||
# [*values_percentage*] | ||
# When enabled, remaining capacity is reported as a percentage instead of raw | ||
# data (most likely in "Wh") | ||
# Defaults to false | ||
# | ||
# [*report_degraded*] | ||
# When set to true, the battery plugin will report three values: charged | ||
# (remaining capacity), discharged (difference between "last full capacity" | ||
# and "remaining capacity") and degraded (difference between "design capacity" | ||
# and "last full capacity"). Otherwise only the remaining capacity is | ||
# reported. | ||
# Defaults to false | ||
# | ||
# [*query_state_fs*] | ||
# When set to true, the battery plugin will only read statistics related to | ||
# battery performance as exposed by StateFS at /run/state. | ||
# Defaults to false | ||
# | ||
class collectd::plugin::battery ( | ||
Enum['present', 'absent'] $ensure = 'present', | ||
Optional[Integer] $interval = undef, | ||
Boolean $values_percentage = false, | ||
Boolean $report_degraded = false, | ||
Boolean $query_state_fs = false, | ||
) { | ||
|
||
include collectd | ||
|
||
collectd::plugin { 'battery': | ||
ensure => $ensure, | ||
interval => $interval, | ||
content => epp('collectd/plugin/battery.conf.epp'), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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"> | ||
ValuesPercentage false | ||
ReportDegraded false | ||
QueryStateFS false | ||
</Plugin> | ||
EOS | ||
|
||
is_expected.to compile.with_all_deps | ||
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' => true, | ||
'query_state_fs' => true | ||
} | ||
end | ||
|
||
it 'overrides defaults' do | ||
content = <<EOS | ||
# Generated by Puppet | ||
<LoadPlugin battery> | ||
Globals false | ||
</LoadPlugin> | ||
<Plugin "battery"> | ||
ValuesPercentage true | ||
ReportDegraded true | ||
QueryStateFS true | ||
</Plugin> | ||
EOS | ||
|
||
is_expected.to compile.with_all_deps | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Plugin "battery"> | ||
ValuesPercentage <%= $collectd::plugin::battery::values_percentage %> | ||
ReportDegraded <%= $collectd::plugin::battery::report_degraded %> | ||
QueryStateFS <%= $collectd::plugin::battery::query_state_fs %> | ||
</Plugin> |