Module: Telemetry::Snmp::Collector

Defined in:
lib/telemetry/snmp/collector.rb

Class Method Summary collapse

Class Method Details

.device_locked?(device_id) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/telemetry/snmp/collector.rb', line 41

def device_locked?(device_id)
  Telemetry::Snmp::Data::Model::DeviceLock.where(device_id: device_id).count.positive?
end

.device_unlocked?(device_id) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/telemetry/snmp/collector.rb', line 45

def device_unlocked?(device_id)
  !device_locked?(device_id)
end

.loop_devicesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/telemetry/snmp/collector.rb', line 5

def loop_devices
  count = 0
  Telemetry::Snmp::Data::Model::Device.where(:active).order(:last_polled).each do |row|
    break if count >= 10
    next if row.values[:last_polled].to_i + row.values[:frequency] > Time.now.to_i
    next if device_locked?(row.values[:id])

    Telemetry::Logger.info "Grabbing metrics for #{row.values[:hostname]}"
    device = Telemetry::Snmp::DeviceCollector.new(row.values[:hostname])
    device.async.collect
    count += 1
  end
end

.poll_next_deviceObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/telemetry/snmp/collector.rb', line 19

def poll_next_device
  Telemetry::Snmp::Data::Model::Device.where(:active).order(:last_polled).each do |row|
    next if row.values[:last_polled].to_i + row.values[:frequency] > Time.now.to_i
    next if device_locked?(row.values[:id])

    Telemetry::Logger.info "Grabbing metrics for #{row.values[:hostname]}"
    collect(row.values[:id])
    break
  rescue StandardError => e
    Telemetry::Logger.exception(e, level: 'error')
  end
end

.unlock_expired_devicesObject



32
33
34
35
36
37
38
39
# File 'lib/telemetry/snmp/collector.rb', line 32

def unlock_expired_devices
  Telemetry::Snmp::Data::Model::DeviceLock.each do |row|
    next if row.values[:expires] < Sequel::CURRENT_TIMESTAMP

    Telemetry::Logger.warn "removing lock for #{row.values[:hostname]}"
    row.delete
  end
end