snmpoc

package
v0.0.0-...-1768917 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SNMPErrCodes = map[gosnmp.SNMPError]string{
	0: "noError", 1: "tooBig", 2: "noSuchName", 3: "badValue",
	4: "readOnly", 5: "genErr", 6: "noAccess", 7: "wrongType",
	8: "wrongLength", 9: "wrongEncoding", 10: "wrongValue",
	11: "noCreation", 12: "inconsistentValue", 13: "resourceUnavailable",
	14: "commitFailed", 15: "undoFailed", 16: "authorizationError",
	17: "notWritable", 18: "inconsistentName",
}

SNMPErrCodes maps the SNMP error codes to their corresponding text descriptions.

Functions

func BytesToSanitizedString

func BytesToSanitizedString(b []byte) string

BytesToSanitizedString removes all but ASCII characters 32-126 to keep the JSON unmarshaler happy.

func DefaultMappings

func DefaultMappings() map[string][]Mapper

DefaultMappings returns an ordered set of mappings per supported path.

func IPFromBytes

func IPFromBytes(s []byte) string

IPFromBytes returns an IP address from a string or byte string.

func MacFromBytes

func MacFromBytes(s []byte) string

MacFromBytes returns a MAC address from a string or hex byte string.

func PDU

func PDU(name string, t gosnmp.Asn1BER, val interface{}) *gosnmp.SnmpPDU

PDU creation wrapper.

func PDUsFromString

func PDUsFromString(s string) []*gosnmp.SnmpPDU

PDUsFromString converts a set of formatted SNMP responses (as returned by snmpwalk -v3 -O ne <target> <oid>) to PDUs.

Types

type Logger

type Logger interface {
	Infof(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

Logger defines an interface for logging.

type Mapper

type Mapper = func(smi.Store, pdu.Store, *sync.Map, Logger) ([]*gnmi.Update, error)

A Mapper contains some logic for producing gNMI updates based on the contents of a pdu.Store and a mapper data cache.

type Translator

type Translator struct {

	// mapping state
	Mappings map[string][]Mapper

	// logging
	Logger Logger

	// alternative get, walk, and time.Now for testing
	Mock   bool
	Getter func([]string) (*gosnmp.SnmpPacket, error)
	Walker func(string, gosnmp.WalkFunc) error
	// contains filtered or unexported fields
}

Translator defines an interface for producing translations from a set of received SNMP PDUs to a set of gNMI updates.

func NewTranslator

func NewTranslator(mibStore smi.Store, gs *gosnmp.GoSNMP) (*Translator, error)

NewTranslator returns a Translator.

func (*Translator) Poll

func (t *Translator) Poll(ctx context.Context, client gnmi.GNMIClient,
	paths []string) error

Poll generates a set of updates for the paths specified. It accepts exact paths and regular expressions. Any path in the translator's mapping list that matches the provided expression is added to the set of updates to produce. It performs a poll for any required SNMP data and translates that data into gNMI updates, which it then transmits via the provided gNMI client's Set method.

type ValueProcessor

type ValueProcessor func(interface{}) *gnmi.TypedValue

A ValueProcessor takes an arbitrary value and returns a gnmi.TypedValue, possibly doing additional processing first.

Jump to

Keyboard shortcuts

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