Created
May 13, 2014 09:25
-
-
Save thesp0nge/e252d3159603d58c128a to your computer and use it in GitHub Desktop.
Sample to gather stats using SNMP (process list is valid only for Sun Solaris operating System)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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