def getall(self, mangledname, indexoid=None): """getall(tablename, [indexoid=False]) Gets all of the rows of a table (given by name). If an (optional) oid fragment is given as a second argument, this is used to restrict the objects retrieved to that index value. If the row has multiple indexes, you must supply a value in the order that the index is listed in the MIB. """ t = Objects.ObjectTable(self.rows[mangledname]) t.fetch(self.session) if indexoid: # return requested subset rt = Objects.ObjectTable(self.rows[mangledname]) OIDtype = Objects.Basetypes.OID for oid, val in t.items(): if OIDtype(oid) == indexoid: rt[oid] = val return rt return t
# 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) print # can combine into one-liner, of course. print "Abstract API one-liner:" print IF_MIB.ifName(indexoid=[1]).get(box) print SNMPv2_MIB.sysName().get(box) print print "Direct table:" from pycopia.SMI import Objects ift = Objects.get_table(box, IF_MIB.ifEntry) # dictionary print "Interface entries:" for iface in ift.values(): print iface.ifDescr print "Entire row data for last interface:" print iface del ift, iface print ################### print "Manager interface:" from pycopia.SNMP import Manager # Define a class that represents a managed device. # You can add device-special methods here. See the Devices package for more examples.
def get_iterator(self, name, indexoid=None, count=0): return Objects.RowIterator(self, self.rows[name], indexoid, count)
def get_table(self, mangledname): rowclass = self.rows[mangledname] t = Objects.PlainTable(rowclass, str(rowclass)) t.fetch(self.session) return t
# 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) print # can combine into one-liner, of course. print "Abstract API one-liner:" print IF_MIB.ifName(indexoid=[1]).get(box) print SNMPv2_MIB.sysName().get(box) print print "Direct table:" from pycopia.SMI import Objects ift = Objects.get_table(box, IF_MIB.ifEntry) # dictionary print "Interface entries:" for iface in ift.values(): print iface.ifDescr print "Entire row data for last interface:" print iface del ift, iface print ################### print "Manager interface:" from pycopia.SNMP import Manager # Define a class that represents a managed device. # You can add device-special methods here. See the Devices package for more examples. class DeviceManager(Manager.Manager):