Difference between revisions of "TUT:snmptranslate"
(Full reworking) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
The SNMP protocol tends to work with numeric OIDs and raw values. One of the main roles of the MIB files is to convert these into more meaningful textual names and sensibly formatted values. | The SNMP protocol tends to work with numeric OIDs and raw values. One of the main roles of the MIB files is to convert these into more meaningful textual names and sensibly formatted values. | ||
− | While most of the Net-SNMP command-line applications can control how the results of an SNMP query are displayed, there is one tool (<tt>snmptranslate</tt>) which can be used standalone, simply | + | While most of the Net-SNMP command-line applications can control how the results of an SNMP query are displayed, there is one tool (<tt>[[snmptranslate]]</tt>) which can be used standalone, simply displays information drawn from the MIB files themselves. |
+ | |||
+ | See [[TUT:Using and loading MIBS]]. | ||
== OID Conversion == | == OID Conversion == |
Latest revision as of 23:35, 30 June 2011
The SNMP protocol tends to work with numeric OIDs and raw values. One of the main roles of the MIB files is to convert these into more meaningful textual names and sensibly formatted values.
While most of the Net-SNMP command-line applications can control how the results of an SNMP query are displayed, there is one tool (snmptranslate) which can be used standalone, simply displays information drawn from the MIB files themselves.
See TUT:Using and loading MIBS.
OID Conversion
In its simplest form, snmptranslate takes a numeric OID and displays the corresponding textual MIB name:
% snmptranslate .1.3.6.1.2.1.1.3.0 SNMPv2-MIB::sysUpTime.0
It can also perform the reverse translation, taking the textual MIB name and displaying the numeric OID. This uses the -On flag:
% snmptranslate -On SNMPv2-MIB::sysUpTime.0 .1.3.6.1.2.1.1.3.0
There are several other ways of displaying an OID, which are described in TUT:Customized_Output_Formats. One of these is to show the full list of MIB subidentifier names, using the -Of flag:
% snmptranslate -Of SNMPv2-MIB::sysUpTime.0 .iso.org.dod.internet.mib-2.system.sysUpTime.0
Note that these flags determine how the OID should be displayed, regardless of how it was originally specified:
% snmptranslate .iso.3.6.1.private.enterprises.2021.2.1.prNames.0 NET-SNMP-MIB::prNames.0 % snmptranslate -On .iso.3.6.1.private.enterprises.2021.2.1.prNames.0 .1.3.6.1.4.1.2021.2.1.2.0 % snmptranslate -Of .iso.3.6.1.private.enterprises.2021.2.1.prNames.0 .iso.org.dod.internet.private.enterprises.ucdavis.procTable.prEntry.prNames.0
Specifying a MIB object
The examples above identified a particular object, either by providing the full list of MIB subidentifiers (numeric, textual or a mixture), or by specifying the relevant MIB module containing the desired MIB object. However MIB objects are guaranteed to be unique within IETF standard MIBs (and are rarely duplicated across vendor-supplied MIBs either). So it would usually be sufficient to simply give the bare MIB object name, with no further qualifications. Snmptranslate uses the -IR flag to do this "random-access" lookup:
% snmptranslate sysUpTime.0 Invalid object identifier: sysUpTime.0 % snmptranslate -IR sysUpTime.0 SNMPv2-MIB::sysUpTime.0
(The other commands do this by default - only snmptranslate needs it to be explicitly turned on).
It's even possible to provide a regex pattern, and have snmptranslate (or the other command-line tools) do a "best-match" search to find the appropriate MIB object. This uses the -Ib flag:
% snmptranslate -Ib 'sys.*ime' system.sysUpTime
However these approaches do run the risk (however slight) of selecting the wrong MIB object. It's safest to use one of the earlier forms.
To get a list of all the nodes that match a given pattern, use the -TB flag:
% snmptranslate -TB 'sys.*ime' SNMPv2-MIB::sysORUpTime SNMPv2-MIB::sysUpTime HOST-RESOURCES-MIB::hrSystemUptime
Further Information
To get extended information about a particular MIB node, use the -Td flag to display the full description from the MIB file:
% snmptranslate -On -Td SNMPv2-MIB::sysUpTime .1.3.6.1.2.1.1.3 sysUpTime OBJECT-TYPE -- FROM SNMPv2-MIB, RFC1213-MIB SYNTAX TimeTicks MAX-ACCESS read-only STATUS current DESCRIPTION "The time (in hundredths of a second) since the network management portion of the system was last re-initialized." ::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) system(1) 3 }
This can be combined with the other flags described earlier:
% snmptranslate -On -Td -IR sysUpTime % snmptranslate -On -Td -Ib 'sys.*ime'
to give the same results.
Finally, it's possible to display a formatted diagram of a selected subset of the MIB tree, using the -Tp flag:
% snmptranslate -Tp -IR system +--system(1) | +-- -R-- String sysDescr(1) | Textual Convention: DisplayString +-- -R-- ObjID sysObjectID(2) +-- -R-- TimeTicks sysUpTime(3) +-- -RW- String sysContact(4) | Textual Convention: DisplayString +-- -RW- String sysName(5) | Textual Convention: DisplayString +-- -RW- String sysLocation(6) | Textual Convention: DisplayString +-- -R-- Integer sysServices(7) +-- -R-- TimeTicks sysORLastChange(8) | Textual Convention: TimeStamp | +--sysORTable(9) | +--sysOREntry(1) | +-- ---- Integer sysORIndex(1) +-- -R-- ObjID sysORID(2) +-- -R-- String sysORDescr(3) | Textual Convention: DisplayString +-- -R-- TimeTicks sysORUpTime(4) Textual Convention: TimeStamp
This shows the accessibility (read-only, or read-write), syntax, name and subidentifier of each MIB object within the specified subtree, together with the internal structure of those MIB objects.
Running snmptranslate -Tp without an OID argument will display this information for the known MIB tree in its entirety. This is left as an exercise for the student!
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: