Extending Net-SNMP 220.127.116.11 Agent
This article describes how to extend Net-SNMP agent toolkit to instrument the EtherLike-MIB (RFC 3635) with hardcoded defaults. This article will describe the setup on windows (I used XP SP3) and Linux (I used openSUSE 11.0) required to develop this agent.
The following instructions were carried out for net-snmp source version 18.104.22.168. This article assumes the following default paths:
- Net-SNMP un-archived on windows in C:\net-snmp and ~/net-snmp on Linux.
- Net-SNMP installed in C:\usr on Windows and /usr/local on Linux.
1.1. Setup the development environment
- Download and install MSVC++ Express 2005 from http://www.microsoft.com/express/2005/download/default.aspx. There is some compilation issue of the net-snmp code with MSVC++ 2008 (Orcas) and i did not bother to fix it but used the 2005 instead.
- Download and setup platform sdk as described in http://www.microsoft.com/express/2005/platformsdk/default.aspx. Be sure to setup the development environment using the PSDK as described in the link step-wise.
- Download net-snmp source from http://www.net-snmp.org/download.html. The net-snmp version 22.214.171.124 can be downloaded from there.
1.2. Build and install net-snmp from source on windows
- Un-archive the net-snmp source to say c:\net-snmp.
- Follow the README.win32 to build the net-snmp code (Read the section Microsoft Visual C++ - Workspace – Building).
- We need to first load the winsdk.dsw in the MSVC++ 2005 express. Below is the screenshot of all projects that make up the win32sdk workspace in MSVC++.
Figure 1 - Projects in win32sdk.dsw
- Modify the win32\netsnmp\netsnmpconfig.h file to add:
#define HAVE_WIN32_PLATFORM_SDK 1
Build in order, the following project for (Release | Debug) configuration.
Go to Build > Batch Build… and select the (Debug | Release) configuration of all projects except for the ones you built in step c above.
If everything is okay with setup, then build should go fine too.
Using cmd line on windows, go to c:\net-snmp and run the command: win32\install_netsnmp.bat to install net-snmp you built above to location c:\usr.
Set the c:\usr\bin to PATH environment variable for easy access to the command line snmp client and agent executables.
1.3. Build and install net-snmp from source on Linux
Un-archive the net-snmp source to say ~/net-snmp.
Follow the INSTALL to build the net-snmp code. Run the following commands on shell prompt:
make install (run as root)
The make install step will install the net-snmp binaries by default in /usr/local path.
1.4. Configuring the snmpd agent (snmpd.conf)
Configure snmp agent by running snmpconf command (see man page) or copy the C:/net-snmp/Example.conf and modify.
snmpconf –g basic_setup
I used the following configuration. Copy-paste the text below into a file named snmpd.conf. The agent is configured for snmp v2c and with rwcommunity string of public.
Save the file in path :
C:\usr\etc\snmp\snmpd.conf (on Windows)
/etc/snmp/snmpd.conf (on Linux)
1.5. Load the MIB module and generate the C code
The EtherLike-MIB has 5 tables (columnar variables).
For mib2c code generation I used linux host. Run the following commands on shell prompt:
EtherLike-MIB was part of the net-snmp distribution so all we need is to tell mib2c to use it by setting the environment variable MIBS.
This will generate dot3StatsTable.c and dot3StatsTable.h files.
Similarly run the similar command for the other tables in the mib.
Use the ethmib_src and use it for windows agent extension too.
1.6. Use the generated source files to instrument the mib on Windows
On Windows, the above generated source files can be copied to c:\net-snmp\agent\mibgroups. You may also create a folder names EtherLike-MIB and sub-folders for each table like dot3StatsTable etc, and keep the respective table *.c and *.h files in the folder with the table name.
Add the generated sources in the MSVC++ netsnmpmibssdk project as shown below:
Figure 2 - EtherLike-MIB files added to the netsnmpmibssdk project.
Add the dot3StatsTable.h and dot3StatsTable.c files to your 'netsnmpmibssdk' project in VC++.
Next edit the '<sourcedir>\win32\mib_module_includes.h' file to add an include to your .h file.
Next edit the '<sourcedir>\win32\mib_module_inits.h' file to add code to call your initialize function.
1.7. Instrument the EtherLike-MIB
This section only instruments the dot3StatsTable generated source to return some default data. Other table instrumentation can be done in the similar manner.
Edit the dot3StatsTable.c file as shown below to return some hardcoded data. The changes to the generated code have been highlighted.
Now rebuild the netsnmpmibssdk project and then snmpdsdk project, in order.
Run the following command to re-install the modified agent with the dot3StatsTable changes.
Start the new agent as follows:
Open a MIB Browser to walk the dot3StatsTable instrumentation:
1.8. Instrumentation on Linux
Copy the generated source to the path ~/net-snmp/agent/mibgroups and run the following commands:
Start the snmpd as:
Run a command line snmpwalk to test it.
2. Co-existance with MS Windows SNMP Agent
We have 2 approaches to getting the net-snmp agent to co-exist with the Microsoft provided SNMP agent:
As of Net-SNMP 5.4, the Net-SNMP agent is able to load the Windows SNMP service extension DLLs by using the Net-SNMP winExtDLL extension. In this scenario, MS SNMP agent is installed but disabled. This is required because winExtDLL extension and existing windows extensions use Windows SNMP API from snmpapi.dll. The limitations of this approach are:
linkUp/Down generic traps are not received for some unknown reason.
sysUpTime.0 does not report the correct uptime for the agent. This is because the Windows extension checks for the uptime of the SNMP service, which is not running when Net-SNMP is running.
Alternatively, Net-SNMP agent can run as a proxy SNMP agent and will proxy for the MS SNMP agent (running at a non-default port) for those MIBs that MS SNMP agent instruments. For all other MIBs, Net-SNMP agent can service the SNMP requests. This approach does not suffer from the winExtDLL approach’s limitation, but then we need to run two snmp agents (net-snmp and MS snmp agents).
This sums up in short, the development setup required to get started with extending the net-snmp agent.