Obtain the OID

Function Description

You can use a Python script to obtain the OID of a specified leaf node.

Command Prototype

# Obtain the OID of a specified leaf node.

opsObj.snmp.get(oid)

# Obtain the OID of the next hop node of a specified leaf node.

opsObj.snmp.getnext(oid)

Parameter Description

Table 1 describes the parameters supported by APIs for obtaining OID values.
Table 1 Parameters supported by APIs for obtaining OID values

Method

Description

opsObj

Specifies an OPS object. It is obtained through ops.ops() instantiation.

oid

The value is a character string, such as 1.3.6.1.2.1.7.1.0.

Description of Return Values

  • First return value: None indicates that the OID value fails to be obtained, and other values indicate that the OID value is obtained successfully.
  • Second return value: result description expressed in a character string.

Example

test.py

import ops

opsObj = ops.ops()

curValue, ret = opsObj.snmp.get("1.3.6.1.2.1.2.2.1.1")
print("ret is ", ret, " and current value of OID is ", curValue, "\n")

nextVal, nextOid, ret = opsObj.snmp.getnext("1.3.6.1.2.1.2.2.1.1")
print("ret is ", ret, " the next OID of the current OID is ", nextOid, " and the corresponding value is ", nextVal, "\n")

This API is used to obtain the OID of a specified leaf node and the OID of the next node.

Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic Next topic >