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:

CodeSeverityMeaning
:parser_warningwarninga lexical or vendor-construct warning recorded by the parser
:duplicate_nameerrorthe same identifier is defined twice
:duplicate_oiderrortwo definitions register the same OID
:unresolved_parenterroran OID's parent is neither defined, imported nor known
:unknown_importwarningan imported symbol's module is not available to the check
:unknown_typeerrora SYNTAX names a type that is not defined, imported or built in
:smiv1_in_smiv2warningACCESS/mandatory/optional (SMIv1) inside an SMIv2 module
:missing_module_identitywarningan SMIv2 module without MODULE-IDENTITY
:row_without_indexerrora conceptual row without INDEX or AUGMENTS
:index_without_sizewarninga string or OID index object without a SIZE restriction
:sequence_field_undefinedwarninga SEQUENCE field with no matching column object
:column_not_in_sequencewarninga column object missing from the row's SEQUENCE
:sequence_type_mismatchwarninga column's SYNTAX differs from its SEQUENCE field
:unknown_objectwarninga notification or group lists an object that is not defined or imported

Options

  • :context - other compiled MIBs (as returned by SnmpKit.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

finding()

@type finding() :: %{
  severity: :error | :warning,
  code: atom(),
  name: String.t() | nil,
  line: pos_integer() | nil,
  message: String.t()
}

report()

@type report() :: %{
  name: String.t(),
  findings: [finding()],
  errors: non_neg_integer(),
  warnings: non_neg_integer()
}

Functions

check(source, opts \\ [])

@spec check(
  map() | Path.t() | String.t(),
  keyword()
) :: {:ok, report()} | {:error, term()}

Checks a compiled MIB map, a parsed MIB map, a file path or MIB text.

format(finding, prefix \\ nil)

@spec format(finding(), String.t() | nil) :: String.t()

One line per finding: MIB-NAME:LINE: severity: [code] message.