Search code examples
variablessnmpmiboid

Use pysnmp to determine OID value type


When dealing with multiple variable-bindings in 1 snmp packet, tshark cannot parse it properly such that the OID-to-value can be determined. Therefore, I have to query the packet by value type and use the results to figure out which OID was set to what. For this to work, I need to know each OID's value type beforehand.

Is there a way to query an OID (even if the instance is not created) and have it return the type (such as Integer32, Gauge32, OctetString, etc)?

I also tried using snmpwalk but that only returns the value when the OID instance is already set. If it is not set it returns "no such instance currently exists at this OID"

The MIB must already know what type it is expecting because if you try to set it to the wrong type you get an error... I am just trying to figure out how to access this information

Thanks!


Solution

  • No, there is no way to query a running SNMP Agent for anything other than variables that have been instantiated.

    If you need to know which type a variable will have, there is help for you in the MIB document. It specifies, for each scalar variable and for each table column, what the appropriate type is. When it receives a query for a variable, the Agent is obliged to provide a value of the type specified in the MIB. If it returns a different type, that's a bug in the agent.

    You should be able to get the MIB document from the vendor of the SNMP Agent you are querying. Often it's published as part of the system administrator's guide or similar, or you might have to request it from their customer support.