Class: Spectacular::Device
- Inherits:
-
Object
- Object
- Spectacular::Device
- Defined in:
- lib/spectacular/device.rb
Defined Under Namespace
Classes: Klass
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
- #columns ⇒ Object
-
#initialize(host, history = 10) ⇒ Device
constructor
A new instance of Device.
- #interfaces ⇒ Object
- #monitor(interval = 1) ⇒ Object
Constructor Details
#initialize(host, history = 10) ⇒ Device
Returns a new instance of Device.
9 10 11 12 |
# File 'lib/spectacular/device.rb', line 9 def initialize host, history = 10 @host = host @history = new_history history end |
Instance Attribute Details
#history ⇒ Object (readonly)
Returns the value of attribute history.
7 8 9 |
# File 'lib/spectacular/device.rb', line 7 def history @history end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/spectacular/device.rb', line 7 def host @host end |
Instance Method Details
#columns ⇒ Object
14 15 16 |
# File 'lib/spectacular/device.rb', line 14 def columns ["ifIndex", "ifDescr", "ifInOctets", "ifOutOctets"] end |
#interfaces ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/spectacular/device.rb', line 18 def interfaces manager = snmp_manager host interfaces = [] manager.walk(['ifDescr']) do |row| interfaces << row.first.value.to_s end interfaces ensure manager.close end |
#monitor(interval = 1) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/spectacular/device.rb', line 29 def monitor interval = 1 manager = snmp_manager host loop do manager.walk(columns) do |row| key = row[1].value.to_s result = diff history.last(key), row yield result unless result.empty? history.add key, row.map(&:dup) end sleep interval end ensure manager.close end |