arborist-snmp 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 968e138781d430383f877e95e7eff1450f79cd76f5bb0aa1caa529759c9c8cd8
4
- data.tar.gz: 9fd01fba144b94cf1439ed7b93df52762f7467ad29666ee05ce009880e74a7bc
3
+ metadata.gz: f2018a5dacf04f2cd6b821c5438fe71b2950d512f4c3f8e1f398c6cba4ca7f52
4
+ data.tar.gz: '084f3b0db42917d34889931ca62a7f45830975024d410b35b715f64d87be1566'
5
5
  SHA512:
6
- metadata.gz: f7f16b4bacaf7c8763164d854b470af466e4e7e49a75ac4358967c0bf9bbdaac3382eaced06463dc973821d657773f9e54595ffdedf6cd0e8a1b0c400d6a70be
7
- data.tar.gz: 8706512e163d1d06808b80db3ca8a2a1d4a3694e16155f2bfff83e34cae34d26ff365b8f667ac060366fb111b40f4632ea37ab973ba867d9e3b4f3038c4c3168
6
+ metadata.gz: 174317ae1282ceadba0660f528e51147395801a3f26956acc950e44159f53567f4393d1f171e1378067ef441f2aac340b196b0902ff0a455f61dc0eed20a68c6
7
+ data.tar.gz: 2e23e9e51ba7b583396f6b35d522e6d855dec586c619ba11c4e6004a6e53590ecd404c8d9cc222abbdf4defdc27d5675ae1e00e8dc3964e886cb3a06cd8d6567
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'arborist/monitor/snmp' unless defined?( Arborist::Monitor::SNMP )
5
5
 
6
- #
6
+ # Namespace for UPS check classes.
7
7
  class Arborist::Monitor::SNMP::UPS
8
8
  include Arborist::Monitor::SNMP
9
9
 
@@ -3,6 +3,10 @@
3
3
 
4
4
  require 'arborist/monitor/snmp/ups' unless defined?( Arborist::Monitor::SNMP::UPS )
5
5
 
6
+ # Checks for UPS battery health.
7
+ #
8
+ # Checks the available battery percentage, if the UPS is on battery,
9
+ # and the temperature of the battery.
6
10
  #
7
11
  class Arborist::Monitor::SNMP::UPS::Battery
8
12
  include Arborist::Monitor::SNMP
@@ -13,13 +17,13 @@ class Arborist::Monitor::SNMP::UPS::Battery
13
17
  # OIDS for discovering ups status.
14
18
  #
15
19
  OIDS = {
16
- battery_status: '.1.3.6.1.2.1.33.1.2.1.0', # 1 - unk, 2 - normal, 3 - low, 4 - depleted
17
- seconds_on_battery: '.1.3.6.1.2.1.33.1.2.2.0',
18
- est_minutes_remaining: '.1.3.6.1.2.1.33.1.2.3.0',
19
- est_charge_remaining: '.1.3.6.1.2.1.33.1.2.4.0', # in percent
20
- battery_voltage: '.1.3.6.1.2.1.33.1.2.5.0', # in 0.1v DC
21
- battery_current: '.1.3.6.1.2.1.33.1.2.6.0', # in 0.1a DC
22
- battery_temperature: '.1.3.6.1.2.1.33.1.2.7.0' # in Celcius
20
+ battery_status: '.1.3.6.1.2.1.33.1.2.1.0', # 1 - unk, 2 - normal, 3 - low, 4 - depleted
21
+ seconds_on_battery: '.1.3.6.1.2.1.33.1.2.2.0',
22
+ est_minutes_remaining: '.1.3.6.1.2.1.33.1.2.3.0',
23
+ est_charge_remaining: '.1.3.6.1.2.1.33.1.2.4.0', # in percent
24
+ battery_voltage: '.1.3.6.1.2.1.33.1.2.5.0', # in 0.1v DC
25
+ battery_current: '.1.3.6.1.2.1.33.1.2.6.0', # in 0.1a DC
26
+ battery_temperature: '.1.3.6.1.2.1.33.1.2.7.0' # in Celcius
23
27
  }
24
28
 
25
29
  # Human-readable translations for battery status OID.
@@ -76,23 +80,23 @@ class Arborist::Monitor::SNMP::UPS::Battery
76
80
 
77
81
  # basic info that's always available
78
82
  info[ :status ] = snmp.get( oid: OIDS[:battery_status] )
79
- info[ :capacity ] = snmp.get( oid: OIDS[:est_charge_remaining] )
80
- info[ :temperature ] = snmp.get( oid: OIDS[:battery_temperature] )
81
- info[ :minutes_remaining ] = snmp.get( oid: OIDS[:est_minutes_remaining] )
83
+ info[ :capacity ] = snmp.get( oid: OIDS[:est_charge_remaining] ) rescue nil
84
+ info[ :temperature ] = snmp.get( oid: OIDS[:battery_temperature] ) rescue nil
85
+ info[ :minutes_remaining ] = snmp.get( oid: OIDS[:est_minutes_remaining] ) rescue nil
82
86
 
83
87
  # don't report voltage if the UPS doesn't
84
88
  voltage = snmp.get( oid: OIDS[:battery_voltage] ) rescue nil
85
- info[ :voltage ] = voltage / 10 unless voltage.nil?
89
+ info[ :voltage ] = voltage / 10 if voltage
86
90
 
87
91
  # don't report current if the UPS doesn't
88
92
  current = snmp.get( oid: OIDS[:battery_current] ) rescue nil
89
- info[ :current ] = current/10 unless current.nil?
93
+ info[ :current ] = current/10 if current
90
94
 
91
95
  # see if we are on battery
92
96
  info[ :seconds_on_battery ] = snmp.get( oid: OIDS[:seconds_on_battery] ) rescue 0
93
97
  info[ :in_use ] = ( info[ :seconds_on_battery ] != 0 )
94
98
 
95
- return { battery: info }
99
+ return { battery: info.compact }
96
100
  end
97
101
 
98
102
  ### Parse SNMP-provided information and alert based on thresholds.
@@ -100,28 +104,28 @@ class Arborist::Monitor::SNMP::UPS::Battery
100
104
  def check_battery( host, snmp )
101
105
  info = self.format_battery( snmp )
102
106
 
103
- config = identifiers[ host ].last || {}
104
- cap_warn = config[ 'capacity_warn_at' ] || self.class.capacity_warn_at
107
+ config = identifiers[ host ].last || {}
108
+ cap_warn = config[ 'capacity_warn_at' ] || self.class.capacity_warn_at
105
109
  temp_warn = config[ 'temperature_warn_at' ] || self.class.temperature_warn_at
106
110
 
107
- in_use = info.dig( :battery, :in_use )
108
- status = info.dig( :battery, :status )
109
- capacity = info.dig( :battery, :capacity )
111
+ in_use = info.dig( :battery, :in_use )
112
+ status = info.dig( :battery, :status )
113
+ capacity = info.dig( :battery, :capacity )
110
114
  temperature = info.dig( :battery, :temperature )
111
115
  warnings = []
112
116
 
113
117
  if in_use
114
- mins = info.dig( :battery, :minutes_remaining )
118
+ mins = info.dig( :battery, :minutes_remaining ) || "(unknown)"
115
119
  warnings << "UPS on battery - %s minute(s) remaning." % [ mins ]
116
120
  end
117
121
 
118
122
  warnings << BATTERY_STATUS[ status ] if status != 2
119
123
 
120
124
  warnings << "Battery remaining capacity %0.1f%% less than %0.1f percent" %
121
- [ capacity, cap_warn ] if capacity <= cap_warn
125
+ [ capacity, cap_warn ] if capacity && capacity <= cap_warn
122
126
 
123
127
  warnings << "Battery temperature %dC greater than %dC" %
124
- [ temperature, temp_warn ] if temperature >= temp_warn
128
+ [ temperature, temp_warn ] if temperature && temperature >= temp_warn
125
129
 
126
130
  info[ :warning ] = warnings.join( "\n" ) unless warnings.empty?
127
131
  self.results[ host ] = info
data/lib/arborist/snmp.rb CHANGED
@@ -14,7 +14,7 @@ module Arborist::SNMP
14
14
 
15
15
 
16
16
  # Package version
17
- VERSION = '0.6.0'
17
+ VERSION = '0.6.1'
18
18
 
19
19
  # Version control revision
20
20
  REVISION = %q$Revision$
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arborist-snmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mahlon E. Smith <mahlon@martini.nu>
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-04-18 00:00:00.000000000 Z
12
+ date: 2019-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arborist