Newer
Older
### Sal Batteryhealth Plugin
This plugin shows a coarse histogram of macbook batteryhealth, calculated by dividing `max_cap` by `design_cap`. To work it needs a custom puppet fact.
### Example fact implementation
```ruby
Facter.add(:mac_macbook_batteryhealth) do
confine :mac_mobile => ['yes']
setcode do
cmd = "ioreg -c AppleSmartBattery -r"
output = Facter::Core::Execution.execute(cmd).strip
max_cap = design_cap = 0
begin
output.split("\n").each do |line|
case line
when /BatteryData/
next
when /"DesignCapacity"/
design_cap = line.split('=')[1].strip.to_f
when /"MaxCapacity"/
max_cap = line.split('=')[1].strip.to_f
else
end
end
health = (100 * max_cap / design_cap).round
health > 100 ? 100 : health
rescue
nil
end
end
end
```