Documentation
¶
Overview ¶
Package mibs implements a parser for SNMP MIBs.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModuleName ¶
ModuleName returns the module name for the given file. If the file is not a module file then a NotAModuleError error is returned.
Types ¶
type MIB ¶
type MIB struct { Modules map[string]*Module Root *Symbol Symbols map[string]*Symbol Debug bool // contains filtered or unexported fields }
A MIB is a collection of SNMP modules. The MIB provides a high-level API for loading and accessing the contents of parsed MIBs.
func NewMIB ¶
NewMIB creates a MIB object for the modules contained in the dirs directories. Creating a MIB does not load any modules from the directories. You need to call LoadModules() on the resulting MIB object.
func (*MIB) LoadModules ¶
LoadModules scans the MIB directories and loads the modules listed by modNames. The imported modules are also loaded. A module's name is the one specified on the first line of the MIB file. The file names do not have to exactly match the module names.
func (*MIB) OID ¶
OID parses the name string in the format provided by the SymbolString function (e.g. Module::Symbol.1.2.3) and returns an OID object. The module and index parts of the string are optional.
Example ¶
package main import ( "fmt" "github.com/hallidave/mibtool/smi" "log" ) func main() { mib := smi.NewMIB("testdata") err := mib.LoadModules("IF-MIB") if err != nil { log.Fatal(err) } examples := []string{ "ifTable", "IF-MIB::ifIndex", "ifType.3", "IF-MIB::ifOperStatus.4", } for _, example := range examples { oid, err := mib.OID(example) if err != nil { log.Fatal(err) } fmt.Println(oid.String()) } }
Output: 1.3.6.1.2.1.2.2 1.3.6.1.2.1.2.2.1.1 1.3.6.1.2.1.2.2.1.3.3 1.3.6.1.2.1.2.2.1.8.4
func (*MIB) SymbolString ¶
SymbolString returns a string representation of the information provided by the Symbol function.
func (*MIB) VisitSymbols ¶
VisitSymbols walks all symbols defined in the MIB in order by OID. The action function is called once for each symbol.
Example ¶
package main import ( "fmt" "github.com/hallidave/mibtool/smi" "log" ) func main() { mib := smi.NewMIB("testdata") mib.Debug = true err := mib.LoadModules("SNMPv2-SMI") if err != nil { log.Fatal(err) } mib.VisitSymbols(func(sym *smi.Symbol, oid smi.OID) { fmt.Printf("%-40s %s\n", sym, oid) }) }
Output: SNMPv2-SMI::org 1.3 SNMPv2-SMI::dod 1.3.6 SNMPv2-SMI::internet 1.3.6.1 SNMPv2-SMI::directory 1.3.6.1.1 SNMPv2-SMI::mgmt 1.3.6.1.2 SNMPv2-SMI::mib-2 1.3.6.1.2.1 SNMPv2-SMI::transmission 1.3.6.1.2.1.10 SNMPv2-SMI::experimental 1.3.6.1.3 SNMPv2-SMI::private 1.3.6.1.4 SNMPv2-SMI::enterprises 1.3.6.1.4.1 SNMPv2-SMI::security 1.3.6.1.5 SNMPv2-SMI::snmpV2 1.3.6.1.6 SNMPv2-SMI::snmpDomains 1.3.6.1.6.1 SNMPv2-SMI::snmpProxys 1.3.6.1.6.2 SNMPv2-SMI::snmpModules 1.3.6.1.6.3
type Module ¶
type Module struct { Name string File string Imports []Import Nodes []Node IsLoaded bool Symbols map[string]*Symbol }
A Module contains all of the parse results for a single module file. Only the Name and File fields are valid if the IsLoaded flag is false.
func ParseModule ¶
type NodeType ¶
type NodeType int
NodeType distinguishes the different types of objects that make up the Nodes in a Module.
type NotAModuleError ¶
type NotAModuleError string
NotAModuleError is returned when a parsed file is not a valid module file.
func (NotAModuleError) Error ¶
func (f NotAModuleError) Error() string
func (NotAModuleError) Filename ¶
func (f NotAModuleError) Filename() string
type Symbol ¶
type Symbol struct { Name string ID int Module *Module Parent *Symbol ChildByLabel map[string]*Symbol ChildByID map[int]*Symbol }
A Symbol represents a single symbol in the tree of identifiers. The tree can be traversed by label or by ID. The collection of IDs in the path from the root of the tree to the symbol is the object identifier (OID) of the symbol.