Documentation ¶
Overview ¶
Package snmplib provides an SNMP query and trapper library.
Index ¶
- Constants
- func DecodeCounter64(toparse []byte) (uint64, error)
- func DecodeIPAddress(toparse []byte) (string, error)
- func DecodeInteger(toparse []byte) (int, error)
- func DecodeIntegerSigned(toparse []byte) (int, error)
- func DecodeLength(toparse []byte) (int, int, error)
- func DecodeSequence(toparse []byte) ([]interface{}, error)
- func DoGetTableTest(target string)
- func DoGetTest(target string)
- func DoGetTestV3(target string, oidstr, username, authAlg, authKey, privAlg, privKey string)
- func DoWalkTest(target string)
- func DoWalkTestV3(target string, oidstr, username, authAlg, authKey, privAlg, privKey string)
- func EncodeInteger(toEncode int) []byte
- func EncodeLength(length int) []byte
- func EncodeSequence(toEncode []interface{}) ([]byte, error)
- func NewUdpStub(t *testing.T) *udpStub
- type BERType
- type Oid
- type SNMP
- func NewSNMP(target, community string, version SNMPVersion, timeout time.Duration, ...) (*SNMP, error)
- func NewSNMPOnConn(target, community string, version SNMPVersion, timeout time.Duration, ...) *SNMP
- func NewSNMPv3(target, user, authAlg, authPwd, privAlg, privPwd string, timeout time.Duration, ...) (*SNMP, error)
- func (w SNMP) Close() error
- func (w *SNMP) Discover() error
- func (w SNMP) Get(oid Oid) (interface{}, error)
- func (w SNMP) GetBulk(oid Oid, maxRepetitions int) (map[string]interface{}, error)
- func (w SNMP) GetMultiple(oids []Oid) (map[string]interface{}, error)
- func (w SNMP) GetNext(oid Oid) (*Oid, interface{}, error)
- func (w *SNMP) GetNextV3(oid Oid) (*Oid, interface{}, error)
- func (w SNMP) GetTable(oid Oid) (map[string]interface{}, error)
- func (w *SNMP) GetV3(oid Oid) (interface{}, error)
- func (w SNMP) ParseTrap(response []byte) (Trap, error)
- type SNMPVersion
- type Trap
- type TrapHandler
- type TrapServer
- type V3user
Constants ¶
const ( SnmpAES string = "AES" SnmpDES string = "DES" SnmpNOPRIV string = "NOPRIV" SnmpSHA1 string = "SHA1" SnmpMD5 string = "MD5" )
SNMP constants.
Variables ¶
This section is empty.
Functions ¶
func DecodeCounter64 ¶
DecodeCounter64 decodes a counter64.
func DecodeIPAddress ¶
DecodeIPAddress decodes an IP address.
func DecodeInteger ¶
DecodeInteger decodes an integer. Will error out if it's longer than 64 bits.
func DecodeIntegerSigned ¶
DecodeIntegerSigned decodes a signed integer. Will error out if it's longer than 64 bits.
func DecodeLength ¶
DecodeLength returns the length and the length of the length or an error. Caveats: Does not support indefinite length. Couldn't find any SNMP packet dump actually using that.
func DecodeSequence ¶
DecodeSequence decodes BER binary data into into *[]interface{}.
func DoGetTableTest ¶
func DoGetTableTest(target string)
func DoGetTestV3 ¶
func DoWalkTest ¶
func DoWalkTest(target string)
func DoWalkTestV3 ¶
func EncodeInteger ¶
EncodeInteger encodes an integer to BER format.
func EncodeLength ¶
EncodeLength encodes an integer value as a BER compliant length value.
func EncodeSequence ¶
EncodeSequence will encode an []interface{} into an SNMP bytestream.
Types ¶
type BERType ¶
type BERType uint8
BERType constants for the Type of the TLV field.
const ( AsnBoolean BERType = 0x01 AsnInteger BERType = 0x02 AsnBitStr BERType = 0x03 AsnOctetStr BERType = 0x04 AsnNull BERType = 0x05 AsnObjectID BERType = 0x06 AsnSequence BERType = 0x10 AsnSet BERType = 0x11 AsnUniversal BERType = 0x00 AsnApplication BERType = 0x40 AsnContext BERType = 0x80 AsnPrivate BERType = 0xC0 AsnPrimitive BERType = 0x00 AsnConstructor BERType = 0x20 AsnLongLen BERType = 0x80 AsnExtensionID BERType = 0x1F AsnBit8 BERType = 0x80 Integer BERType = AsnUniversal | 0x02 Integer32 BERType = AsnUniversal | 0x02 Bitstring BERType = AsnUniversal | 0x03 Octetstring BERType = AsnUniversal | 0x04 Null BERType = AsnUniversal | 0x05 UOid BERType = AsnUniversal | 0x06 Sequence BERType = AsnConstructor | 0x10 Ipaddress BERType = AsnApplication | 0x00 Counter BERType = AsnApplication | 0x01 Counter32 BERType = AsnApplication | 0x01 Gauge BERType = AsnApplication | 0x02 Gauge32 BERType = AsnApplication | 0x02 Timeticks BERType = AsnApplication | 0x03 Opaque BERType = AsnApplication | 0x04 Counter64 BERType = AsnApplication | 0x06 AsnGetRequest BERType = 0xa0 AsnGetNextRequest BERType = 0xa1 AsnGetResponse BERType = 0xa2 AsnSetRequest BERType = 0xa3 AsnTrap BERType = 0xa4 AsnGetBulkRequest BERType = 0xa5 AsnInform BERType = 0xa6 AsnTrap2 BERType = 0xa7 AsnReport BERType = 0xa8 )
Constants for the different types of the TLV fields.
type Oid ¶
type Oid []int
The SNMP object identifier type.
func MustParseOid ¶
MustParseOid parses a string oid to an Oid instance. Panics on error.
type SNMP ¶
type SNMP struct { Target string // Target device for these SNMP events. Community string // Community to use to contact the device. Version SNMPVersion // SNMPVersion to encode in the packets. TrapUsers []V3user // contains filtered or unexported fields }
SNMP object type that lets you do SNMP requests.
func NewSNMP ¶
func NewSNMP(target, community string, version SNMPVersion, timeout time.Duration, retries int) (*SNMP, error)
NewSNMP creates a new SNMP object. Opens a UDP connection to the device that will be used for the SNMP packets.
func NewSNMPOnConn ¶
func NewSNMPOnConn(target, community string, version SNMPVersion, timeout time.Duration, retries int, conn net.Conn) *SNMP
NewSNMPOnConn creates a new SNMP object from an existing net.Conn. It does not check if the provided target is valid.
func NewSNMPv3 ¶
func NewSNMPv3(target, user, authAlg, authPwd, privAlg, privPwd string, timeout time.Duration, retries int) (*SNMP, error)
NewSNMPv3 creates a new SNMP object for SNMPv3. Opens a UDP connection to the device that will be used for the SNMP packets.
func (*SNMP) Discover ¶
Discover : SNMP V3 requires a discover packet being sent before a request being sent, so that agent's engineID and other parameters can be automatically detected.
func (SNMP) GetBulk ¶
GetBulk is semantically the same as maxRepetitions getnext requests, but in a single GETBULK SNMP packet. Caveat: many devices will silently drop GETBULK requests for more than some number of maxrepetitions, if it doesn't work, try with a lower value and/or use GetTable.
func (SNMP) GetMultiple ¶
GetMultiple issues a single GET SNMP request requesting multiple values
func (SNMP) GetTable ¶
GetTable efficiently gets an entire table from an SNMP agent. Uses GETBULK requests to go fast.
type SNMPVersion ¶
type SNMPVersion uint8
SNMPVersion indicates which SNMP version is in use.
const ( SNMPv1 SNMPVersion = 0 SNMPv2c SNMPVersion = 1 SNMPv3 SNMPVersion = 3 )
List the supported snmp versions.
type Trap ¶
type Trap struct { Version int TrapType int // for V1 traps OID Oid Other interface{} Community string Username string Address string VarBinds map[string]interface{} VarBindOIDs []string }
Trap object.
type TrapHandler ¶
TrapHandler interface.
type TrapServer ¶
type TrapServer struct { PacketSize int IPAddress net.UDPAddr Port int Conn *net.UDPConn Users []V3user }
TrapServer object.
func NewTrapServer ¶
func NewTrapServer(ip string, port int) (TrapServer, error)
NewTrapServer creates a new TrapServer object.
func (*TrapServer) ListenAndServe ¶
func (s *TrapServer) ListenAndServe(handler TrapHandler)
ListenAndServe starts the listen loop and will pause execution until server is shut down.