[Switch] SNMP programming experience summary

Reprinted from http://blog.chinaunix.net/uid-20644632-id-4115425.html

 

SNMP programming experience summary Leng Shengkui (Seaquester)
[email protected]
2013-10-30

1. MIB modules are generally composed of variables and tables. Therefore, net-snmp divides the objects in SMI into two categories: scalar and table. scalar contains data types such as integers and strings that we commonly use. A table is a collection of scalars consisting of one or more columns, similar to a table in a database. It must have an index entry, which is used to retrieve table entries in order.

2. The mib2c tool parses the MIB file into .c and .h files through the template, but it only generates a framework, and you need to manually add the corresponding code in the corresponding place. mib2c has many templates, which can be called as needed. mib2c currently does not support parsing scalar and table objects at the same time. For MIB modules with these two objects, code files need to be generated separately and then merged.

3. When defining an object in the MIB file, pay attention that the name of the object cannot contain an underscore "_", otherwise, when using mib2c to generate code, it will prompt error: Bad operator (_): At line nn in xx_MIB.txt.

4. When writing a MIB file today, I found that if Table is defined, you need to pay attention to the name of Table (the name must have Table). Otherwise, it may not be possible to generate code with mib2c.

5. If there is a Table in the MIB file, after generating the code with mib2c, it should be noted that the Index field of the Table may be defined repeatedly. Careful inspection is required.

6. The SNMP Agent module written by the net-snmp library supports two modes. One is the master agent, the agent in this mode can run without snmpd.
The other is sub-agent, which must depend on snmpd to run. The sub-agent communicates with snmpd through the AgentX protocol (local socket).
Before running the sub-agent, snmpd.conf must be modified. The easiest way is to create a new file with only the following lines:
    rocommunity public
    rwcommunity private
    master agentx
These lines mainly tell snmpd to enable the AgentX protocol, the community definition of the sub-agent, etc.
Then, start snmpd first, and then run the sub-agent program.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326675039&siteId=291194637