Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement