Home
You are not currently signed in.

MIB Smithy

  1. Up to Table of Contents

Importing Files and Modules

Modules may be imported into a database, either by reading directly from a file or by passing the module data to be parsed directly, using the import subcommand. Any errors or warnings that are generated during parsing will be logged to the file channel configured for the database (see Logging Compiler Messages).

Syntax:

% dbcmd import option value ?option value ...?

Where:

dbcmd
is the name of the database into which modules are to be imported; and
option value
are series of option+value pairs to specify how the data is to be processed, which are listed below.

Returns:

  • 1 if the data was parsed successfully (i.e., either there were no errors during the parse or any errors that occurred were "recoverable").
  • 0 if the data was not parsed successfully (i.e., one or more non-recoverable errors occurred). If any module fails to be parsed successfully, then all imported data is discarded, including the file record its self if the -in option (see below) was not specified.

MIB Search Path

The SMITHY_MIB_PATH environment variable can be set to a list of paths (delimited by semicolon on Windows or colon on other platforms) to be searched for the specified file when the import command is given a relative path that is not found. For example, if set in the environment outside Tcl (csh syntax):

setenv SMITHY_MIB_PATH /usr/share/mibs:$HOME/mibs

With the above setting, given a relative file name like IF-MIB.mib, the SDK will first attempt to find ./IF-MIB.mib, then /usr/share/mibs/IF-MIB.mib, and finally $HOME/mibs/IF-MIB.mib, choosing the first file match found.

Import Options

-errors variable
Specifies the name of a local variable that is to be assigned a count of the number of errors (if any) that occurred during the parse.
-filename path
Specifies the name of the file to be imported from if reading directly. May also specify the filename for data that has been preprocessed (such as stripping RFC headers/documentation) and passed directly to the command. If the extension is ".xml" then the data is passed to the XML parser; otherwise, the data is parsed as an SMI or COPS-PR-SPPI module.
-in recordName
Specifies the handle for the file record that the module(s) are to be imported into. Note that this is NOT the path for the file on disk: file record handles take the form @File#, where # is an integer suffix that uniquely identifies the file within its database. If this property is unspecified, then a new file record will be created to hold the imported records.
-rawdata text
Specifies module data to be parsed directly, rather than read from file. This option is useful if the data to be parsed has been pre-processed to conform to the XML-SMI Schema or SMI or COPS-PR-SPPI formats by the Tcl script that is importing modules.
-warnings variable
Specifies the name of a local variable that is to be assigned a count of the number of warnings (if any) that occurred during the parse.
-yylineno value
Specifies an integer offset value to for the line number indicated when logging any parse errors resulting from the import. For example, if extracting modules from a file and importing those modules individually, it may be useful to inform the parser of the "real" line number corresponding to the first line of data being parsed if, as a result of the extraction, the module begins on a different line number than in the source file.

Example 1 - Importing SMI/COPS-PR-SPPI modules:

% smilib import -filename /path/to/module.mib \
    -errors errCount -warnings warnCount
1
% smilib log "$errCount error(s), $warnCount warning(s)"
0 error(s), 0 warning(s)

Example 2 - Importing XML modules:

% smilib import -filename /path/to/module.xml \
    -errors errCount -warnings warnCount
1
% smilib log "$errCount error(s), $warnCount warning(s)"
0 error(s), 0 warning(s)

Example 3 - Importing Raw Data:

% set channel [open "example.mib" r]
% set rawData [read $channel]
% close $channel
% set file [smilib new -file -filename "example.mib"]
% smilib import -rawdata $rawData -in $file
1
  1. Up to Table of Contents