snmp

package module
v0.0.0-...-3e847c3 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2016 License: BSD-3-Clause Imports: 15 Imported by: 0

README

snmp Circle CI GoDoc BSD License

An SNMP v3 client library for Go.

This package only supports SNMP v3 with authPriv mode using SHA authentication and AES encryption. Only 128-bit AES is supported.

SNMP sessions are goroutine-safe. One of the goals of this package is to be able to handle sessions with many (> 100) devices concurrently.

API guarantees

API stability is not guaranteed. Vendoring or using a dependency manager is suggested.

License

BSD (see LICENSE)

Documentation

Index

Constants

View Source
const (
	TypeInteger   = 0x02
	TypeString    = 0x04
	TypeNull      = 0x05
	TypeOID       = 0x06
	TypeSequence  = 0x30
	TypeIpAddress = 0x40
	TypeCounter   = 0x41
	TypeGauge     = 0x42
	TypeTimeTicks = 0x43
	TypeCounter64 = 0x46

	TypeNoSuchObject   = 0x80
	TypeNoSuchInstance = 0x81
	TypeEndOfMIBView   = 0x82

	TypeGetRequest     = 0xa0
	TypeGetNextRequest = 0xa1
	TypeGetResponse    = 0xa2
	TypeReport         = 0xa8
)
View Source
const EndOfMIBView tag = TypeEndOfMIBView
View Source
const NoSuchInstance tag = TypeNoSuchInstance
View Source
const NoSuchObject tag = TypeNoSuchObject
View Source
const Null tag = 0x05

Null represents an SNMP NULL.

Variables

View Source
var (
	ErrDecodingType = errors.New("snmp: error decoding type")
	ErrUnknownType  = errors.New("snmp: unknown type")
)
View Source
var (
	ErrorIncorrectType = errors.New("snmp: incorrect type")
)

Functions

This section is empty.

Types

type Counter

type Counter int

Counter represents an SNMP Counter data type.

func (Counter) Encode

func (c Counter) Encode() ([]byte, error)

Encode encodes a Counter with the proper header.

type Counter64

type Counter64 int

Counter64 represents an SNMP Counter64 data type.

func (Counter64) Encode

func (c Counter64) Encode() ([]byte, error)

Encode encodes a Counter with the proper header.

type DataType

type DataType interface {
	Encode() ([]byte, error)
}

DataType represents an SNMP data type.

type Gauge

type Gauge int

Gauge represents an SNMP Gauge data type.

func (Gauge) Encode

func (g Gauge) Encode() ([]byte, error)

Encode encodes a Gauge with the proper header.

type GetNextRequest

type GetNextRequest struct {
	PDU
}

GetNextRequest represents an SNMP GetNextRequest-PDU.

func (GetNextRequest) Encode

func (s GetNextRequest) Encode() ([]byte, error)

Encode encodes a GetNextRequest with the proper header.

type GetRequest

type GetRequest struct {
	PDU
}

GetRequest represents an SNMP GetRequest-PDU.

func (GetRequest) Encode

func (s GetRequest) Encode() ([]byte, error)

Encode encodes a GetRequest with the proper header.

type GetResponse

type GetResponse struct {
	PDU
}

GetResponse represents an SNMP GetResponse-PDU.

func (GetResponse) Encode

func (s GetResponse) Encode() ([]byte, error)

Encode encodes a GetResponse with the proper header.

type Int

type Int int

Int represents an SNMP INTEGER.

func (Int) Encode

func (i Int) Encode() ([]byte, error)

Encode encodes an Int with the proper header.

type IpAddress

type IpAddress []byte

String represents an SNMP IpAddress.

func (IpAddress) Encode

func (ip IpAddress) Encode() ([]byte, error)

Encode encodes a String with the proper header.

type ObjectIdentifier

type ObjectIdentifier []uint

ObjectIdentifier represents an SNMP OID.

func MustParseOID

func MustParseOID(str string) ObjectIdentifier

MustParseOID parses a string and returns an ObjectIdentifier. It panics if an error is encountered.

func ParseOID

func ParseOID(str string) (ObjectIdentifier, error)

ParseOID parses and returns an ObjectIdentifier and an error.

func (ObjectIdentifier) Encode

func (oid ObjectIdentifier) Encode() ([]byte, error)

Encode encodes an ObjectIdentifier with the proper header.

func (ObjectIdentifier) String

func (oid ObjectIdentifier) String() string

String returns the string representation of an ObjectIdentifer. This value can be parsed into the original OID as well.

type PDU

type PDU struct {
	// contains filtered or unexported fields
}

PDU represents an SNMP PDU.

func (PDU) Varbinds

func (p PDU) Varbinds() []Varbind

type Report

type Report []DataType

Report represents an SNMP Report-PDU.

func (Report) Encode

func (s Report) Encode() ([]byte, error)

Encode encodes a Report with the proper header.

type Sequence

type Sequence []DataType

Sequence represents an SNMP SEQUENCE.

func (Sequence) Encode

func (s Sequence) Encode() ([]byte, error)

Encode encodes a Sequence with the proper header.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session represents an SNMP v3 session to a single device.

func (*Session) Discover

func (s *Session) Discover() error

TODO: add comment

func (*Session) Get

func (s *Session) Get(oid ObjectIdentifier) (*GetResponse, error)

func (*Session) GetNext

func (s *Session) GetNext(oid ObjectIdentifier) (*GetResponse, error)

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

A SessionManager listens on a UDP port and manages SNMP sessions.

func NewSessionManager

func NewSessionManager() (*SessionManager, error)

NewSessionManager creates a new SessionManager and starts listening on a UDP port.

func (*SessionManager) NewSession

func (s *SessionManager) NewSession(address, user, authPassphrase, privPassphrase string) (*Session, error)

NewSession creates a new SNMP v3 session using "authPriv" mode with SHA authentication and AES encryption.

type String

type String string

String represents an SNMP OCTET STRING.

func (String) Encode

func (s String) Encode() ([]byte, error)

Encode encodes a String with the proper header.

type TimeTicks

type TimeTicks int

TimeTicks represents an SNMP TimeTicks data type.

func (TimeTicks) Encode

func (t TimeTicks) Encode() ([]byte, error)

Encode encodes a Gauge with the proper header.

type Varbind

type Varbind struct {
	OID ObjectIdentifier
	// contains filtered or unexported fields
}

Varbind represents a single variable binding.

func NewVarbind

func NewVarbind(OID ObjectIdentifier, value DataType) Varbind

NewVarbind returns a new Varbind with the given OID and value.

func (Varbind) GetIntegerValue

func (v Varbind) GetIntegerValue() (int, error)

GetIntegerValue returns the integer value of a variable binding. An error is returned if the value is not an integer.

func (Varbind) GetStringValue

func (v Varbind) GetStringValue() (string, error)

GetStringValue returns the string value of a variable binding. An error is returned if the value is not a string.

Jump to

Keyboard shortcuts

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