Logo
Home page Net-SNMP

Archive Search:

Require all words?

Site Search:
Google

NET-SNMP Tutorial -- Demon


*** WARNING WARNING WARNING ***

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.


We strongly recomment that AgentX subagent developers use the 5.1 or 5.2 versions of net-snmp. The AgentX support in the 5.0 versions of the net-snmp package is still beta level quality. Although many people have used it successfully, we're not confident enough yet to say that its bug free (and in fact we know its not in areas). Use at your own risk.

Sub-Agent Demon tutorial

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:

FileDescription
MakefileA simple makefile used to build the projects
UCD-SNMP-TUTORIAL-MIB.txtThe MIB we'll be serving
ustScalarSet.hThe mib module's header file (same)
ustScalarSet.cThe mib module's C source code (same)
ustMain.cThe main() code for our demon
snmpd.confThe 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
      

Valid CSS!


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.