Documentation ¶
Overview ¶
Package wapsnmp provides an SNMP query library.
Index ¶
- Constants
- func DecodeCounter64(toparse []byte) (uint64, error)
- func DecodeIPAddress(toparse []byte) (string, error)
- func DecodeInt64(bytes []byte) (ret int64, err error)
- func DecodeInteger(toparse []byte) (int, error)
- func DecodeLength(toparse []byte) (int, int, error)
- func DecodeSequence(toparse []byte) ([]interface{}, error)
- func DecodeTimeticks(toparse []byte) (string, error)
- func DecryptAESCFB(dst, src, key, iv []byte) error
- func DecryptDESCBC(dst, src, key, iv []byte) 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 EncodeUInteger32(toEncode uint32) []byte
- func EncryptAESCFB(dst, src, key, iv []byte) error
- func EncryptDESCBC(dst, src, key, iv []byte) error
- func IsStringAsciiPrintable(s string) bool
- func NewUdpStub(t *testing.T) *udpStub
- type BERType
- type IPAddress
- type Oid
- type SNMPError
- type SNMPVersion
- type SnmpV3MsgFlags
- type SnmpV3SecurityModel
- type V3user
- type WapSNMP
- func (w WapSNMP) Close() error
- func (w *WapSNMP) Discover() error
- func (w WapSNMP) Get(oid Oid) (interface{}, error)
- func (w WapSNMP) GetBulk(oid Oid, maxRepetitions int) (map[string]interface{}, *orderedmap.OrderedMap[string, interface{}], error)
- func (w *WapSNMP) GetBulkV3(oid Oid, maxRepetitions int) (map[string]interface{}, *orderedmap.OrderedMap[string, interface{}], error)
- func (w WapSNMP) GetMultiple(oids []Oid) (map[string]interface{}, error)
- func (w *WapSNMP) GetMultipleV3(oids []Oid) (map[string]interface{}, error)
- func (w WapSNMP) GetNext(oid Oid) (string, interface{}, error)
- func (w *WapSNMP) GetNextV3(oid Oid) (string, interface{}, error)
- func (w WapSNMP) GetTable(oid Oid) (*orderedmap.OrderedMap[string, interface{}], error)
- func (w *WapSNMP) GetV3(oid Oid) (interface{}, error)
- func (w WapSNMP) ParseTrap(response []byte) error
- func (w WapSNMP) Set(oid Oid, value interface{}) (interface{}, error)
- func (w *WapSNMP) SetV3(oid Oid, value interface{}) (interface{}, error)
Constants ¶
const ( SNMP_AES string = "AES" SNMP_DES string = "DES" SNMP_SHA1 string = "SHA1" SNMP_MD5 string = "MD5" )
Variables ¶
This section is empty.
Functions ¶
func DecodeCounter64 ¶
func DecodeIPAddress ¶
func DecodeInt64 ¶
DecodeInt64 treats the given bytes as a big-endian, signed integer and returns the result.
func DecodeInteger ¶
DecodeInteger decodes an integer. This does not handle signed value.
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 *[]interface{}.
func DecodeTimeticks ¶
func DecryptAESCFB ¶
func DecryptDESCBC ¶
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.
func EncodeUInteger32 ¶
EncodeUInteger32 encodes an Unsigned32 integer to BER format.
func EncryptAESCFB ¶
func EncryptDESCBC ¶
func IsStringAsciiPrintable ¶
IsStringAsciiPrintable checks if the given string is ASCII and is printable form. Returns boolean value
Types ¶
type BERType ¶
type BERType uint8
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 Uinteger32 BERType = AsnApplication | 0x07 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 NoSuchObject BERType = 0x80 NoSuchInstance BERType = 0x81 EndOfMibView BERType = 0x82 )
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 SNMPError ¶
type SNMPError uint8 // SNMPError is the type for standard SNMP errors.
const ( NoError SNMPError = iota // No error occurred. This code is also used in all request PDUs, since they have no error status to report. TooBig // The size of the Response-PDU would be too large to transport. NoSuchName // The name of a requested object was not found. BadValue // A value in the request didn't match the structure that the recipient of the request had for the object. For example, an object in the request was specified with an incorrect length or type. ReadOnly // An attempt was made to set a variable that has an Access value indicating that it is read-only. GenErr // An error occurred other than one indicated by a more specific error code in this table. NoAccess // Access was denied to the object for security reasons. WrongType // The object type in a variable binding is incorrect for the object. WrongLength // A variable binding specifies a length incorrect for the object. WrongEncoding // A variable binding specifies an encoding incorrect for the object. WrongValue // The value given in a variable binding is not possible for the object. NoCreation // A specified variable does not exist and cannot be created. InconsistentValue // A variable binding specifies a value that could be held by the variable but cannot be assigned to it at this time. CommitFailed // An attempt to set a particular variable failed. UndoFailed // An attempt to set a particular variable as part of a group of variables failed, and the attempt to then undo the setting of other variables was not successful. AuthorizationError // A problem occurred in authorization. NotWritable // The variable cannot be written or created. InconsistentName // The name in a variable binding specifies a variable that does not exist. )
SNMP Errors
type SNMPVersion ¶
type SNMPVersion uint8
Type to indicate which SNMP version is in use.
const ( SNMPv1 SNMPVersion = 0 SNMPv2c SNMPVersion = 1 SNMPv3 SNMPVersion = 3 )
List the supported snmp versions.
type SnmpV3MsgFlags ¶
type SnmpV3MsgFlags uint8
SnmpV3MsgFlags contains various message flags to describe Authentication, Privacy, and whether a report PDU must be sent.
const ( NoAuthNoPriv SnmpV3MsgFlags = 0x0 // No authentication, and no privacy AuthNoPriv SnmpV3MsgFlags = 0x1 // Authentication and no privacy AuthPriv SnmpV3MsgFlags = 0x3 // Authentication and privacy Reportable SnmpV3MsgFlags = 0x4 // Report PDU must be sent. AuthPrivReport SnmpV3MsgFlags = 0x7 //Authentication and privacy + report PDU )
Possible values of SnmpV3MsgFlags
type SnmpV3SecurityModel ¶
type SnmpV3SecurityModel int
SnmpV3SecurityModel describes the security model used by a SnmpV3 connection
const (
UserSecurityModel SnmpV3SecurityModel = 0x03
)
UserSecurityModel is the only SnmpV3SecurityModel currently implemented.
type WapSNMP ¶
type WapSNMP 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. //SNMP V3 variables User string AuthAlg string //MD5 or SHA1 AuthPwd string PrivAlg string //AES or DES PrivPwd string MessageFlags SnmpV3MsgFlags //V3 temp variables AuthKey string PrivKey string Trapusers []V3user // contains filtered or unexported fields }
The object type that lets you do SNMP requests.
func NewWapSNMP ¶
func NewWapSNMP(target, community string, version SNMPVersion, timeout time.Duration, retries int) (*WapSNMP, error)
NewWapSNMP creates a new WapSNMP object. Opens a udp connection to the device that will be used for the SNMP packets.
func NewWapSNMPOnConn ¶
func NewWapSNMPOnConn(target, community string, version SNMPVersion, timeout time.Duration, retries int, conn net.Conn) *WapSNMP
NewWapSNMPOnConn creates a new WapSNMP object from an existing net.Conn.
It does not check if the provided target is valid.
func NewWapSNMPv3 ¶
func (*WapSNMP) 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 (WapSNMP) GetBulk ¶
func (w WapSNMP) GetBulk(oid Oid, maxRepetitions int) (map[string]interface{}, *orderedmap.OrderedMap[string, interface{}], error)
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 (*WapSNMP) GetBulkV3 ¶
func (w *WapSNMP) GetBulkV3(oid Oid, maxRepetitions int) (map[string]interface{}, *orderedmap.OrderedMap[string, interface{}], error)
GetBulk snmpv3 request.
func (WapSNMP) GetMultiple ¶
GetMultiple issues a single GET SNMP request requesting multiple values
func (*WapSNMP) GetMultipleV3 ¶
A function that does GetMultiple for SNMP V3
func (WapSNMP) GetTable ¶
func (w WapSNMP) GetTable(oid Oid) (*orderedmap.OrderedMap[string, interface{}], error)
GetTable efficiently gets an entire table from an SNMP agent. Uses GETBULK requests to go fast.
func (WapSNMP) ParseTrap ¶
ParseTrap parses a received SNMP trap and returns a map of oid to objects