def compile_module(modname, preload=None, all=False): if preload: for pm in preload: SMI.load_module(pm) smimodule = SMI.get_module(modname) if not smimodule: print "Could not load module", modname return if all: for dep in _get_dependents(smimodule): _compile_module(SMI.get_module(dep)) _compile_module(smimodule)
def test_index(self): print("index test: get an Index object of a row") rtpmib = SMI.get_module("RTP-MIB") rtpsess = rtpmib.get_node("rtpSessionInverseEntry") rtpsess_index = rtpsess.get_index() for ind in rtpsess_index: print(rtpmib.get_node(ind.name).value)
def compile_everything(all=False): count = 0 paths = SMI.get_path().split(":") for dir in paths: print "Looking in", dir for modname in os.listdir(dir): modpath = os.path.join(dir, modname) if os.path.isfile(modpath): print "Found module", modname, "compiling..." try: compile_module(modname, None, all) except SMI.SmiError, err: print "***[", err, "]***" count += 1 SMI.clear() # clear out mememory SMI.init()
def test_ipmib(self): ipmod = SMI.get_module("IP-MIB") eslist = ipmod.get_scalars() for es in eslist: print(es.name, es.syntax) n = ipmod.get_node("ipForwarding") print(n.syntax.enumerations)
def finalize(self): self.oidfo.write("}\n") handle_specials(self.fo, self.smimodule) self.fo.write(""" # Add to master OIDMAP. from pycopia import SMI SMI.update_oidmap(__name__) """)
def test_augments(self): print("augments test: should see base conceptual row index.") snmpmib = SMI.get_module("SNMP-COMMUNITY-MIB") taenode = snmpmib.get_node("snmpTargetAddrExtEntry") # base row with implied index taenode_index = taenode.get_index() print(repr(taenode_index)) comm = snmpmib.get_node("snmpCommunityEntry") # augmented row comm_index = comm.get_index() print(repr(comm_index)) newoid = comm.OID print(newoid)
def setUp(self): SMI.load_modules("SNMPv2-SMI", "SNMPv2-TC", "SNMPv2-MIB", "UDP-MIB", "TCP-MIB") mods = list(SMI.get_modules()) self.mod = mods[-1]
def _get_dependents(module, hash=None): h = hash or {} for imp in module.get_imports(): h[imp.module] = True _get_dependents(SMI.get_module(imp.module), h) return h.keys()
# bug here... must import Python mibs so that OIDMAP gets created. from pycopia.mibs import SNMPv2_MIB from pycopia.mibs import IF_MIB print "Direct OID list method:" print box.get([1, 3, 6, 1, 2, 1, 1, 5, 0]) # get OID from some other source print print "MIB node and raw SNMP method:" try: from pycopia.SMI import SMI except ImportError, err: print err print "you need libsmi and the libsmi wrappers installed for this demo." else: oid1 = SMI.get_node('IF-MIB::ifName').OID + [1] # InterfaceIndex oid2 = SMI.get_node('SNMPv2-MIB::sysName').OID + [0] # same SNMP methods for varbind in box.get(oid1, oid2): print varbind.value print print "Abstract API method:" # get SMI instance ifname = IF_MIB.ifName(indexoid=[1]) # ColumnObject needs indexoid sysname = SNMPv2_MIB.sysName() # Get the SMI using the SNMP session. useful for getting the same MIB variable # from many devices/sessions (iterate over a list of sessions). print ifname.get(box) print sysname.get(box)
def test_types(self): print(" types test:") tcmib = SMI.get_module("SNMPv2-TC") smi_types = tcmib.get_types() for smi_type in smi_types: print("Type: ", smi_type, smi_type.snmptype)