Difference between revisions of "TUT:Customized Output Formats"

From Net-SNMP Wiki
Jump to: navigation, search
 
(-Oq =)
Line 161: Line 161:
  
  
=== -Oq ====
+
=== -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:  
 
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:  
Line 171: Line 171:
  
  
Note that in the above output, there is no equal sign and there is no "OID:" string in the output.  
+
Note that in the above output, there is no equal sign and there is no "OID:" string in the output.
  
 
=== Combinations ===
 
=== Combinations ===

Revision as of 20:14, 23 January 2007

Output Formatting

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:

 % snmpget -h
 Usage: snmpget [options...]  [ ...]
 ...
   -O    Toggle various defaults controlling oid printing:
                   OIDOPTS values:
                       n: Print oids numerically.
                       e: Print enums numerically.
                       E: Escape quotes in string indices.
                       X: Extended index format.
                       b: Dont break oid indexes down.
                       q: Quick print for easier parsing.
                       f: Print full oids on output.
                       s: Print only last symbolic element of oid.
                       S: Print MIB module-id plus last element.
                       t: Print timeticks unparsed as numeric integers.
                       v: Print values only (not OID = value).


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 (this example will not work for you the:

 % 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 -R 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````

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.

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!

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.

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.

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:

Operating System Specific Tutorials