Logo
Home page Net-SNMP

Archive Search:

Require all words?

Site Search:
Google
Net-SNMP Tutorial -- Commands

Net-SNMP Tutorial -- Commands

All of the net-snmp commands pick a common set of options, which the next few sections will be discussing. The only commands that do not accept these common set of arguments are the running demons (like snmpd and snmptrapd).

A list of all of the options that are available for use from a command can be printed by passing "-h" on the command lien to any of the commands.

Command Options Affecting Output Formatting

All of the commands allow you to format their output in a manner which you personally will find attractive. The behavior is controlled using the -O flag:


Here are brief examples of all the above options in use:

  • -On

    This flag controls whether or not you want to display the results using numerical order to textual OIDs:

      % snmpgetnext -v 2c -c demopublic test.net-snmp.org sysObjectID system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.hpux10 % snmpgetnext -v 2c -On -c demopublic test.net-snmp.org sysObjectID .1.3.6.1.2.1.1.2.0 = OID: .1.3.6.1.4.1.2021.250.6
  • -Oe

    Similarly, this flag controls whether you want to display enumerated lists numerically or with textual translations:

      % snmpgetnext -v 2c -c demopublic test.net-snmp.org snmpEnableAuthenTraps snmp.snmpEnableAuthenTraps.0 = disabled(2) % snmpgetnext -v 2c -c demopublic test.net-snmp.org snmpEnableAuthenTraps snmp.snmpEnableAuthenTraps.0 = 2
  • -Ob

    Many SNMP tables are indexed by strings. The strings are then translated into OID segments so that they can be referenced in a SNMP request. The best way to understand this is through an example. So, let's take a look at the usmUserEntry object and how it is indexed:

      % snmptranslate -Td -IR usmUserEntry .1.3.6.1.6.3.15.1.2.2.1 usmUserEntry OBJECT-TYPE -- FROM SNMP-USER-BASED-SM-MIB MAX-ACCESS not-accessible STATUS current INDEXES { usmUserEngineID, usmUserName } DESCRIPTION "A user configured in the SNMP engine's Local Configuration Datastore (LCD) for the User-based Security Model. " ::= { iso(1) org(3) dod(6) internet(1) snmpV2(6) snmpModules(3) snmpUsmMIB(15) usmMIBObjects(1) usmUser(2) usmUserTable(2) 1 }

    As you can see by the above description, it is indexed by two different objects: usmUserEngineID, and usmUserName. Both of these are strings. The default for all of the commands is to breakdown the result for you to make it easier for you to decode the above indexes out of the printed result:

      % snmpgetnext -v 2c -c demopublic test.net-snmp.org usmUserEntry .iso.org.dod.internet.snmpV2.snmpModules.snmpUsmMIB.usmMIBObjects.usmUser.usmUserTable.usmUserEntry.usmUserOwnPrivKeyChange."........."."MD5User" = ""

    As you can see, they OID in the output above shows 2 strings in it: "........." and "MD5User". The first string is an engine ID which is full of unprintable characters, so in this case it didn't help much that the library printed it out for us. However, the user string "MD5User" got nicely printed instead. We generally think this is much easier to understand than looking at the numbers directly. However, this is available to you as an option as well:

      % snmpgetnext -Ob -v 2c -c demopublic test.net-snmp.org usmUserEntry .iso.org.dod.internet.snmpV2.snmpModules.snmpUsmMIB.usmMIBObjects.usmUser.usmUserTable.usmUserEntry.usmUserOwnPrivKeyChange.9.128.0.7.229.1.169.237.235.161.7.77.68.53.85.115.101.114 = ""

    Here you can see that the OID is much more complex, and does not intuitively look like it contains 2 strings to the naked eye.

    Of course, all of the net-snmp commands also accept strings in the requested OID, although most shells will require you to escape the quotes with a back slash:

      % snmpget -v 2c -c demopublic test.net-snmp.org usmUserOwnPrivKeyChange.9.128.0.7.229.1.169.237.235.161.\"MD5User\" .iso.org.dod.internet.snmpV2.snmpModules.snmpUsmMIB.usmMIBObjects.usmUser.usmUserTable.usmUserEntry.usmUserOwnPrivKeyChange."........."."MD5User" = ""
  • -OX

    A more elaborate output for index values is -OX. This format is output-only - no provision has been made to accept it on input.

    Especially the IPv6 mibs return values that can be very difficult to read, and is very different from the ways you normally see the values involved.

    Consider for instance the IPV6-MIB:ipv6RouteTable

      $ snmptranslate -Td IPV6-MIB::ipv6RouteEntry .1.3.6.1.2.1.55.1.11.1 ipv6RouteEntry OBJECT-TYPE -- FROM IPV6-MIB MAX-ACCESS not-accessible STATUS current INDEX { ipv6RouteDest, ipv6RoutePfxLength, ipv6RouteIndex } DESCRIPTION "A routing entry." ::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) ipv6MIB(55) ipv6MIBObjects(1) ipv6RouteTable(11) 1 }
    i.e. the index is an IPv6 address and two integers. So requesting
      $ snmpgetnext -OS host IPV6-MIB::ipv6RouteTable IPV6-MIB::ipv6RouteIfIndex.63.254.1.0.255.0.0.0.0.0.0.0.0.0.0.0.64.1 = 2
    is not easily read. But how about
      $ snmpgetnext -OSX host IPV6-MIB::ipv6RouteTable IPV6-MIB::ipv6RouteIfIndex[3ffe:100:ff00:0:0:0:0:0][64][1] = 2
    It looks a lot nicer. The format puts square brackets around each index, and uses DISPLAY-HINT information and string conversions to format each index.

  • -Os, -OS, and -Of

    Shorting the output of those really long OIDs is also possible, using the -Os and -OS command (the -OS version pre-pends the url with the MIB name that the node came from):

      % snmpget -v 2c -c demopublic test.net-snmp.org sysUpTime.0 ucdDemoUserList.0 system.sysUpTime.0 = Timeticks: (586910990) 67 days, 22:18:29.90 enterprises.ucdavis.ucdDemoMIB.ucdDemoMIBObjects.ucdDemoPublic.ucdDemoUserList.0 = " noAuthUser MD5User MD5DESUser SHAUser SHADESUser" % snmpget -Os -v 2c -c demopublic test.net-snmp.org sysUpTime.0 ucdDemoUserList.0 sysUpTime.0 = Timeticks: (586910990) 67 days, 22:18:29.90 ucdDemoUserList.0 = " noAuthUser MD5User MD5DESUser SHAUser SHADESUser" % snmpget -OS -v 2c -c demopublic test.net-snmp.org sysUpTime.0 ucdDemoUserList.0 RFC1213-MIB::sysUpTime.0 = Timeticks: (586911833) 67 days, 22:18:38.33 UCD-DEMO-MIB::ucdDemoUserList.0 = " noAuthUser MD5User MD5DESUser SHAUser SHADESUser"

    As you can see the above options only print out the last node in the OID, but the -OS option additionally prepends the output with the name of the MIB that the OID can be found in.

    -Of Is sort of the reverse of the previous options and always displays the full OID:

      % snmpget -Of -v 2c -c demopublic test.net-snmp.org sysUpTime.0 ucdDemoUserList.0 .iso.org.dod.internet.mgmt.mib-2.system.sysUpTime.0 = Timeticks: (741998862) 85 days, 21:06:28.62 .iso.org.dod.internet.private.enterprises.ucdavis.ucdDemoMIB.ucdDemoMIBObjects.ucdDemoPublic.ucdDemoUserList.0 = " noAuthUser MD5User MD5DESUser SHAUser SHADESUser"
  • -Ov

    The -Ov flag outputs only the value, but not variable name

      % snmpget -Ov -v 2c -c demopublic test.net-snmp.org sysObjectID.0 OID: enterprises.ucdavis.ucdSnmpAgent.hpux10
  • -Oq

    Finally, the -Oq flag allows us to print everything as quick as possible in a fashion that is easily parsible by things like scripting languages:

      % snmpget -Oq -v 2c -c demopublic test.net-snmp.org sysObjectID.0 system.sysObjectID.0 enterprises.ucdavis.ucdSnmpAgent.hpux10

    Note that in the above output, there is no equal sign and there is no "OID:" string in the output.

  • Combinations

    Of course, you're allowed to combine many of these options into one statement:

      % snmpget -Oqs -v 2c -c demopublic test.net-snmp.org sysObjectID.0 sysObjectID.0 hpux10

    For shell scripts, the -Oqv option is useful. It only returns the value of the attribute, which is useful for instance in (using sh/ksh/bash syntax)

      % interfaces=`snmpget -Oqv -v 2c -c demopublic test.net-snmp.org ifNumber.0`


  • Last modified: Wednesday, 01-Aug-2018 04:41:28 UTC
    For questions regarding web content and site functionality, please write to the net-snmp-users mail list.