Documentation ¶
Index ¶
- Variables
- func BytesToSanitizedString(b []byte) string
- func DefaultMappings() map[string][]Mapper
- func IPFromBytes(s []byte) string
- func MacFromBytes(s []byte) string
- func PDU(name string, t gosnmp.Asn1BER, val interface{}) *gosnmp.SnmpPDU
- func PDUsFromString(s string) []*gosnmp.SnmpPDU
- type Logger
- type Mapper
- type Translator
- type ValueProcessor
Constants ¶
This section is empty.
Variables ¶
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 ¶
BytesToSanitizedString removes all but ASCII characters 32-126 to keep the JSON unmarshaler happy.
func DefaultMappings ¶
DefaultMappings returns an ordered set of mappings per supported path.
func IPFromBytes ¶
IPFromBytes returns an IP address from a string or byte string.
func MacFromBytes ¶
MacFromBytes returns a MAC address from a string or hex byte string.
func PDUsFromString ¶
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 ¶
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 ¶
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.