Re: [pysnmp-users] Introspecting returned OID values from custom MIBs
Brought to you by:
elie
From: Ilya E. <il...@gl...> - 2012-11-28 14:38:35
|
Hi Ian, There's a TextualConvention class in pysnmp/smi/mibs/SNMPv2-TC.py which is designed to be mixed into any standard SNMP type (Integer, OctetString etc) to customize value verification and interpretation in accordance with TEXTUAL-CONVENTION macro concent. For example: TruthValue ::= TEXTUAL-CONVENTION STATUS current DESCRIPTION "Represents a boolean value." SYNTAX INTEGER { true(1), false(2) } gets converted into: class TruthValue(Integer, TextualConvention): subtypeSpec = Integer.subtypeSpec + SingleValueConstraint(1, 2) namedValues = NamedValues(('true', 1), ('false', 2)) by libsmi2pysnmp or by hand. You can see more examples on the above technique in pysnmp/smi/mibs/SNMPv2-TC.py. If you convert custom manufacturer MIBs with pysnmp/build-pysnmp-mib script, the above magic would happen by its own. Is that what you need? -ilya > I am working on a tool that consumes custom manufacturer MIBs with pysnmp. > > I am trying to find a way to return more useful python values from > both the custom variable types defined in the MIBs provided by the > manufacturer as well as the standard RFC 1902 SNMP variable types. > > A hypothetical example of what I have and what I need to get: > > Let there be a MIB file that defines a textual convention > ManufacturerXInterfaceType that includes: > - Integer(1) -> Ethernet > - Integer(2) -> USB > - Integer(3) -> Fibre > > Excerpt from the hypothetical MIB: > ManufacturerXInterfaceType ::= TEXTUAL-CONVENTION > STATUS current > DESCRIPTION > " Define the hardware type of a given network interface. " > SYNTAX INTEGER > { > Ethernet(1) > USB(2) > Fibre(3) > } > > lanDeviceInterfaceType OBJECT-TYPE > SYNTAX ManufacturerXInterfaceType > MAX-ACCESS read-write > STATUS current > DESCRIPTION > "The interface type of the current row " > ::= { lanDeviceTable 3} > > Here is a hypothetical class ManufacturerXInterfaceType that I can > pass around my application that is more useful than just an rfc1902 > Integer. > > Pseudocode: > class ManufacturerXInterfaceType: > def __str__(self): > if self.value == 1: > return 'Ethernet' > ellif self.value == 2: > return 'USB' > elif self.value == 3: > return 'Fibre' > > I would like to find a way of determining the textual > convention/SYNTAX parameter type an OID is defined as using in the > manufacturer MIBs. In the following pseudocode example, I need some > advice on writing the "magic_function_to_get_textual_convention" > function. Is there a method on the MibVariable to see what SYNTAX > parameter used for an OID? > > cmdgen = rfc3413.oneliner.CommandGenerator() > mibVar = cmdgen.MibVariable('modName', 'varName') > errIndication, errStatus, errIndex, data = > cmdgen.cmdGet(community_string, udp_transport, mibVar) > textual_convention = magic_function_to_get_textual_convention(mibVar, data) > if textual_convention == "ManufacturerXInterfaceType": > interface = ManufacturerXInterfaceType(data) > elif textual_convention == "SomeOtherCustomType" > ... > > Pysnmp.entity.rfc3413.mibvar has a couple of convenience functions for > determining additional information about an OID. mibvar.mibNameToOid > and mibvar.oidToMibName are quite useful, but I am looking for > something similar that will give me additional information about the > definition of the OID. |