Difference between revisions of "TUT:Writing a Dynamically Loadable Object"
(→Loading via the snmpd.conf file) |
|||
Line 67: | Line 67: | ||
=== Loading via the snmpd.conf file === | === Loading via the snmpd.conf file === | ||
− | + | You can also load shared objects using the "dlmod" token in the snmpd.conf file by putting a line like this in your snmpd.conf file: | |
dlmod nstAgentPluginObject /path/to/nstAgentPluginObject.so | dlmod nstAgentPluginObject /path/to/nstAgentPluginObject.so | ||
Revision as of 16:43, 8 February 2007
First off, you need to write a mib module first before you can do this part of the tutorial. We assume you have read and completed the mib module portion of the toolkit tutorial. This part of the tutorial shows how to install a dynamic module into the agent, assuming you already have written a mib-module which we'll then compile into a dynamic module. For example purposes, we'll refer to some example MIB objects and code: the NET-SNMP-TUTORIAL-MIB MIB, and the example mib module and it's header file.
Note: For this to work, you must have compiled the net-snmp package with dynamicly loadable module support turned on, as well as built it with --enable-shared turned on. (It's on by default, if your system supports it). You can check for support in your agent but looking at the output of the "snmpd -H" command for the "dlmod" token. If its listed, the compiled agent supports it.
Note: All command line options below assume you have an appropriately setup ~/.snmp/snmp.conf file that allows you to not have to specify a snmp version number, community name, username, or whatever else in order to talk to your agent. The agent, of course, must have a matching /usr/local/share/snmp/snmpd.conf file (or equivalent).
Here are the files discussed in this example so you can download them:
XXX File Description Makefile A simple makefile used to build the projects NET-SNMP-TUTORIAL-MIB.txt The MIB we'll be writing code for nstAgentPluginObject.h The mib module's header file nstAgentPluginObject.c The mib module's C source code
The shared object loader calls the "init_nstAgentPluginObject()" function in the above code when it gets loaded, and calls the "deinit_nstAgentPluginObject()" when (and if) the module is unloaded. These function names to use are built by adding the shared object's module name (UCD-DLMOD-MIB::dlmodName) to the `init_' and `deinit_' prefixes.
Contents
- First off we must get the Makefile file, the nstAgentPluginObject.h file, and the nstAgentPluginObject.c file.
- make nstAgentPluginObject.so
- Start the snmpd and watch the dlmod and nstAgentPluginObject modules interact using the debugging flag (this assumes you already have access control set up properly for your agent):
% snmpd -f -L -DnstAgentPluginObject,dlmod
- In another window, test to make sure that the agent doesn't currently support the nstAgentPluginObject (if you get different results running this command you need to recompile the net-snmp agent without the nstAgentPluginObject mib module compiled in directly):
% snmpget localhost NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0 nstAgentPluginObject.0 = No Such Object available on this agent at this OID
- Then, run snmpset to create a new row in the dlmod table:
% snmpset localhost UCD-DLMOD-MIB::dlmodStatus.1 i create dlmodStatus.1 = create(6)
- See that the row was created:
% snmptable localhost UCD-DLMOD-MIB::dlmodTable SNMP table: dlmodTable dlmodName dlmodPath dlmodError dlmodStatus unloaded
- Then set the properties of the row up to point to our new object and to give it a name:
% snmpset localhost UCD-DLMOD-MIB::dlmodName.1 s "nstAgentPluginObject" UCD-DLMOD-MIB::dlmodPath.1 s "/path/to/nstAgentPluginObject.so" dlmodName.1 = "nstAgentPluginObject" dlmodName.1 = "/path/to/nstAgentPluginObject.so" % snmptable localhost UCD-DLMOD-MIB::dlmodTable SNMP table: dlmodTable dlmodName dlmodPath dlmodError dlmodStatus nstAgentPluginObject /path/to/nstAgentPluginObject.so unloaded
- Finally, load the shared object into the running agent:
% snmpset localhost UCD-DLMOD-MIB::dlmodStatus.1 i load dlmodStatus.1 = loaded(1) % snmptable localhost UCD-DLMOD-MIB::dlmodTable
SNMP table: dlmodTable
dlmodName dlmodPath dlmodError dlmodStatus nstAgentPluginObject /path/to/nstAgentPluginObject.so loaded
- If everything above was done correctly, then the following command should work and will access the shared object's data:
% snmpget localhost NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0 nstAgentPluginObject.0 = INTEGER: 3
Loading via the snmpd.conf file
You can also load shared objects using the "dlmod" token in the snmpd.conf file by putting a line like this in your snmpd.conf file:
dlmod nstAgentPluginObject /path/to/nstAgentPluginObject.so
The first argument specifies the shared object's module name (UCD-DLMOD-MIB::dlmodName) and second argument specifies the full pathname of the shared object file.
Tutorial Sections
About the SNMP Protocol
These tutorial links talk about SNMP generically and how the protocol itself works. They are good introductory reading material and the concepts are important to understand before diving into the later tutorials about Net-SNMP itself.
- How SNMP Works: About the protocol itself (GETs, GETNEXTs, etc)
- What data is in SNMP: All about SNMP Management Information Bases (MIBs)
- Securing SNMP: How to use the SNMP protocol securely
Net-SNMP Command Line Applications
These tutorial pages discuss the command line tools provided in the Net-SNMP suite of tools. Nearly all the example commands in these tutorials works if you try it yourself, as they're all examples that talk to our online Net-SNMP test agent. Given them a shot!
- snmptranslate: learning about the MIB tree.
- snmpget: retrieving data from a host.
- snmpgetnext: retrieving unknown indexed data.
- snmpwalk: retrieving lots of data at once!
- snmptable: displaying a table.
- snmpset: peforming write operations.
- snmpbulkget: communicates with a network entity using SNMP GETBULK request
- snmpbulkwalk: retrieve a sub-tree of management values using SNMP GETBULK requests.
- snmptrap: Sending and receiving traps, and acting upon them.
- Traps/informs with SNMPv3/USM: Sending and receiving SNMPv3/USM TRAPs and INFORMs
- Sending Traps/Informs via AgentX: Sending notifications from the command line through snmpd
- Common command line options:
- Writing mib2c config files
Application Configuration
All of our applications support configuration to allow you to customize how they behave.
Net-SNMP Daemons
Net-SNMP comes with two long-running daemons: a SNMP agent (snmpd) for responding to management requests and a notification receiver (snmptrapd) for receiving SNMP notifications.
- SNMP Agent (snmpd) Configuration
- SNMP Notification Receiver (snmptrapd)
- Agent Monitoring
Coding Tutorials
Net-SNMP comes with a highly flexible and extensible API. The API allows you to create your own commands, add extensions to the agent to support your own MIBs and perform specialized processing of notifications.
- Client / Manager Coding Tutorials
- Agent Coding Tutorials
- The Agent Architecture page might be worth reading before or after the agent coding tutorials, and describes how the Agent Helpers work under the hood.
- Writing a mib module to serve information described by an SNMP MIB, and how to compile it into the net-snmp snmpd agent.
- Writing a Dynamically Loadable Object that can be loaded into the SNMP agent.
- Writing a Subagent that can be run to attach to the snmpd master agent.
- Writing a perl plugin to extend the agent using the NetSNMP::agent module.
- Writing shell scripts to extend the agent
- Using mib2c to help write an agent code template for you
- Header files and autoconf
Debugging SNMP Applications and Agents
All our tools and applications have extensive debugging output. These tutorials talk about how the debugging system works and how you can add your own debugging statements to you code:
- Debugging output printed using the -D command line option
- Using -Ddump to display packet breakdowns
- Debugging using GDB
Operating System Specific Tutorials
- Building With Visual Studio 2005 Express
- Building Net-SNMP 64-bit with Visual C++ 2010 Express
- Net-Snmp on Ubuntu
- Net-SNMP and lm-sensors on Ubuntu 10.04
- Net-SNMP for windows: