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 raw binary strings (byte arrays in Tcl_Obj terms). With the exception of symbolic OIDs and enumerated integers these are also the only forms accepted for sending in a request.
MIB Smithy SDK provides 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. Instead of a record, you can specify an ASN.1 type directly, although typically this is most useful for hex encoding of binary OCTET STRING data.
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.
% dbcmd format ?options? record ?syntax? value
% dbcmd format ?options? syntax value
% snmpcmd format ?options? record ?syntax? value
% snmpcmd format ?options? syntax value
dbcmd
snmpcmd
record
syntax
value
Using both record
and syntax
parameters is useful for applying default formatting for variables received in SNMP requests for which the OID is unknown.
destroy
.sysDescr.0
.-enumformat format
-nocomplain
-oidformat format
-strformat format
-ticksformat format
%t
for formatting as number of days, hours, minutes, seconds, and hundredths of a second as "Nd HH:MM::SS.ss" (e.g. "3d 23:59:59.99
" for the TimeTicks value 34559999
).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. |
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. |
% smilib format RowStatus 6 destroy
% smilib format -enumformat "%a" RowStatus 6 destroy(6)
% smilib format RowPointer 1.3.6.1.2.1.1.1.0 sysDescr.0
% smilib format -oidformat "%a" RowPointer 1.3.6.1.2.1.1.1.0 SNMPv2-MIB:sysDescr.0
% smilib format DateAndTime "\x07\xd5\x0b\x01\x0c\x00\x00" 2005-11-1,12:0:0
% smilib format "OCTET STRING" "\x07\xd5\x0b\x01\x0c\x00\x00" 07:d5:0b:01:0c:00:00