Advertisement
Guest User

Untitled

a guest
Jul 9th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.71 KB | None | 0 0
  1. begin  
  2.         mibpath = "/usr/share/snmp/mibs/mib"
  3.         if !File.directory?("#{mibpath}")
  4.                 puts "Aborting: #{mibpath} does not exist"
  5.                 exit
  6.         end
  7.         mibs = Array.new
  8.         mibs.push("SNMPv2-SMI")
  9.         mibs.push("SNMPv2-MIB")
  10.         mibs.push("IANAifType-MIB")
  11.         mibs.push("IF-MIB")
  12.         mibs.push("SNMPv2-CONF")
  13.         mibs.push("SNMPv2-TC")
  14.         SNMP::MIB.list_imported(regex=/.*/).each do |mib|
  15.                 mibs.each do |mymib|
  16.                         if "#{mib}".eql?("#{mymib}")
  17.                                 puts "Removing : #{mymib}"
  18.                                 mibs.delete("#{mymib}")
  19.                         end
  20.                 end
  21.         end
  22.  
  23.         mibs.each do |element|
  24.                 if !element.nil?
  25.                         puts "Importing #{element}"
  26.                         SNMP::MIB.import_module("#{mibpath}/#{element}.txt")
  27.                 end
  28.         end
  29.         #exit # TODO remove this when done testing
  30.         manager = SNMP::Manager.new(:host => "swith910.moraminfra.net",
  31.                                     :community => "XXXXXXcommunity",
  32.                                     :version => 'SNMPv2c'.to_sym,
  33.                                     :timeout => 6, :mib_modules => ["SNMPv2-TC","SNMPv2-CONF","SNMPv2-SMI", "SNMPv2-MIB" , "IANAifType-MIB", "IF-MIB"])
  34.         response = manager.get(["1.3.6.1.2.1.31.1.1.1.6"])
  35. rescue SNMP::RequestTimeout
  36.         puts "TIMEOUT ERROR: not responding"
  37. rescue SNMP::MIB::ModuleNotLoadedError
  38.         puts "Module Import error"
  39. rescue => e
  40.         puts "An unknown error occured: #{e.inspect}"
  41. end
  42.  
  43. response.each_varbind do |vb|
  44.         puts "Value is #{vb.value}"
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement