Documentation ¶
Index ¶
- Constants
- Variables
- func MarshalVarBind(data *SNMPData) ([]byte, error)
- func Partition(curPos, partitionSize, sliceLen 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 []SNMPData, err error)
- func (x *GoSNMP) Close() error
- func (x *GoSNMP) Connect() error
- func (x *GoSNMP) Get(oids []string) (result *SNMPPacket, err error)
- func (x *GoSNMP) GetBulk(oids []string, nonRepeaters uint8, maxReps uint8) (result *SNMPPacket, err error)
- func (x *GoSNMP) GetNext(oids []string) (result *SNMPPacket, err error)
- func (x *GoSNMP) Set(data []SNMPData) (result *SNMPPacket, err error)
- func (x *GoSNMP) Walk(rootOid string, walkFn WalkFunc) error
- func (x *GoSNMP) WalkAll(rootOid string) (results []SNMPData, err error)
- type Logger
- type PDUType
- type SNMPData
- type SNMPPacket
- type SNMPVersion
- type VarBind
- type Variable
- type WalkFunc
Constants ¶
const ( EndOfContents ASN1BER = 0x00 UnknownType = 0x00 Boolean = 0x01 Integer = 0x02 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 )
const ( Sequence PDUType = 0x30 GetRequest = 0xa0 GetNextRequest = 0xa1 GetResponse = 0xa2 SetRequest = 0xa3 Trap = 0xa4 GetBulkRequest = 0xa5 )
const (
MaxOids = 60 //MaxOids is the maximum number of oids allowed in a Get()
)
Variables ¶
var Default = &GoSNMP{ Port: 161, Community: "public", Version: Version2c, Timeout: time.Duration(2) * time.Second, Retries: 3, }
Default contains the defaul values for an SNMP connection if none are provided
Functions ¶
func MarshalVarBind ¶
MarshalVarBind marshals a varbind??? TODO: what does this mean?
func Partition ¶
Partition - returns true when dividing a slice into partition_size lengths, including last partition which may be smaller than partition_size. 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 current_position having the following values:
0 1 2 3 4 5 6 7
T T T
func ToBigInt ¶
ToBigInt converts SNMPData.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 SNMPData'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 string //Target is an IP address Port uint16 //Port is a udp port Community string //Community is an SNMP Community string Version SNMPVersion //Version is an SNMP Version Timeout time.Duration //Timeout is the timeout for the SNMP Query Retries int //Set the number of retries to attempt within timeout. Conn net.Conn //Conn is net connection to use, typically establised using GoSNMP.Connect() //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 // contains filtered or unexported fields }
GoSNMP is the struct containing info about an SNMP connection
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 send an SNMP GET request using the connection made with Connect
func (*GoSNMP) GetBulk ¶
func (x *GoSNMP) GetBulk(oids []string, nonRepeaters uint8, maxReps uint8) (result *SNMPPacket, err error)
GetBulk send an SNMP GETBULK request
func (*GoSNMP) GetNext ¶
func (x *GoSNMP) GetNext(oids []string) (result *SNMPPacket, err error)
GetNext send an SNMP GETNEXT request using the connection made with Connect
func (*GoSNMP) Set ¶
func (x *GoSNMP) Set(data []SNMPData) (result *SNMPPacket, err error)
Set send an SNMP SET request using the connection made with Connect
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 SNMPData ¶
type SNMPData struct { Name string //Name is an oid in string format eg "1.3.6.1.4.9.27" Type ASN1BER //The type of the value eg Integer Value interface{} // The value to be set by the SNMP set }
SNMPData will be used when doing SNMP Set's
type SNMPPacket ¶
type SNMPPacket struct { Version SNMPVersion Community string PDUType PDUType RequestID uint32 Error uint8 ErrorIndex uint8 NonRepeaters uint8 MaxReps uint8 Variables []SNMPData }
SNMPPacket contains all of the info required for an SNMP PAcket
type SNMPVersion ¶
type SNMPVersion uint8
SNMPVersion indicates the SNMP version
const ( //Version1 defines the SNMPv1 code Version1 SNMPVersion = 0x0 //Version2c devinces the SNMPv2c code Version2c SNMPVersion = 0x1 )
func (SNMPVersion) String ¶
func (s SNMPVersion) String() string
type VarBind ¶
type VarBind struct { Name asn1.ObjectIdentifier Value asn1.RawValue }
VarBind contains bindings to the Variable(s)???? TODO: Figure out what the heck this means