Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample to gather stats using SNMP (process list is valid only for Sun Solaris operating System)
#!/usr/bin/ruby
require 'snmp'
require 'ipaddress'
include SNMP
# ARGV[0] is an IP address or a network in CIDR notation
raise "Missing IP address or network" if ARGV[0].nil?
@list = IPAddress.parse(ARGV[0])
@list.each do |ip|
puts "Asking #{ip.to_s} for info using 'public' SNMP community"
Manager.open(:Host => ip.to_s, :Community => 'public') do |manager|
response = manager.get([ObjectId.new("1.3.6.1.2.1.1.1.0"), ObjectId.new("1.3.6.1.2.1.1.3.0")])
response.each_varbind do |vb|
puts "#{vb.name.to_s} #{vb.value.to_s} #{vb.value.asn1_type}"
end
# Sun Process Table - http://www.alvestrand.no/objectid/1.3.6.1.4.1.42.3.12.1.html
processTable = ObjectId.new("1.3.6.1.4.1.42.3.12.1")
manager.walk(processTable) { |varbind| puts "#{varbind.value.to_s}" if varbind.name.to_s.start_with?("SNMPv2-SMI::enterprises.42.3.12.1.10")}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.