SnmpKit.MIB.Lint (snmpkit v2.0.1)
Semantic checks for a parsed or compiled MIB, in the spirit of libsmi's
smilint levels 1 and 2. The parser only decides whether a file is
syntactically a MIB; this module checks whether it makes sense: do all
OIDs resolve, are the referenced types and objects defined or imported, do
table rows have indexes, do SEQUENCE fields match their columns, and is
the module consistent with the SMI version it claims.
{:ok, report} = SnmpKit.MIB.Lint.check("priv/mibs/MY-MIB.mib")
report.errors #=> 0
report.warnings #=> 2
Enum.each(report.findings, &IO.puts(SnmpKit.MIB.Lint.format(&1)))Findings
Each finding is %{severity: :error | :warning, code: atom, name: String.t | nil, line: pos_integer | nil, message: String.t}. Codes:
| Code | Severity | Meaning |
|---|---|---|
:parser_warning | warning | a lexical or vendor-construct warning recorded by the parser |
:duplicate_name | error | the same identifier is defined twice |
:duplicate_oid | error | two definitions register the same OID |
:unresolved_parent | error | an OID's parent is neither defined, imported nor known |
:unknown_import | warning | an imported symbol's module is not available to the check |
:unknown_type | error | a SYNTAX names a type that is not defined, imported or built in |
:smiv1_in_smiv2 | warning | ACCESS/mandatory/optional (SMIv1) inside an SMIv2 module |
:missing_module_identity | warning | an SMIv2 module without MODULE-IDENTITY |
:row_without_index | error | a conceptual row without INDEX or AUGMENTS |
:index_without_size | warning | a string or OID index object without a SIZE restriction |
:sequence_field_undefined | warning | a SEQUENCE field with no matching column object |
:column_not_in_sequence | warning | a column object missing from the row's SEQUENCE |
:sequence_type_mismatch | warning | a column's SYNTAX differs from its SEQUENCE field |
:unknown_object | warning | a notification or group lists an object that is not defined or imported |
Options
:context- other compiled MIBs (as returned bySnmpKit.MIB.compile/1) whose symbols satisfy imports:known-%{name => oid}of names already available (defaults to the built-in tables plus whatever the registry has loaded)
Summary
Functions
Checks a compiled MIB map, a parsed MIB map, a file path or MIB text.
One line per finding: MIB-NAME:LINE: severity: [code] message.
Types
@type finding() :: %{ severity: :error | :warning, code: atom(), name: String.t() | nil, line: pos_integer() | nil, message: String.t() }
@type report() :: %{ name: String.t(), findings: [finding()], errors: non_neg_integer(), warnings: non_neg_integer() }
Functions
Checks a compiled MIB map, a parsed MIB map, a file path or MIB text.
One line per finding: MIB-NAME:LINE: severity: [code] message.