Skip to content

Instantly share code, notes, and snippets.

@mapledyne
Created September 3, 2015 15:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapledyne/b762ad6251b5460a78bc to your computer and use it in GitHub Desktop.
Save mapledyne/b762ad6251b5460a78bc to your computer and use it in GitHub Desktop.
Cisco ASA Bandwidth usage widget for dashing.io
require 'rubygems'
require 'snmp'
# Populate the graph with some random points
@inbound_points = []
@outbound_points = []
@inbound_long = []
@outbound_long = []
(1..15).each do
@inbound_points << { x: Time.new.to_i, y: 0 }
@outbound_points << { x: Time.new.to_i, y: 0 }
end
(1..1440).each do
@inbound_long << { x: Time.new.to_i, y: 0 }
@outbound_long << { x: Time.new.to_i, y: 0 }
end
SCHEDULER.every '20s' do
# outbound:
# snmpwalk -v2c -ccommunity 10.30.10.1 1.3.6.1.4.1.9.9.171
# inbound: 1.3.6.1.2.1.2.2.1.10.3
results1 = []
results2 = []
service = 'Cisco ASA'
status = 'normal'
manager = SNMP::Manager.new(host: '10.30.10.1', community: 'community')
response = manager.get(['1.3.6.1.2.1.2.2.1.10.3', '1.3.6.1.2.1.2.2.1.16.3'])
response.each_varbind do |vb|
results1.push(vb.value.to_i)
end
sleep 10
response = manager.get(['1.3.6.1.2.1.2.2.1.10.3', '1.3.6.1.2.1.2.2.1.16.3'])
response.each_varbind do |vb|
results2.push(vb.value.to_i)
end
inbound = (results2[0] - results1[0]) / 10 * 8 / 1_000_000
outbound = (results2[1] - results1[1]) / 10 * 8 / 1_000_000
manager.close
@inbound_points.shift
@outbound_points.shift
@inbound_points << { x: Time.new.to_i, y: inbound }
@outbound_points << { x: Time.new.to_i, y: outbound }
@inbound_long.shift
@outbound_long.shift
@inbound_long << { x: Time.new.to_i, y: inbound }
@outbound_long << { x: Time.new.to_i, y: outbound }
in_max = 0
out_max = 0
@in_smooth = []
@out_smooth = []
i = 0
@inbound_long.each do |item|
i += 1
in_max = [in_max, item[:y]].max
if i.modulo(10).zero?
@in_smooth << { x: i, y: in_max.to_i }
in_max = 0
end
end
i = 0
@outbound_long.each do |item|
i += 1
out_max = [out_max, item[:y]].max
if i.modulo(10).zero?
@out_smooth << { x: i, y: out_max.to_i }
out_max = 0
end
end
@series = [{ name: 'Inbound Data', data: @inbound_points },
{ name: 'Outbound Data', data: @outbound_points }]
@series_long = [{ name: 'Inbound Data', data: @inbound_long },
{ name: 'Outbound Data', data: @outbound_long }]
@series_long_smooth = [{ name: 'Inbound Data', data: @in_smooth },
{ name: 'Outbound Data', data: @out_smooth }]
send_event('bandwidth_short', series: @series, service: service,
status: status)
send_event('bandwidth_long', series: @series_long, service: service,
status: status)
send_event('bandwidth_long_smooth', series: @series_long_smooth,
service: service,
status: status)
puts 'sending inbound_bandwidth : ' + inbound.to_s
send_event('inbound_bandwidth', value: inbound.to_i,
service: service,
status: status)
send_event('inbound_bandwidth_graph', points: @inbound_points,
service: service,
status: status)
puts 'sending outbound_bandwidth : ' + outbound.to_s
send_event('outbound_bandwidth', value: outbound.to_i,
service: service,
status: status)
send_event('outbound_bandwidth_graph', points: @outbound_points,
service: service,
status: status)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment