Note: Much of this tutorial requires ucd-snmp-4.2.2 or higher!, so make sure you get it before running the commands found in this tutorial.
Note: A new tutorial for net-snmp 5.0 and above is available as well. The commands is
the ucd-snmp specific tutorial will not work as expected if you
are using net-snmp and not ucd-snmp.
Finally, lets take the previous example and implement it in our own process which attaches to the master agent using the AgentX protocol. This is easier than you might think, as we provide libraries to do the work for you and additionally the mib module code that we wrote in the last section does not have to change at all. We merely compile it ourselves this time, outside the main net-snmp package and put a main() wrapper around it.
First, the files you'll need:
File | Description |
---|---|
Makefile | A simple makefile used to build the projects |
UCD-SNMP-TUTORIAL-MIB.txt | The MIB we'll be serving |
ustScalarSet.h | The mib module's header file (same) |
ustScalarSet.c | The mib module's C source code (same) |
ustMain.c | The main() code for our demon |
snmpd.conf | The example configuration file for access control |
Now, build and install the net-snmp package. You'll need to configure it for AgentX support by compiling in those mib modules, so run configure like:
% ./configure --with-mib-modules="agentx"
This will actually compile the code for both the master and the subagent support. Do not compile in the ustScalarSet code like you did last time! The demon that it builds when you run make will by default be a master agent:
% make % make install
Now, you can fire up the master agent using the configuration file found above. As root (of course):
% /usr/local/sbin/snmpd -C -c snmpd.conf
Once the agent is started, we can build and attach our own to it.
To do so, compile the ustMain program using the Makefile found above. Note that it links with the libucdagent and the libucdmibs libraries in addition to the regular libsnmp one.
% make cc -I/usr/local/include -g -c ustMain.c -o ustMain.o cc -I/usr/local/include -g -c ustScalarSet.c -o ustScalarSet.o cc -o ustMain ustMain.o ustScalarSet.o -L/usr/local/lib -lucdagent -lucdmibs -lsnmp
Then run snmpwalk to ensure that the current running demon is missing the code we've just built and that it doesn't exist:
% snmpwalk localhost democommunity ucdavis.13.4242
Then run the application we just built:
% ./ustMain
That should attach to the running agent and make it now respond to our same query above, but with results this time:
% snmpwalk localhost democommunity ucdavis.13.4242
Last modified: Wednesday, 01-Aug-2018 04:41:28 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.