TUT:snmptranslate

From Net-SNMP Wiki
Revision as of 19:23, 23 January 2007 by Wes (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

snmptranslate

The snmptranslate tool is a very powerful tool that allows you to browse the MIB tree in various ways from the command line. In its simplest form, it merely looks up an OID and spits it back out in textual form:

 % snmptranslate .1.3.6.1.2.1.1.3.0
 SNMPv2-MIB::sysUpTime.0


It can also translate into numerical results as well, by adding the -On flag to its options

 % snmptranslate -On SNMPv2-MIB::system.sysUpTime.0
 .1.3.6.1.2.1.1.3.0


Note that the argument passed can describe a OID in any fashion, and the -On flag merely toggles which type of output is displayed:

 % 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


Note how the oid was abbreviated for you? You can change this behaviour as well with -Of:

 % snmptranslate -Of .iso.3.6.1.private.enterprises.2021.2.1.prNames.0
 .iso.org.dod.internet.private.enterprises.ucdavis.procTable.prEntry.prNames.0


The problem with the above commands is that you have to remember the entire OID for what you're looking for. Now, we wouldn't be a very good package if we didn't provide some sort of random-access lookup function right? Well, the good news is that we do. -IR nicely does this for us, and searches the MIB tree for the node you want:

 % snmptranslate sysUpTime.0
 Invalid object identifier: sysUpTime.0
 % snmptranslate -IR sysUpTime.0
 SNMPv2-MIB::sysUpTime.0


Finally, it'll even try to do regex pattern matching to find the exact node you want given only a piece of its name by using the -Ib (best match) option:

 % snmptranslate -Ib 'sys.*ime'
 system.sysUpTime

To get a list of all the nodes that match a given pattern, use the -TB flag:

 % snmptranslate -TB 'vacm.*table'
 SNMP-VIEW-BASED-ACM-MIB::vacmViewTreeFamilyTable
 SNMP-VIEW-BASED-ACM-MIB::vacmAccessTable
 SNMP-VIEW-BASED-ACM-MIB::vacmSecurityToGroupTable
 SNMP-VIEW-BASED-ACM-MIB::vacmContextTable

To get extended information about a mib node, use the -Td (description) flag:

 % snmptranslate -On -Td -Ib 'sys.*ime'
 .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 }


Finally, last but certainly not least, if you want a pretty diagram of a section of the mib tree, check out 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

As a homework assignment, we'll leave it up to you to run snmptranslate -Tp without an oid argument, which prints the known MIB tree in its entirety.