arborist-snmp 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2a1e7f51762b179cee87fda4bc23a7f8e5875cf5
4
- data.tar.gz: e4455394ab0a4e0f5affa2aba4053ec915585dad
2
+ SHA256:
3
+ metadata.gz: 968e138781d430383f877e95e7eff1450f79cd76f5bb0aa1caa529759c9c8cd8
4
+ data.tar.gz: 9fd01fba144b94cf1439ed7b93df52762f7467ad29666ee05ce009880e74a7bc
5
5
  SHA512:
6
- metadata.gz: 61225e9bd9a10ae9ede1072b30dda70fb93910b2f1210e67d60c368ace730aaebe1ae0ee8b3fadf9ce5e1d85ec33b5970be12d6f0c262def2dc18ef4cf7b2d64
7
- data.tar.gz: a725b24835f6d7a9eabd04c7ea36a4fe8ecbdbaab2a3863021aa28d125e1969009b1e8f8d569e42b89586bdbb4137010dbad9d8012b3b98e26c97c64922f0a4e
6
+ metadata.gz: f7f16b4bacaf7c8763164d854b470af466e4e7e49a75ac4358967c0bf9bbdaac3382eaced06463dc973821d657773f9e54595ffdedf6cd0e8a1b0c400d6a70be
7
+ data.tar.gz: 8706512e163d1d06808b80db3ca8a2a1d4a3694e16155f2bfff83e34cae34d26ff365b8f667ac060366fb111b40f4632ea37ab973ba867d9e3b4f3038c4c3168
@@ -135,4 +135,6 @@ require 'arborist/monitor/snmp/cpu'
135
135
  require 'arborist/monitor/snmp/disk'
136
136
  require 'arborist/monitor/snmp/process'
137
137
  require 'arborist/monitor/snmp/memory'
138
+ require 'arborist/monitor/snmp/ups'
139
+ require 'arborist/monitor/snmp/ups/battery'
138
140
 
@@ -24,11 +24,7 @@ class Arborist::Monitor::SNMP::CPU
24
24
  # When walking load OIDS, the iterator count matches
25
25
  # these labels.
26
26
  #
27
- LOADKEYS = {
28
- 1 => :load1,
29
- 2 => :load5,
30
- 3 => :load15
31
- }
27
+ LOADKEYS = %i[ load1 load5 load15 ]
32
28
 
33
29
 
34
30
  # Global defaults for instances of this monitor
@@ -96,8 +92,8 @@ class Arborist::Monitor::SNMP::CPU
96
92
  #
97
93
  else
98
94
  snmp.walk( oid: OIDS[:load] ).each_with_index do |(_, value), idx|
99
- next unless LOADKEYS[ idx + 1 ]
100
- info[ :load ][ LOADKEYS[idx + 1] ] = value.to_f
95
+ next unless LOADKEYS[ idx ]
96
+ info[ :load ][ LOADKEYS[idx] ] = value.to_f
101
97
  end
102
98
 
103
99
  percentage = (( ( info[:load][ :load5 ] / cpus.size) - 1 ) * 100 ).round( 1 )
@@ -0,0 +1,10 @@
1
+ # -*- ruby -*-
2
+ # vim: set noet nosta sw=4 ts=4 :
3
+
4
+ require 'arborist/monitor/snmp' unless defined?( Arborist::Monitor::SNMP )
5
+
6
+ #
7
+ class Arborist::Monitor::SNMP::UPS
8
+ include Arborist::Monitor::SNMP
9
+
10
+ end
@@ -0,0 +1,132 @@
1
+ # -*- ruby -*-
2
+ # vim: set noet nosta sw=4 ts=4 :
3
+
4
+ require 'arborist/monitor/snmp/ups' unless defined?( Arborist::Monitor::SNMP::UPS )
5
+
6
+ #
7
+ class Arborist::Monitor::SNMP::UPS::Battery
8
+ include Arborist::Monitor::SNMP
9
+
10
+ extend Configurability, Loggability
11
+ log_to :arborist_snmp
12
+
13
+ # OIDS for discovering ups status.
14
+ #
15
+ 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
23
+ }
24
+
25
+ # Human-readable translations for battery status OID.
26
+ #
27
+ BATTERY_STATUS = {
28
+ 1 => "Battery status is Unknown.",
29
+ 2 => "Battery is OK.",
30
+ 3 => "Battery is Low.",
31
+ 4 => "Battery is Depleted."
32
+ }
33
+
34
+ # Global defaults for instances of this monitor
35
+ #
36
+ configurability( 'arborist.snmp.ups.battery' ) do
37
+ # What battery percentage qualifies as a warning
38
+ setting :capacity_warn_at, default: 60
39
+
40
+ # What battery temperature qualifies as a warning, in C
41
+ setting :temperature_warn_at, default: 50
42
+ end
43
+
44
+
45
+ ### Return the properties used by this monitor.
46
+ ###
47
+ def self::node_properties
48
+ return USED_PROPERTIES
49
+ end
50
+
51
+
52
+ ### Class #run creates a new instance and immediately runs it.
53
+ ###
54
+ def self::run( nodes )
55
+ return new.run( nodes )
56
+ end
57
+
58
+
59
+ ### Perform the monitoring checks.
60
+ ###
61
+ def run( nodes )
62
+ super do |host, snmp|
63
+ self.check_battery( host, snmp )
64
+ end
65
+ end
66
+
67
+
68
+ #########
69
+ protected
70
+ #########
71
+
72
+ ### Query SNMP and format information into a hash.
73
+ ###
74
+ def format_battery( snmp )
75
+ info = {}
76
+
77
+ # basic info that's always available
78
+ 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] )
82
+
83
+ # don't report voltage if the UPS doesn't
84
+ voltage = snmp.get( oid: OIDS[:battery_voltage] ) rescue nil
85
+ info[ :voltage ] = voltage / 10 unless voltage.nil?
86
+
87
+ # don't report current if the UPS doesn't
88
+ current = snmp.get( oid: OIDS[:battery_current] ) rescue nil
89
+ info[ :current ] = current/10 unless current.nil?
90
+
91
+ # see if we are on battery
92
+ info[ :seconds_on_battery ] = snmp.get( oid: OIDS[:seconds_on_battery] ) rescue 0
93
+ info[ :in_use ] = ( info[ :seconds_on_battery ] != 0 )
94
+
95
+ return { battery: info }
96
+ end
97
+
98
+ ### Parse SNMP-provided information and alert based on thresholds.
99
+ ###
100
+ def check_battery( host, snmp )
101
+ info = self.format_battery( snmp )
102
+
103
+ config = identifiers[ host ].last || {}
104
+ cap_warn = config[ 'capacity_warn_at' ] || self.class.capacity_warn_at
105
+ temp_warn = config[ 'temperature_warn_at' ] || self.class.temperature_warn_at
106
+
107
+ in_use = info.dig( :battery, :in_use )
108
+ status = info.dig( :battery, :status )
109
+ capacity = info.dig( :battery, :capacity )
110
+ temperature = info.dig( :battery, :temperature )
111
+ warnings = []
112
+
113
+ if in_use
114
+ mins = info.dig( :battery, :minutes_remaining )
115
+ warnings << "UPS on battery - %s minute(s) remaning." % [ mins ]
116
+ end
117
+
118
+ warnings << BATTERY_STATUS[ status ] if status != 2
119
+
120
+ warnings << "Battery remaining capacity %0.1f%% less than %0.1f percent" %
121
+ [ capacity, cap_warn ] if capacity <= cap_warn
122
+
123
+ warnings << "Battery temperature %dC greater than %dC" %
124
+ [ temperature, temp_warn ] if temperature >= temp_warn
125
+
126
+ info[ :warning ] = warnings.join( "\n" ) unless warnings.empty?
127
+ self.results[ host ] = info
128
+
129
+ end
130
+
131
+ end # class Arborist::Monitor::UPS::Battery
132
+
@@ -14,10 +14,10 @@ module Arborist::SNMP
14
14
 
15
15
 
16
16
  # Package version
17
- VERSION = '0.5.0'
17
+ VERSION = '0.6.0'
18
18
 
19
19
  # Version control revision
20
- REVISION = %q$Revision: e4f0fd44734d $
20
+ REVISION = %q$Revision$
21
21
 
22
22
 
23
23
  ### Return the name of the library with the version, and optionally the build ID if
metadata CHANGED
@@ -1,37 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arborist-snmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mahlon E. Smith <mahlon@martini.nu>
8
8
  - Michael Granger <ged@faeriemud.org>
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain:
12
- - |
13
- -----BEGIN CERTIFICATE-----
14
- MIIDbDCCAlSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MQ8wDQYDVQQDDAZtYWhs
15
- b24xFzAVBgoJkiaJk/IsZAEZFgdtYXJ0aW5pMRIwEAYKCZImiZPyLGQBGRYCbnUw
16
- HhcNMTcxMTIyMjIyMTAyWhcNMTgxMTIyMjIyMTAyWjA+MQ8wDQYDVQQDDAZtYWhs
17
- b24xFzAVBgoJkiaJk/IsZAEZFgdtYXJ0aW5pMRIwEAYKCZImiZPyLGQBGRYCbnUw
18
- ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDpXGN0YbMVpYv4EoiCxpQw
19
- sxKdyhlkvpvENUkpEhbpnEuMKXgUfRHO4T/vBZf0h8eYgwnrHCRhAeIqesFKfoj9
20
- mpEJk5JUuADOAz18aT+v24UqAtJdiwBJLuqhslSNB6CFXZv3OOMny9bjoJegz0hI
21
- Fht9ppCuNmxJNd+L3zAX8lD01RUWNRC+8L5QLCjViJtjFDDCFfh9NCirs+XnTCzo
22
- AJgFbsZIzFJtSiXUtFgscKr4Ik8ruhRbPbYbmx9rf6W74aTMPxggq/d3gj0Eh32y
23
- WsXsQ5giVnmkbsRkBNu3QyZ8Xr5+7mvy5AWyqXKOrcW7lnYaob6Z9x/MGXGNeD6j
24
- AgMBAAGjdTBzMAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBRY8ea6
25
- +6kAaW7ukKph2/4MTAD8/TAcBgNVHREEFTATgRFtYWhsb25AbWFydGluaS5udTAc
26
- BgNVHRIEFTATgRFtYWhsb25AbWFydGluaS5udTANBgkqhkiG9w0BAQUFAAOCAQEA
27
- 00FljTeSNaYUqJ59yLRA+i43wVNiO4ETQQu6fYQCPns12Sm90spOJb3SmTDkJ7CY
28
- dixOQg5A3Et1LVS+Z/YfH1TAbb50oTWbZbTW2JknHS0hohq3UF1pvbkk1niZ26er
29
- skJ352MUfcyaUkQyMmCjL/BpkDutYH5OCGh+FmK8+mH7SoC9Nr48WwH2prVdHs3y
30
- OMWFgB33sXdj1XqOd2Rw1WPgAeMeDqWeIrRMpUhNZOwroaA1MAr60f9NIYxua/vx
31
- n0YyneERGuHPSRZFgo72tGOqLpAlWnhPxRNqnayZmsg3hPPI87B6MTUI2UQ7VUdh
32
- UrSf3b+cPoC8PNfjp8zsdw==
33
- -----END CERTIFICATE-----
34
- date: 2018-06-13 00:00:00.000000000 Z
11
+ cert_chain: []
12
+ date: 2019-04-18 00:00:00.000000000 Z
35
13
  dependencies:
36
14
  - !ruby/object:Gem::Dependency
37
15
  name: arborist
@@ -86,6 +64,8 @@ files:
86
64
  - lib/arborist/monitor/snmp/disk.rb
87
65
  - lib/arborist/monitor/snmp/memory.rb
88
66
  - lib/arborist/monitor/snmp/process.rb
67
+ - lib/arborist/monitor/snmp/ups.rb
68
+ - lib/arborist/monitor/snmp/ups/battery.rb
89
69
  - lib/arborist/snmp.rb
90
70
  homepage: http://bitbucket.org/mahlon/Arborist-SNMP
91
71
  licenses:
@@ -107,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
87
  version: '0'
108
88
  requirements: []
109
89
  rubyforge_project:
110
- rubygems_version: 2.5.2.1
90
+ rubygems_version: 2.7.6
111
91
  signing_key:
112
92
  specification_version: 4
113
93
  summary: SNMP support for Arborist monitors