exe/snmp_collector in telemetry-snmp-0.1.0 vs exe/snmp_collector in telemetry-snmp-0.2.0
- old
+ new
@@ -1,42 +1,53 @@
#!/usr/bin/env ruby
+ENV['telemetry.snmp.amqp.nodes'] = 'apvrs33012'
+ENV['telemetry.snmp.amqp.username'] = 'snmp'
+ENV['telemetry.snmp.amqp.password'] = 'snmp'
+ENV['telemetry.snmp.amqp.port'] = '8080'
+ENV['telemetry.snmp.amqp.vhost'] = 'telegraf'
+
require 'telemetry/snmp'
Telemetry::Snmp.bootstrap
trap('SIGTERM') { @quit = true }
trap('SIGHUP') { @quit = true }
trap('SIGINT') { @quit = true }
@quit = false
until @quit
+ sleep(1)
@lines = []
- Telemetry::Snmp::Data::Model::Device.each do |row|
+ Telemetry::Snmp::Data::Model::Device.where(:active).each do |row|
+ break if @quit
next if row.values[:last_polled].to_i + row.values[:frequency] > Time.now.to_i
fields = {}
tags = {
hostname: row.values[:hostname],
ip_address: row.values[:ip_address],
env: row.values[:environment],
dc: row.values[:datacenter],
zone: row.values[:zone],
- influxdb_node_group: 'snmp'
+ influxdb_node_group: 'snmp',
+ influxdb_database: 'snmp'
}
Telemetry::Snmp::Data::Model::OID.each do |oid_row|
+ break if @quit
+
oid_value = Telemetry::Snmp::Client.oid_value(row[:hostname], oid_row.values[:oid])
next if oid_value.nil?
next unless oid_value.is_a?(Integer) || oid_value.is_a?(Float)
fields[oid_row.values[:name]] = "#{Telemetry::Snmp::Client.oid_value(row[:hostname], oid_row.values[:oid])}i"
rescue StandardError => e
Telemetry::Logger.error "#{e.class}: #{e.message}"
end
@lines.push Telemetry::Metrics::Parser.to_line_protocol(
- measurement: 'palo_alto_a',
+ measurement: 'palo_alto',
fields: fields,
tags: tags,
timestamp: (DateTime.now.strftime('%Q').to_i * 1000 * 1000)
)
@@ -46,9 +57,10 @@
row.update(last_polled: Sequel::CURRENT_TIMESTAMP)
row.save
rescue StandardError => e
Telemetry::Logger.error "#{e.class}: #{e.message}"
+ Telemetry::Logger.error e.backtrace[0..20]
end
Telemetry::Snmp::Publisher.push_lines(@lines) unless @lines.empty?
sleep(1)
end