snmp

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2024 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadMibsFromPath

func LoadMibsFromPath(paths []string, loader MibLoader) error

func NewGosmiTranslator

func NewGosmiTranslator(paths []string) (*gosmiTranslator, error)

func NewNetsnmpTranslator

func NewNetsnmpTranslator() *netsnmpTranslator

func SnmpInlet

func SnmpInlet(ctx *engine.Context) engine.Inlet

Types

type ClientConfig

type ClientConfig struct {
	Timeout                 time.Duration
	Retries                 int
	Version                 int
	UseUnconnectedUDPSocket bool

	// Version 1 and 2
	Community string

	// Version 2 and 3
	MaxRepetitions uint32

	// Version 3 only
	ContextName  string
	SecLevel     string
	SecName      string
	AuthProtocol string
	AuthPassword string
	PrivProtocol string
	PrivPassword string
	EngineID     string
	EngineBoots  uint32
	EngineTime   uint32
}

type Conn

type Conn interface {
	Host() string
	Walk(string, gosnmp.WalkFunc) error
	Get(oids []string) (*gosnmp.SnmpPacket, error)
	Reconnect() error
}

type Field

type Field struct {
	Name           string
	Oid            string
	OidIndexSuffix string
	OidIndexLength int
	IsTag          bool
	// Conversion controls any type conversion that is done on the value.
	//  "float"/"float(0)" will convert the value into a float.
	//  "float(X)" will convert the value into a float, and then move the decimal before Xth right-most digit.
	//  "int" will convert the value into an integer.
	//  "hwaddr" will convert a 6-byte string to a MAC address.
	//  "ipaddr" will convert the value to an IPv4 or IPv6 address.
	//  "enum"/"enum(1)" will convert the value according to its syntax. (Only supported with gosmi translator)
	Conversion          string
	Translate           bool
	SecondaryIndexTable bool
	SecondaryIndexUse   bool
	SecondaryOuterJoin  bool
	// contains filtered or unexported fields
}

Fields for the configuration for a Field to look up

func (*Field) Convert

func (f *Field) Convert(ent gosnmp.SnmpPDU) (interface{}, error)

func (*Field) Init

func (f *Field) Init(tr Translator) error

type GosmiMibLoader

type GosmiMibLoader struct{}

type GosnmpWrapper

type GosnmpWrapper struct {
	*gosnmp.GoSNMP
}

func NewWrapper

func NewWrapper(c ClientConfig) (GosnmpWrapper, error)

func (GosnmpWrapper) Get

func (gs GosnmpWrapper) Get(oids []string) (*gosnmp.SnmpPacket, error)

func (GosnmpWrapper) Host

func (gs GosnmpWrapper) Host() string

func (GosnmpWrapper) Reconnect

func (gs GosnmpWrapper) Reconnect() error

func (GosnmpWrapper) SetAgent

func (gs GosnmpWrapper) SetAgent(agent string) error

SetAgent sets the target agent for the connection. sheme://host:port

func (GosnmpWrapper) Walk

func (gs GosnmpWrapper) Walk(oid string, f gosnmp.WalkFunc) error

type MibEntry

type MibEntry struct {
	MibName string
	OidText string
}

type MibLoader

type MibLoader interface {
	// contains filtered or unexported methods
}

type RTable

type RTable struct {
	// Name is the name of the field, copied from Table.Name.
	Name string
	// Time is the time the table was built.
	Time time.Time
	// Rows are the rows that were found, one row for each table OID index found.
	Rows []RTableRow
}

RTable is the resulting table built from a Table.

type RTableRow

type RTableRow struct {
	// Tags are all the Field values which had IsTag=true.
	Tags map[string]string
	// Fields are all the Field values which had IsTag=false.
	Fields map[string]interface{}
}

RTableRow is the resulting row containing all the OID values which shared the same index.

type Table

type Table struct {
	Name        string
	InheritTags []string

	IndexAsTag bool

	Fields []Field

	Oid string
	// contains filtered or unexported fields
}

Table for the configuration of a SNMP table

func (Table) Build

func (t Table) Build(gs Conn, walk bool) (*RTable, error)

type Translator

type Translator interface {
	SnmpTranslate(string) (
		mibName string, oidNum string, oidText string,
		conversion string,
		err error,
	)
	SnmpTable(oid string) (
		mibName string, oidNum string, oidText string,
		fields []Field,
		err error,
	)
	SnmpFormatEnum(oid string, value any, full bool) (
		formatted string,
		err error,
	)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL