Difference between revisions of "TUT:mib2c General Overview"
Line 49: | Line 49: | ||
So once you've generated the template (aka skeleton) code for your mib, you need to edit the code and implement the portions of the code specific to your module. As more elaborate configuration files are developed, it should become simpler to identify the what/when/where portions of the code (the MFD configuration file is the latest step towards this goal - see the MFD tutorial [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/mfd/ here]). | So once you've generated the template (aka skeleton) code for your mib, you need to edit the code and implement the portions of the code specific to your module. As more elaborate configuration files are developed, it should become simpler to identify the what/when/where portions of the code (the MFD configuration file is the latest step towards this goal - see the MFD tutorial [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/mfd/ here]). | ||
− | The next section covers the shell script mib2c-update, which is a wrapper around mib2c to help you take advantage of updates to the configuration file you chose for your mib module. | + | The next section covers the shell script [[TUT:mib2c-update | mib2c-update]], which is a wrapper around mib2c to help you take advantage of updates to the configuration file you chose for your mib module. |
+ | |||
+ | {{TUT:LIST}} |
Revision as of 17:12, 8 February 2007
This brief tutorial presents an overview of generating skeleton C code for a SNMP MIB using the mib2c utility.
For mib2c to work, it needs to be able to find the MIB file that defines the MIB for which it will be generating code. Running mib2c without arguments informs you of this:
You didn't give mib2c a valid OID to start with. IE, I could not find any information about the mib node "". This could be caused because you supplied an incorrectly node, or by the MIB that you're trying to generate code from isn't loaded. To make sure your mib is loaded, run mib2c using this as an example: env MIBS="+MY-PERSONAL-MIB" mib2c You might wish to start by reading the MIB loading tutorial at: http://www.net-snmp.org/wiki/index.php/TUT:Using_and_loading_MIBS And making sure you can get snmptranslate to display information about
your MIB node. Once snmptranslate works, then come back and try mib2c again.
So, if you are interested in generating code for your table XYZTable, make sure that
snmptranslate -IR XYZTable
works first.
When you run mib2c, you must specify a MIB node for it to process. You can also specify which configuration file you would like it to use to generate the code. The available options are:
mib2c.array-user.conf mib2c.create-dataset.conf mib2c.int_watch.conf mib2c.iterate.conf mib2c.iterate_access.conf mib2c.mfd.conf mib2c.notify.conf mib2c.old-api.conf mib2c.scalar.conf
Running mib2c without specifying a configuration file will prompt you with some questions to help determine which one might be appropriate for your situation.
One thing many people get confuse about is what to do after running mib2c. Contrary to popular belief, simply running mib2c on a MIB does not generate a complete implementation for the module, as indicated by this warning printed after running mib2c without specifying a configuration file:
********************************************************************** * NOTE WELL: The code generated by mib2c is only a template. *YOU* * * must fill in the code before it'll work most of the time. In many * * cases, spots that MUST be edited within the files are marked with * * /* XXX */ or /* TODO */ comments. * **********************************************************************
So once you've generated the template (aka skeleton) code for your mib, you need to edit the code and implement the portions of the code specific to your module. As more elaborate configuration files are developed, it should become simpler to identify the what/when/where portions of the code (the MFD configuration file is the latest step towards this goal - see the MFD tutorial here).
The next section covers the shell script mib2c-update, which is a wrapper around mib2c to help you take advantage of updates to the configuration file you chose for your mib module.
Contents
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
- General mib2c Overview
- Using the mib2c-update script to recode your code
- mib2c.mfd.conf tutorial
- 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: