Documentation
¶
Index ¶
- Constants
- Variables
- func Partition(currentPosition, partitionSize, sliceLength int) bool
- func ToBigInt(value interface{}) *big.Int
- type Asn1BER
- type BitStringValue
- type GoSNMP
- func (x *GoSNMP) BulkWalk(rootOid string, walkFn WalkFunc) error
- func (x *GoSNMP) BulkWalkAll(rootOid string) (results []SnmpPDU, err error)
- func (x *GoSNMP) Connect() error
- func (x *GoSNMP) Get(oids []string) (result *SnmpPacket, err error)
- func (x *GoSNMP) GetBulk(oids []string, nonRepeaters uint8, maxRepetitions uint8) (result *SnmpPacket, err error)
- func (x *GoSNMP) GetNext(oids []string) (result *SnmpPacket, err error)
- func (x *GoSNMP) Set(pdus []SnmpPDU) (result *SnmpPacket, err error)
- func (x *GoSNMP) Walk(rootOid string, walkFn WalkFunc) error
- func (x *GoSNMP) WalkAll(rootOid string) (results []SnmpPDU, err error)
- type Logger
- type PDUType
- type SnmpPDU
- type SnmpPacket
- type SnmpV3AuthProtocol
- type SnmpV3MsgFlags
- type SnmpV3PrivProtocol
- type SnmpV3SecurityModel
- type SnmpV3SecurityParameters
- type SnmpVersion
- type TrapListener
- type UsmSecurityParameters
- type VarBind
- type WalkFunc
Constants ¶
const ( EndOfContents Asn1BER = 0x00 UnknownType = 0x00 // TODO these should all be type Asn1BER, however Boolean = 0x01 // tests fail if implemented. See for example Integer = 0x02 /// http://stackoverflow.com/questions/5037610/typed-constant-declaration-list. BitString = 0x03 OctetString = 0x04 Null = 0x05 ObjectIdentifier = 0x06 ObjectDescription = 0x07 IPAddress = 0x40 Counter32 = 0x41 Gauge32 = 0x42 TimeTicks = 0x43 Opaque = 0x44 NsapAddress = 0x45 Counter64 = 0x46 Uinteger32 = 0x47 NoSuchObject = 0x80 NoSuchInstance = 0x81 EndOfMibView = 0x82 )
Asn1BER's - http://www.ietf.org/rfc/rfc1442.txt
const ( NoError = 0 // No error occurred. This code is also used in all request PDUs, since they have no error status to report. TooBig = 1 // The size of the Response-PDU would be too large to transport. NoSuchName = 2 // The name of a requested object was not found. BadValue = 3 // 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 = 4 // An attempt was made to set a variable that has an Access value indicating that it is read-only. GenErr = 5 // An error occurred other than one indicated by a more specific error code in this table. NoAccess = 6 // Access was denied to the object for security reasons. WrongType = 7 // The object type in a variable binding is incorrect for the object. WrongLength = 8 // A variable binding specifies a length incorrect for the object. WrongEncoding = 9 // A variable binding specifies an encoding incorrect for the object. WrongValue = 10 // The value given in a variable binding is not possible for the object. NoCreation = 11 // A specified variable does not exist and cannot be created. InconsistentValue = 12 // A variable binding specifies a value that could be held by the variable but cannot be assigned to it at this time. CommitFailed = 14 // An attempt to set a particular variable failed. UndoFailed = 15 // 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 = 16 // A problem occurred in authorization. NotWritable = 17 // The variable cannot be written or created. InconsistentName = 18 // The name in a variable binding specifies a variable that does not exist. )
SNMP Errors
Variables ¶
var Default = &GoSNMP{ Port: 161, Community: "public", Version: Version2c, Timeout: time.Duration(2) * time.Second, Retries: 3, }
The default connection settings
Functions ¶
func Partition ¶
Partition - returns true when dividing a slice into partitionSize lengths, including last partition which may be smaller than partitionSize. This is useful when you have a large array of OIDs to run Get() on. See the tests for example usage.
For example for a slice of 8 items to be broken into partitions of length 3, Partition returns true for the currentPosition having the following values:
0 1 2 3 4 5 6 7
T T T
func ToBigInt ¶
ToBigInt converts SnmpPDU.Value to big.Int, or returns a zero big.Int for non int-like types (eg strings).
This is a convenience function to make working with SnmpPDU's easier - it reduces the need for type assertions. A big.Int is convenient, as SNMP can return int32, uint32, and uint64.
Types ¶
type BitStringValue ¶
type BitStringValue struct {
Bytes []byte // bits packed into bytes.
BitLength int // length in bits.
}
BitStringValue is the structure to use when you want an ASN.1 BIT STRING type. A bit string is padded up to the nearest byte in memory and the number of valid bits is recorded. Padding bits will be zero.
func (BitStringValue) At ¶
func (b BitStringValue) At(i int) int
At returns the bit at the given index. If the index is out of range it returns false.
func (BitStringValue) RightAlign ¶
func (b BitStringValue) RightAlign() []byte
RightAlign returns a slice where the padding bits are at the beginning. The slice may share memory with the BitString.
type GoSNMP ¶
type GoSNMP struct {
// Target is an ipv4 address
Target string
// Port is a udp port
Port uint16
// Version is an SNMP Version
Version SnmpVersion
// Community is an SNMP Community string
Community string
// Timeout is the timeout for the SNMP Query
Timeout time.Duration
// Set the number of retries to attempt within timeout.
Retries int
// Logger is the GoSNMP.Logger to use for debugging. If nil, debugging
// output will be discarded (/dev/null). For verbose logging to stdout:
// x.Logger = log.New(os.Stdout, "", 0)
Logger Logger
// MsgFlags is an SNMPV3 MsgFlags
MsgFlags SnmpV3MsgFlags
// SecurityModel is an SNMPV3 Security Model
SecurityModel SnmpV3SecurityModel
// SecurityParameters is an SNMPV3 Security Model paramaters struct
SecurityParameters SnmpV3SecurityParameters
// ContextEngineID is SNMPV3 ContextEngineID in ScopedPDU
ContextEngineID string
// ContextName is SNMPV3 ContextName in ScopedPDU
ContextName string
// Conn is net connection to use, typically establised using GoSNMP.Connect()
Conn net.Conn
// MaxRepetitions sets the GETBULK max-repetitions used by BulkWalk*
// (default: 50)
MaxRepetitions int
// NonRepeaters sets the GETBULK max-repeaters used by BulkWalk*
// (default: 0 as per RFC 1905)
NonRepeaters int
// contains filtered or unexported fields
}
GoSNMP represents GoSNMP library state
func (*GoSNMP) BulkWalk ¶
BulkWalk retrieves a subtree of values using GETBULK. As the tree is walked walkFn is called for each new value. The function immediately returns an error if either there is an underlaying SNMP error (e.g. GetBulk fails), or if walkFn returns an error.
func (*GoSNMP) BulkWalkAll ¶
BulkWalkAll is similar to BulkWalk but returns a filled array of all values rather than using a callback function to stream results.
func (*GoSNMP) Get ¶
func (x *GoSNMP) Get(oids []string) (result *SnmpPacket, err error)
Get sends an SNMP GET request
func (*GoSNMP) GetBulk ¶
func (x *GoSNMP) GetBulk(oids []string, nonRepeaters uint8, maxRepetitions uint8) (result *SnmpPacket, err error)
GetBulk sends an SNMP GETBULK request
func (*GoSNMP) GetNext ¶
func (x *GoSNMP) GetNext(oids []string) (result *SnmpPacket, err error)
GetNext sends an SNMP GETNEXT request
func (*GoSNMP) Set ¶
func (x *GoSNMP) Set(pdus []SnmpPDU) (result *SnmpPacket, err error)
Set sends an SNMP SET request
func (*GoSNMP) Walk ¶
Walk retrieves a subtree of values using GETNEXT - a request is made for each value, unlike BulkWalk which does this operation in batches. As the tree is walked walkFn is called for each new value. The function immediately returns an error if either there is an underlaying SNMP error (e.g. GetNext fails), or if walkFn returns an error.
type Logger ¶
type Logger interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
}
Logger is an interface used for debugging. Both Print and Printf have the same interfaces as Package Log in the std library. The Logger interface is small to give you flexibility in how you do your debugging.
For verbose logging to stdout:
gosnmp_logger = log.New(os.Stdout, "", 0)
type PDUType ¶
type PDUType byte
PDUType describes which SNMP Protocol Data Unit is being sent.
const ( Sequence PDUType = 0x30 GetRequest PDUType = 0xa0 GetNextRequest PDUType = 0xa1 GetResponse PDUType = 0xa2 SetRequest PDUType = 0xa3 Trap PDUType = 0xa4 GetBulkRequest PDUType = 0xa5 InformRequest PDUType = 0xa6 SNMPV2Trap PDUType = 0xa7 Report PDUType = 0xa8 )
The currently supported PDUType's
type SnmpPDU ¶
type SnmpPDU struct {
// Name is an oid in string format eg ".1.3.6.1.4.9.27"
Name string
// The type of the value eg Integer
Type Asn1BER
// The value to be set by the SNMP set
Value interface{}
}
SnmpPDU will be used when doing SNMP Set's
type SnmpPacket ¶
type SnmpPacket struct {
Version SnmpVersion
MsgFlags SnmpV3MsgFlags
SecurityModel SnmpV3SecurityModel
SecurityParameters SnmpV3SecurityParameters
ContextEngineID string
ContextName string
Community string
PDUType PDUType
MsgID uint32
RequestID uint32
Error uint8
ErrorIndex uint8
NonRepeaters uint8
MaxRepetitions uint8
Variables []SnmpPDU
}
SnmpPacket struct represents the entire SNMP Message or Sequence at the application layer.
type SnmpV3AuthProtocol ¶
type SnmpV3AuthProtocol uint8
SnmpV3AuthProtocol describes the authentication protocol in use by an authenticated SnmpV3 connection.
const ( NoAuth SnmpV3AuthProtocol = 1 MD5 SnmpV3AuthProtocol = 2 SHA SnmpV3AuthProtocol = 3 )
NoAuth, MD5, and SHA are implemented
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. )
Possible values of SnmpV3MsgFlags
type SnmpV3PrivProtocol ¶
type SnmpV3PrivProtocol uint8
SnmpV3PrivProtocol is the privacy protocol in use by an private SnmpV3 connection.
const ( NoPriv SnmpV3PrivProtocol = 1 DES SnmpV3PrivProtocol = 2 AES SnmpV3PrivProtocol = 3 )
NoPriv, DES implemented, AES planned
type SnmpV3SecurityModel ¶
type SnmpV3SecurityModel uint8
SnmpV3SecurityModel describes the security model used by a SnmpV3 connection
const (
UserSecurityModel SnmpV3SecurityModel = 3
)
UserSecurityModel is the only SnmpV3SecurityModel currently implemented.
type SnmpV3SecurityParameters ¶
type SnmpV3SecurityParameters interface {
Copy() SnmpV3SecurityParameters
}
SnmpV3SecurityParameters is a generic interface type to contain various implementations of SnmpV3SecurityParameters
type SnmpVersion ¶
type SnmpVersion uint8
SnmpVersion 1, 2c and 3 implemented
const ( Version1 SnmpVersion = 0x0 Version2c SnmpVersion = 0x1 Version3 SnmpVersion = 0x3 )
SnmpVersion 1, 2c and 3 implemented
func (SnmpVersion) String ¶
func (s SnmpVersion) String() string
type TrapListener ¶
type TrapListener struct {
OnNewTrap func(s *SnmpPacket, u *net.UDPAddr)
Params *GoSNMP
}
A TrapListener defineds parameters for running a SNMP Trap reciever. nil values will be replaced by default values.
func (*TrapListener) Listen ¶
func (t *TrapListener) Listen(addr string) (err error)
Listen listens on the UDP address addr and calls the OnNewTrap function specified in *TrapListener for every trap recieved.
type UsmSecurityParameters ¶
type UsmSecurityParameters struct {
AuthoritativeEngineID string
AuthoritativeEngineBoots uint32
AuthoritativeEngineTime uint32
UserName string
AuthenticationParameters string
PrivacyParameters []byte
AuthenticationProtocol SnmpV3AuthProtocol
PrivacyProtocol SnmpV3PrivProtocol
AuthenticationPassphrase string
PrivacyPassphrase string
// contains filtered or unexported fields
}
UsmSecurityParameters is an implementation of SnmpV3SecurityParameters for the UserSecurityModel
func (*UsmSecurityParameters) Copy ¶
func (sp *UsmSecurityParameters) Copy() SnmpV3SecurityParameters
Copy method for UsmSecurityParameters used to copy a SnmpV3SecurityParameters without knowing it's implementation
