Writing a MIB Module
http://www.net-snmp.org/wiki/index.php/TUT:Writing_a_MIB_Module
******compile******
Compiling in your new MIB module
Note: you will need to have previously installed the Net-SNMP Source Package on your system before proceeding.
There are a few ways to get your new MIB module loaded and accessible via SNMP requests. We'll discuss all three ways separately. To make this easy to test the procedures outlined below, we've provided three simple mib modules which implement the
three simple scalars in the
NET-SNMP-TUTORIAL-MIB MIB. To see how MIBs can be properly used by the tools, please see the
mib-options tutorial.
-
- Compile it into the master agent.
Lets assume you're going to compile in a new mib module. For our example, lets use the
example mib module and it's
header file. To do this, you would put the nstAgentModuleObject.h and nstAgentModuleObject.c files into the net-snmp source code directory. You do this by copying them into a agent/mibgroup/nstAgentModuleObject.h and agent/mibgroup/nstAgentModuleObject.c
file.
Next, you have to configure the package to find them and compile them into the agent. To do this, you run the configure script giving it the extra module names you want it to load:
% ./configure --with-mib-modules="nstAgentModuleObject"
If you had multiple modules to include (like a second "XXX" module, for example), you can separate them with spaces inside the quotes (e.g., --with-mib-modules="nstAgentModuleObject XXX").
Note that nstAgentModuleObject is the prefix and the configure script will actually look for a nstAgentModuleObject.h and a nstAgentModuleObject.c file. You must have a .h file and you can not get it to work with just a .c file.
Build your new agent with your new code in it by running make:
% make
Finally, install the whole lot by running make install:
% make install
******config snmpd.conf******
rocommunity tutget .1.3.6.1.4.1.8072.2.4
rwcommunity tutset .1.3.6.1.4.1.8072.2.4
rouser noAuthUser
rouser MD5User
rwuser MD5DESUser
createUser NoAuthUser
createUser MD5User MD5 "The Net-SNMP Demo Password"
createUser MD5DESUser MD5 "The Net-SNMP Demo Password" DES
******snmpd******
/usr/local/sbin/snmpd -f -L -d -c /usr/local/net-snmp/share/snmp/snmpd.conf
******GET******
# snmpget -v2c -c tutget localhost NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0
NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0 = INTEGER: 42
snmpd:
Received 48 byte packet from UDP: [127.0.0.1]:54770->[127.0.0.1]:161
0000: 30 2E 02 01 01 04 06 74 75 74 67 65 74 A0 21 02 0......tutget.!.
0016: 04 0D 13 B7 FF 02 01 00 02 01 00 30 13 30 11 06 ...........0.0..
0032: 0D 2B 06 01 04 01 BF 08 02 04 01 01 01 00 05 00 .+..............
Sending 49 bytes to UDP: [127.0.0.1]:54770->[127.0.0.1]:161
0000: 30 2F 02 01 01 04 06 74 75 74 67 65 74 A2 22 02 0/.....tutget.".
0016: 04 0D 13 B7 FF 02 01 00 02 01 00 30 14 30 12 06 ...........0.0..
0032: 0D 2B 06 01 04 01 BF 08 02 04 01 01 01 00 02 01 .+..............
0048: 2A
# snmpget -v 3 -n "" -u MD5User -a MD5 -A "The Net-SNMP Demo Password" -l authNoPriv 127.0.0.1 nstAgentModuleObject.0
NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0 = INTEGER: 42
snmpd res:
Received 64 byte packet from UDP: [127.0.0.1]:45470->[127.0.0.1]:161
0000: 30 3E 02 01 03 30 11 02 04 73 29 2A 2C 02 03 00 0>...0...s)*,...
0016: FF E3 04 01 04 02 01 03 04 10 30 0E 04 00 02 01 ..........0.....
0032: 00 02 01 00 04 00 04 00 04 00 30 14 04 00 04 00 ..........0.....
0048: A0 0E 02 04 39 27 3A E8 02 01 00 02 01 00 30 00 ....9':.......0.
Sending 108 bytes to UDP: [127.0.0.1]:45470->[127.0.0.1]:161
0000: 30 6A 02 01 03 30 11 02 04 73 29 2A 2C 02 03 00 0j...0...s)*,...
0016: FF E3 04 01 00 02 01 03 04 1E 30 1C 04 0D 80 00 ..........0.....
0032: 1F 88 80 FD 95 71 5A F4 6C 5F 52 02 01 27 02 02 .....qZ.l_R..'..
0048: 05 F5 04 00 04 00 04 00 30 32 04 0D 80 00 1F 88 ........02......
0064: 80 FD 95 71 5A F4 6C 5F 52 04 00 A8 1F 02 04 39 ...qZ.l_R......9
0080: 27 3A E8 02 01 00 02 01 00 30 11 30 0F 06 0A 2B ':.......0.0...+
0096: 06 01 06 03 0F 01 01 04 00 41 01 0F .........A..
Received 129 byte packet from UDP: [127.0.0.1]:45470->[127.0.0.1]:161
0000: 30 7F 02 01 03 30 11 02 04 73 29 2A 2B 02 03 00 0....0...s)*+...
0016: FF E3 04 01 05 02 01 03 04 31 30 2F 04 0D 80 00 .........10/....
0032: 1F 88 80 FD 95 71 5A F4 6C 5F 52 02 01 27 02 02 .....qZ.l_R..'..
0048: 05 F5 04 07 4D 44 35 55 73 65 72 04 0C F3 B8 58 ....MD5User....X
0064: 54 59 E6 87 EB 23 81 18 29 04 00 30 34 04 0D 80 TY...#..)..04...
0080: 00 1F 88 80 FD 95 71 5A F4 6C 5F 52 04 00 A0 21 ......qZ.l_R...!
0096: 02 04 39 27 3A E7 02 01 00 02 01 00 30 13 30 11 ..9':.......0.0.
0112: 06 0D 2B 06 01 04 01 BF 08 02 04 01 01 01 00 05 ..+.............
0128: 00 .
Sending 131 bytes to UDP: [127.0.0.1]:45470->[127.0.0.1]:161
0000: 30 81 80 02 01 03 30 11 02 04 73 29 2A 2B 02 03 0.....0...s)*+..
0016: 00 FF E3 04 01 01 02 01 03 04 31 30 2F 04 0D 80 ..........10/...
0032: 00 1F 88 80 FD 95 71 5A F4 6C 5F 52 02 01 27 02 ......qZ.l_R..'.
0048: 02 05 F5 04 07 4D 44 35 55 73 65 72 04 0C 6F 33 .....MD5User..o3
0064: CB FA 9D AB 11 D6 15 92 DC 7B 04 00 30 35 04 0D .........{..05..
0080: 80 00 1F 88 80 FD 95 71 5A F4 6C 5F 52 04 00 A2 .......qZ.l_R...
0096: 22 02 04 39 27 3A E7 02 01 00 02 01 00 30 14 30 "..9':.......0.0
0112: 12 06 0D 2B 06 01 04 01 BF 08 02 04 01 01 01 00 ...+............
0128: 02 01 2A
*******SET******
# snmpset -v 3 -n "" -u MD5DESUser -a MD5 -A "The Net-SNMP Demo Password" -x DES -X "The Net-SNMP Demo Password" -l authNoPriv 127.0.0.1 nstAgentModuleObject.0 = 6
# snmpget -v 3 -n "" -u MD5DESUser -a MD5 -A "The Net-SNMP Demo Password" -x DES -X "The Net-SNMP Demo Password" -l authNoPriv 127.0.0.1 nstAgentModuleObject.0
NET-SNMP-TUTORIAL-MIB::nstAgentModuleObject.0 = INTEGER: 6