class Arborist::Monitor::SNMP::UPS::Battery
Checks for UPS battery health.
Checks the available battery percentage, if the UPS is on battery, and the temperature of the battery.
Constants
- BATTERY_STATUS
Human-readable translations for battery status OID.
- OIDS
OIDS
for discovering ups status.
Public Class Methods
node_properties()
click to toggle source
Return the properties used by this monitor.
# File lib/arborist/monitor/snmp/ups/battery.rb, line 50 def self::node_properties return USED_PROPERTIES end
run( nodes )
click to toggle source
Class run
creates a new instance and immediately runs it.
# File lib/arborist/monitor/snmp/ups/battery.rb, line 57 def self::run( nodes ) return new.run( nodes ) end
Public Instance Methods
run( nodes )
click to toggle source
Perform the monitoring checks.
Calls superclass method
Arborist::Monitor::SNMP#run
# File lib/arborist/monitor/snmp/ups/battery.rb, line 64 def run( nodes ) super do |host, snmp| self.check_battery( host, snmp ) end end
Protected Instance Methods
check_battery( host, snmp )
click to toggle source
Parse SNMP-provided information and alert based on thresholds.
# File lib/arborist/monitor/snmp/ups/battery.rb, line 103 def check_battery( host, snmp ) info = self.format_battery( snmp ) config = self.identifiers[ host ].last['config'] || {} cap_warn = config[ 'capacity_warn_at' ] || self.class.capacity_warn_at temp_warn = config[ 'temperature_warn_at' ] || self.class.temperature_warn_at in_use = info.dig( :battery, :in_use ) status = info.dig( :battery, :status ) capacity = info.dig( :battery, :capacity ) temperature = info.dig( :battery, :temperature ) warnings = [] if in_use mins = info.dig( :battery, :minutes_remaining ) || "(unknown)" warnings << "UPS on battery - %s minute(s) remaning." % [ mins ] end warnings << BATTERY_STATUS[ status ] if status != 2 warnings << "Battery remaining capacity %0.1f%% less than %0.1f percent" % [ capacity, cap_warn ] if capacity && capacity <= cap_warn warnings << "Battery temperature %dC greater than %dC" % [ temperature, temp_warn ] if temperature && temperature >= temp_warn info[ :warning ] = warnings.join( "\n" ) unless warnings.empty? self.results[ host ] = info end
format_battery( snmp )
click to toggle source
Query SNMP and format information into a hash.
# File lib/arborist/monitor/snmp/ups/battery.rb, line 77 def format_battery( snmp ) info = {} # basic info that's always available info[ :status ] = snmp.get( oid: OIDS[:battery_status] ) info[ :capacity ] = snmp.get( oid: OIDS[:est_charge_remaining] ) rescue nil info[ :temperature ] = snmp.get( oid: OIDS[:battery_temperature] ) rescue nil info[ :minutes_remaining ] = snmp.get( oid: OIDS[:est_minutes_remaining] ) rescue nil # don't report voltage if the UPS doesn't voltage = snmp.get( oid: OIDS[:battery_voltage] ) rescue nil info[ :voltage ] = voltage / 10 if voltage # don't report current if the UPS doesn't current = snmp.get( oid: OIDS[:battery_current] ) rescue nil info[ :current ] = current/10 if current # see if we are on battery info[ :seconds_on_battery ] = snmp.get( oid: OIDS[:seconds_on_battery] ) rescue 0 info[ :in_use ] = ( info[ :seconds_on_battery ] != 0 ) return { battery: info.compact } end