-
-
Save anonymous/7aa617b2b8b18d0fcaad to your computer and use it in GitHub Desktop.
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
begin | |
mibpath = "/usr/share/snmp/mibs/mib" | |
if !File.directory?("#{mibpath}") | |
puts "Aborting: #{mibpath} does not exist" | |
exit | |
end | |
mibs = Array.new | |
mibs.push("SNMPv2-SMI") | |
mibs.push("SNMPv2-MIB") | |
mibs.push("IANAifType-MIB") | |
mibs.push("IF-MIB") | |
mibs.push("SNMPv2-CONF") | |
mibs.push("SNMPv2-TC") | |
SNMP::MIB.list_imported(regex=/.*/).each do |mib| | |
mibs.each do |mymib| | |
if "#{mib}".eql?("#{mymib}") | |
puts "Removing : #{mymib}" | |
mibs.delete("#{mymib}") | |
end | |
end | |
end | |
mibs.each do |element| | |
if !element.nil? | |
puts "Importing #{element}" | |
SNMP::MIB.import_module("#{mibpath}/#{element}.txt") | |
end | |
end | |
#exit # TODO remove this when done testing | |
manager = SNMP::Manager.new(:host => "swith910.moraminfra.net", | |
:community => "XXXXXXcommunity", | |
:version => 'SNMPv2c'.to_sym, | |
:timeout => 6, :mib_modules => ["SNMPv2-TC","SNMPv2-CONF","SNMPv2-SMI", "SNMPv2-MIB" , "IANAifType-MIB", "IF-MIB"]) | |
response = manager.get(["1.3.6.1.2.1.31.1.1.1.6"]) | |
rescue SNMP::RequestTimeout | |
puts "TIMEOUT ERROR: not responding" | |
rescue SNMP::MIB::ModuleNotLoadedError | |
puts "Module Import error" | |
rescue => e | |
puts "An unknown error occured: #{e.inspect}" | |
end | |
response.each_varbind do |vb| | |
puts "Value is #{vb.value}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment