bottrap
< Prev Back to Table of Contents Next >

Formatting Data for Display

Because DISPLAY-HINTs are not reversible (in general), object values returned by SNMP Get, Get-Next, and Get-Bulk requests are returned in raw form, unformatted for display. For example, OBJECT IDENTIFIER values are returned in dotted number form, enumerated integers in integer form, and OCTET STRINGs as byte arrays or hex strings. With the exception of symbolic OIDs and enumerated integers these are also the only forms accepted for sending in a request.

Versions 3.4 and later of MIB Smithy SDK provide an API for formatting such raw data for display. Formatting is done according to the data type, enumerations, and DISPLAY-HINT, as applicable for a specified record and value. This gives you the freedom to work with raw values as necessary for requests while displaying values in a more human-readable form.

The API can be called through either the SMI Database command or an SNMP Session command. In the latter case, the command is passed on to the SMI Database that is associated with the session.

Syntax:

% dbcmd format ?options? record value
% snmpcmd format ?options? record value

..where dbcmd is the name of any database, snmpcmd is the name of any session, record is is the name or OID of a record (generally an OBJECT-TYPE or TEXTUAL-CONVENTION) and value is a value (appropriate to the record's type) to be formatted.

Returns:

For enumerated integer values: the label assigned to the integer value, such as destroy.

For OBJECT IDENTIFIER values: the symbolic name (plus any subidentifiers) in dotted notation, such as sysDescr.0.

For other integer and OCTET STRING values: a string formatted according to the appropriate DISPLAY-HINT specification, if any.

For all other cases, returns the input value.

Options:

Option Argument Description
-enumformat format Specifies the desired output format for enumerated INTEGER values, overriding the database defaults.
-nocomplain N/A Suppresses errors in cases such as the value not being valid according to type or DISPLAY-HINT for the record. If an error would have occurred, the format command will instead return the unmodified input value.
-oidformat format Specifies the desired output format for OBJECT IDENTIFIER values, overriding the database defaults.

Enumeration Formatting Codes:

Code Description
%% Inserts a single % character into the result.
%a Equivalent of "%n(%i)" -- i.e., enumeration label and integer value in parentheses.
%i The integer form for the enumeration value.
%n Enumeration label only.
%v The raw value provided in the value field of the command.

OID Formatting Codes:

Code Description
%% Inserts a single % character into the result.
%a Equivalent of "%m%n%s" -- i.e., module name, descriptor, and subidentifiers (if any).
%m The name of the module the OID is defined in along with a trailing colon. (e.g. "SNMPv2-MIB:").
%M The name of the module the OID is defined in (e.g. "SNMPv2-MIB").
%n The descriptor only for the longest matching OID prefix, as with $db get -name $record.
%s The instance identifiers for the OID value (e.g. 1.3.6.1.2.1.1.1.0, sysDescr.0, returns "0").
%S The instance identifiers for the OID value along with a "." prefix, if there are any (e.g. 1.3.6.1.2.1.1.1.0, sysDescr.0, returns "0").
%v The raw value provided in the value field of the command.

Example 1 - Enumerated Integer Value

% smilib format RowStatus 6
destroy

Example 2 - Enumerated Integer Value with Format

% smilib format -enumformat "%a" RowStatus 6
destroy(6)

Example 3 - OBJECT IDENTIFIER Value

% smilib format RowPointer 1.3.6.1.2.1.1.1.0
sysDescr.0

Example 4 - OBJECT IDENTIFIER Value with Format

% smilib format -oidformat "%a" RowPointer 1.3.6.1.2.1.1.1.0
SNMPv2-MIB:sysDescr.0

Example 5 - OCTET STRING Value

% smilib format DateAndTime 0x07d50b010c0000
2005-11-1,12:0:0
< Prev Back to Table of Contents Next >