The chapter The MIB Compiler describes the MIB compiler and contains the following topics:
When importing MIBs, ensure that the imported MIBs as well as the importing MIB are compiled using the same version of the SNMP-compiler.
The MIB must be written as a text file in SMIv1 or SMIv2 using
an ASN.1 notation before
it will be compiled. This text file must have the same name as the MIB,
but with the suffix
The association file, which contains the names of
instrumentation functions for the MIB, should have the suffix
The MIB compiler is started with a call to
snmpc:compile("RFC1213-MIB").
The output is a new file which is called
The MIB compiler understands both SMIv1 and SMIv2 MIBs. It uses the MODULE-IDENTITY statement to determinate if the MIB is written in SMI version 1 or 2.
The compiler handles the
The compiled files of the imported MIBs must be present in the
current directory, or a directory in the current path. The path is
supplied with the
snmpc:compile("MY-MIB",
[{i, ["friend_mibs/", "../standard_mibs/"]}]).
It is also possible to import MIBs from OTP applications in an
snmpc:compile("MY-MIB",
[{il, ["snmp/priv/mibs/", "myapp/priv/mibs/"]}]).
finds the latest version of the
Note that an SMIv2 MIB can import an SMIv1 MIB and vice versa.
The following MIBs are built-ins of the Erlang SNMP compiler: SNMPv2-SMI, RFC-1215, RFC-1212, SNMPv2-TC, SNMPv2-CONF, and RFC1155-SMI. They cannot therefore be compiled separately.
When an MIB is compiled, the compiler detects if several
managed objects use the same
erl>snmpc:is_consistent(ListOfMibNames).
It is possible to generate an
Use the following command to generate a .hrl file from an MIB:
erl>snmpc:mib_to_hrl(MibName).
With the Emacs editor, the
Use
erl -s snmpc compile <MibName> -noshell
An example of
The
erlc MY-MIB.mib
All the standard
erlc -I mymibs -o mymibs -W MY-MIB.mib
The flags specific to the MIB compiler can be specified by
using the
erlc +'{group_check,false}' MY-MIB.mib
In some aspects the Erlang MIB compiler does not follow or implement the SMI fully. Here are the differences:
Tables must be written in the following order:
Integer values, for example in the
Symbolic names must be unique within a MIB and within a system.
Hyphens are allowed in SMIv2 (a pragmatic approach). The reason for this is that according to SMIv2, hyphens are allowed for objects converted from SMIv1, but not for others. This is impossible to check for the compiler.
If a word is a keyword in any of SMIv1 or SMIv2, it is a keyword in the compiler (deviates from SMIv1 only).
Indexes in a table must be objects, not types (deviates from SMIv1 only).
A subset of all semantic checks on types are
implemented. For example, strictly the
The
Two different names cannot define the same OBJECT IDENTIFIER.
The type checking in the SEQUENCE construct is non-strict (i.e. subtypes may be specified). The reason for this is that some standard MIBs use this.