snmpclient2

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: MIT Imports: 34 Imported by: 1

README

snmpgo

snmpgo is a golang implementation for sending SNMP messages.

Supported Message Types

  • SNMP V1
    • GetRequest
    • GetNextRequest
  • SNMP V2c, V3
    • GetRequest
    • GetNextRequest
    • GetBulkRequest
    • V2Trap
    • InformRequest

Examples

getv2.go, getv3.go

Example for sending a GetRequest. Explain how to use basic of the API.

package main

import (
    "fmt"

    "github.com/k-sone/snmpgo"
)

func main() {
    snmp, err := snmpgo.NewSNMP(snmpgo.Arguments{
        Version:   snmpgo.V2c,
        Address:   "127.0.0.1:161",
        Retries:   1,
        Community: "public",
    })
    if err != nil {
        // Failed to create snmpgo.SNMP object
        fmt.Println(err)
        return
    }

    oids, err := snmpgo.NewOids([]string{
        "1.3.6.1.2.1.1.1.0",
        "1.3.6.1.2.1.1.2.0",
        "1.3.6.1.2.1.1.3.0",
    })
    if err != nil {
        // Failed to parse Oids
        fmt.Println(err)
        return
    }

    if err = snmp.Open(); err != nil {
        // Failed to open connection
        fmt.Println(err)
        return
    }
    defer snmp.Close()

    pdu, err := snmp.GetRequest(oids)
    if err != nil {
        // Failed to request
        fmt.Println(err)
        return
    }
    if pdu.ErrorStatus() != snmpgo.NoError {
        // Received an error from the agent
        fmt.Println(pdu.ErrorStatus(), pdu.ErrorIndex())
    }

    // get VariableBinding list
    fmt.Println(pdu.VariableBindings())

    // select a VariableBinding
    fmt.Println(pdu.VariableBindings().MatchOid(oids[0]))
}

trapv2.go, trapv3.go

Example for sending a V2Trap. Explain how to build VariableBindings using API.

multiget.go

Example for sending a GetRequest to multiple agents.

ifstat.go

This command displays the traffic of agent at regular intervals. Explain how to process the obtained information.

snmpgoget.go

snmpget@Net-SNMP like command.

snmpgobulkwalk.go

snmpbulkwalk@Net-SNMP like command.

snmpgotrap.go

snmptrap@Net-SNMP like command.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OidSysUpTime = MustParseOidFromString("1.3.6.1.2.1.1.3.0")
	OidSnmpTrap  = MustParseOidFromString("1.3.6.1.6.3.1.1.4.1.0")
)
View Source
var ENDOFMIBVIEW = &EndOfMibView{Null{}}
View Source
var NOSUCHEINSTANCE = &NoSucheInstance{Null{}}
View Source
var NOSUCHEOBJECT = &NoSucheObject{Null{}}
View Source
var TimeoutError = errors.New("time out")
View Source
var UnsupportedOperation error = errors.New("Unsupported operation")

Functions

func ArgsValidate added in v1.1.0

func ArgsValidate(args *Arguments) error

For snmpgo testing

func AsInt added in v1.1.0

func AsInt(value Variable) (int, error)

func AsInt32 added in v1.1.0

func AsInt32(value Variable) (int32, error)

func AsInt64 added in v1.1.0

func AsInt64(value Variable) (int64, error)

Int type AsSerts to `float64` then converts to `int`

func AsString added in v1.1.0

func AsString(value Variable) (string, error)

func AsUint added in v1.1.0

func AsUint(value Variable) (uint, error)

func AsUint32 added in v1.1.0

func AsUint32(value Variable) (uint32, error)

func AsUint64 added in v1.1.0

func AsUint64(value Variable) (uint64, error)

Uint type AsSerts to `float64` then converts to `int`

func DecryptAES added in v1.1.0

func DecryptAES(src, key, privParam []byte, engineBoots, engineTime int32) (
	dst []byte, err error)

func DecryptDES added in v1.1.0

func DecryptDES(src, key, privParam []byte) (dst []byte, err error)

func EncryptAES added in v1.1.0

func EncryptAES(src, key []byte, engineBoots, engineTime int32, salt int64) (
	dst, privParam []byte, err error)

func EncryptDES added in v1.1.0

func EncryptDES(src, key []byte, engineBoots, salt int32) (dst, privParam []byte, err error)

func ParseIntsFromString added in v1.1.0

func ParseIntsFromString(s string) ([]int, error)

func ParseLine added in v1.1.0

func ParseLine(ss []string, is_end bool) (*Oid, Variable, []string, error)

func PasswordToKey added in v1.1.0

func PasswordToKey(proto AuthProtocol, password string, engineId []byte) []byte

func Read added in v1.1.0

func Read(reader io.Reader, cb func(oid Oid, value Variable) error) error

func ReadHex added in v1.1.0

func ReadHex(buf *bytes.Buffer, s string) error

func SnmpCheckPdu added in v1.1.0

func SnmpCheckPdu(snmp *SNMP, pdu PDU) error

func StripHexPrefix added in v1.1.0

func StripHexPrefix(s string) string

func ToHexStr added in v1.1.0

func ToHexStr(a []byte, sep string) string

func ToOidString added in v1.1.0

func ToOidString(sub []int) string

func ToSyntexString added in v1.1.0

func ToSyntexString(t int) string

Types

type ArgumentError

type ArgumentError struct {
	Value   interface{} // Argument that has a problem
	Message string      // Error message
}

An ArgumentError suggests that the arguments are wrong

func (ArgumentError) Error

func (e ArgumentError) Error() string

type Arguments added in v1.1.0

type Arguments struct {
	Version          SnmpVersion   // SNMP version to use
	Timeout          time.Duration // Request timeout (The default is 5sec)
	Retries          uint          // Number of retries (The default is `0`)
	MessageMaxSize   int           // Maximum size of an SNMP message (The default is `1400`)
	Community        string        // Community (V1 or V2c specific)
	UserName         string        // Security name (V3 specific)
	SecurityLevel    SecurityLevel // Security level (V3 specific)
	AuthPassword     string        // Authentication protocol pass phrase (V3 specific)
	AuthProtocol     AuthProtocol  // Authentication protocol (V3 specific)
	AuthKey          []byte
	PrivPassword     string       // Privacy protocol pass phrase (V3 specific)
	PrivProtocol     PrivProtocol // Privacy protocol (V3 specific)
	PrivKey          []byte
	SecurityEngineId string // Security engine ID (V3 specific)
	ContextEngineId  string // Context engine ID (V3 specific)
	ContextName      string // Context name (V3 specific)
}

An argument for creating a SNMP Object

func GetArgs added in v1.1.0

func GetArgs(snmp *SNMP) *Arguments

func (*Arguments) String added in v1.1.0

func (a *Arguments) String() string

type AuthProtocol

type AuthProtocol string
const (
	Md5 AuthProtocol = "MD5"
	Sha AuthProtocol = "SHA"
)

func ParseAuthProtocol added in v1.1.0

func ParseAuthProtocol(s string) (AuthProtocol, error)

type CompareFunc added in v1.1.0

type CompareFunc func(a, b Item) int

CompareFunc returns 0 if a==b, <0 if a<b, >0 if a>b.

type Counter32

type Counter32 struct {
	Value uint32
}

func NewCounter32

func NewCounter32(i uint32) *Counter32

func (*Counter32) Bytes added in v1.1.0

func (v *Counter32) Bytes() []byte

func (*Counter32) ErrorMessage added in v1.1.0

func (v *Counter32) ErrorMessage() string

func (*Counter32) Int added in v1.1.0

func (v *Counter32) Int() int64

func (*Counter32) IsError added in v1.1.0

func (v *Counter32) IsError() bool

func (*Counter32) Marshal

func (v *Counter32) Marshal() ([]byte, error)

func (*Counter32) MarshalJSON added in v1.1.0

func (v *Counter32) MarshalJSON() ([]byte, error)

func (*Counter32) String

func (v *Counter32) String() string

func (*Counter32) Syntex added in v1.1.0

func (v *Counter32) Syntex() int

func (*Counter32) ToString added in v1.1.0

func (v *Counter32) ToString() string

func (*Counter32) Uint added in v1.1.0

func (v *Counter32) Uint() uint64

func (*Counter32) Unmarshal

func (v *Counter32) Unmarshal(b []byte) (rest []byte, err error)

type Counter64

type Counter64 struct {
	Value uint64
}

func NewCounter64

func NewCounter64(i uint64) *Counter64

func (*Counter64) Bytes added in v1.1.0

func (v *Counter64) Bytes() []byte

func (*Counter64) ErrorMessage added in v1.1.0

func (v *Counter64) ErrorMessage() string

func (*Counter64) Int added in v1.1.0

func (v *Counter64) Int() int64

func (*Counter64) IsError added in v1.1.0

func (v *Counter64) IsError() bool

func (*Counter64) Marshal

func (v *Counter64) Marshal() ([]byte, error)

func (*Counter64) MarshalJSON added in v1.1.0

func (v *Counter64) MarshalJSON() ([]byte, error)

func (*Counter64) String

func (v *Counter64) String() string

func (*Counter64) Syntex added in v1.1.0

func (v *Counter64) Syntex() int

func (*Counter64) ToString added in v1.1.0

func (v *Counter64) ToString() string

func (*Counter64) Uint added in v1.1.0

func (v *Counter64) Uint() uint64

func (*Counter64) Unmarshal

func (v *Counter64) Unmarshal(b []byte) (rest []byte, err error)

type EndOfMibView

type EndOfMibView struct {
	Null
}

func NewEndOfMibView

func NewEndOfMibView() *EndOfMibView

func (*EndOfMibView) Bytes added in v1.1.0

func (v *EndOfMibView) Bytes() []byte

func (*EndOfMibView) ErrorMessage added in v1.1.0

func (v *EndOfMibView) ErrorMessage() string

func (*EndOfMibView) IsError added in v1.1.0

func (v *EndOfMibView) IsError() bool

func (*EndOfMibView) Marshal

func (v *EndOfMibView) Marshal() ([]byte, error)

func (*EndOfMibView) MarshalJSON added in v1.1.0

func (v *EndOfMibView) MarshalJSON() ([]byte, error)

func (*EndOfMibView) String added in v1.1.0

func (v *EndOfMibView) String() string

func (*EndOfMibView) Syntex added in v1.1.0

func (v *EndOfMibView) Syntex() int

func (*EndOfMibView) Unmarshal

func (v *EndOfMibView) Unmarshal(b []byte) (rest []byte, err error)

type ErrorStatus

type ErrorStatus int
const (
	NoError ErrorStatus = iota
	TooBig
	NoSuchName
	BadValue
	ReadOnly
	GenError
	NoAccess
	WrongType
	WrongLength
	WrongEncoding
	WrongValue
	NoCreation
	InconsistentValue
	ResourceUnavailable
	CommitFailed
	UndoFailed
	AuthorizationError
	NotWritable
	InconsistentName
)

func (ErrorStatus) String

func (e ErrorStatus) String() string

type Gauge32

type Gauge32 struct {
	Counter32
}

func NewGauge32

func NewGauge32(i uint32) *Gauge32

func (*Gauge32) Marshal

func (v *Gauge32) Marshal() ([]byte, error)

func (*Gauge32) MarshalJSON added in v1.1.0

func (v *Gauge32) MarshalJSON() ([]byte, error)

func (*Gauge32) String added in v1.1.0

func (v *Gauge32) String() string

func (*Gauge32) Syntex added in v1.1.0

func (v *Gauge32) Syntex() int

func (*Gauge32) Unmarshal

func (v *Gauge32) Unmarshal(b []byte) (rest []byte, err error)

type Integer

type Integer struct {
	Value int
}

func NewInteger

func NewInteger(i int32) *Integer

func (*Integer) Bytes added in v1.1.0

func (v *Integer) Bytes() []byte

func (*Integer) ErrorMessage added in v1.1.0

func (v *Integer) ErrorMessage() string

func (*Integer) Int added in v1.1.0

func (v *Integer) Int() int64

func (*Integer) IsError added in v1.1.0

func (v *Integer) IsError() bool

func (*Integer) Marshal

func (v *Integer) Marshal() ([]byte, error)

func (*Integer) MarshalJSON added in v1.1.0

func (v *Integer) MarshalJSON() ([]byte, error)

func (*Integer) String

func (v *Integer) String() string

func (*Integer) Syntex added in v1.1.0

func (v *Integer) Syntex() int

func (*Integer) ToString added in v1.1.0

func (v *Integer) ToString() string

func (*Integer) Uint added in v1.1.0

func (v *Integer) Uint() uint64

func (*Integer) Unmarshal

func (v *Integer) Unmarshal(b []byte) (rest []byte, err error)

type Ipaddress

type Ipaddress struct {
	OctetString
}

func NewIpaddress

func NewIpaddress(a, b, c, d byte) *Ipaddress

func (*Ipaddress) Int added in v1.1.0

func (v *Ipaddress) Int() int64

func (*Ipaddress) Marshal

func (v *Ipaddress) Marshal() ([]byte, error)

func (*Ipaddress) MarshalJSON added in v1.1.0

func (v *Ipaddress) MarshalJSON() ([]byte, error)

func (*Ipaddress) String

func (v *Ipaddress) String() string

func (*Ipaddress) Syntex added in v1.1.0

func (v *Ipaddress) Syntex() int

func (*Ipaddress) ToString added in v1.1.0

func (v *Ipaddress) ToString() string

func (*Ipaddress) Uint added in v1.1.0

func (v *Ipaddress) Uint() uint64

func (*Ipaddress) Unmarshal

func (v *Ipaddress) Unmarshal(b []byte) (rest []byte, err error)

type Item added in v1.1.0

type Item interface{}

Item is the object stored in each tree node.

type Iterator added in v1.1.0

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

Iterator allows scanning tree elements in sort order.

Iterator invalidation rule is the same as C++ std::map<>'s. That is, if you delete the element that an iterator points to, the iterator becomes invalid. For other operation types, the iterator remains valid.

func (Iterator) Equal added in v1.1.0

func (iter Iterator) Equal(iter2 Iterator) bool

func (Iterator) Item added in v1.1.0

func (iter Iterator) Item() interface{}

Return the current element.

REQUIRES: !iter.Limit() && !iter.NegativeLimit()

func (Iterator) Limit added in v1.1.0

func (iter Iterator) Limit() bool

Check if the iterator points beyond the max element in the tree

func (Iterator) Max added in v1.1.0

func (iter Iterator) Max() bool

Check if the iterator points to the maximum element in the tree

func (Iterator) Min added in v1.1.0

func (iter Iterator) Min() bool

Check if the iterator points to the minimum element in the tree

func (Iterator) NegativeLimit added in v1.1.0

func (iter Iterator) NegativeLimit() bool

Check if the iterator points before the minumum element in the tree

func (Iterator) Next added in v1.1.0

func (iter Iterator) Next() Iterator

Create a new iterator that points to the successor of the current element.

REQUIRES: !iter.Limit()

func (Iterator) Prev added in v1.1.0

func (iter Iterator) Prev() Iterator

Create a new iterator that points to the predecessor of the current node.

REQUIRES: !iter.NegativeLimit()

type Message added in v1.1.0

type Message interface {
	Version() SnmpVersion
	PDU() PDU
	PduBytes() []byte
	SetPduBytes([]byte)
	Marshal() ([]byte, error)
	Unmarshal([]byte) ([]byte, error)
	String() string
}
snmp messsage v1 or v2

+----------------------------------+ | version | community | pdu | +----------------------------------+

                                                                     |<------------ ScopedPdu ---------->|
+--------------------------------------------------------------------------------------------------------+

snmpv3 message | version | RequestID | MaxSize | Flag | security | Security | context | context | PDU |

|          |           |          |        |   Model    | parameters | engineId |  name   |              |
+--------------------------------------------------------------------------------------------------------+

                                                                     +-----------------------------------+

ScopedPdu | context | context | PDU |

| engineId |  name   |              |
+-----------------------------------+

func NewMessage added in v1.1.0

func NewMessage(ver SnmpVersion, pdu PDU) (msg Message)

type MessageProcessing added in v1.1.0

type MessageProcessing interface {
	Security() Security
	PrepareOutgoingMessage(*SNMP, PDU) (Message, error)
	PrepareDataElements(*SNMP, Message, []byte) (PDU, error)
}

func NewMessageProcessing added in v1.1.0

func NewMessageProcessing(ver SnmpVersion) (mp MessageProcessing)

type MessageV1 added in v1.1.0

type MessageV1 struct {
	Community []byte
	// contains filtered or unexported fields
}

func (*MessageV1) Marshal added in v1.1.0

func (msg *MessageV1) Marshal() (b []byte, err error)

func (*MessageV1) PDU added in v1.1.0

func (msg *MessageV1) PDU() PDU

func (*MessageV1) PduBytes added in v1.1.0

func (msg *MessageV1) PduBytes() []byte

func (*MessageV1) SetPDU added in v1.1.0

func (msg *MessageV1) SetPDU(pdu PDU)

func (*MessageV1) SetPduBytes added in v1.1.0

func (msg *MessageV1) SetPduBytes(b []byte)

func (*MessageV1) String added in v1.1.0

func (msg *MessageV1) String() string

func (*MessageV1) Unmarshal added in v1.1.0

func (msg *MessageV1) Unmarshal(b []byte) (rest []byte, err error)

func (*MessageV1) Version added in v1.1.0

func (msg *MessageV1) Version() SnmpVersion

type MessageV3 added in v1.1.0

type MessageV3 struct {
	MessageV1
	// contains filtered or unexported fields
}
                                                                     |<------------ ScopedPdu ---------->|
+--------------------------------------------------------------------------------------------------------+

snmpv3 message | version | RequestID | MaxSize | Flag | security | Security | context | context | PDU |

|          |           |          |        |   Model    | parameters | engineId |  name   |              |
+--------------------------------------------------------------------------------------------------------+

                                                                     +-----------------------------------+

ScopedPdu | context | context | PDU |

                                                                                    | engineId |  name   |              |
                                                                                    +-----------------------------------+

                  SNMPv3 Packet Format

                -------------------------
  /|\           | msgVersion            |
   |            |-----------------------|
   |            | msgID                 |
   |            |-----------------------|         USM Security Parameters
   |            | msgMaxSize            |
   |            |-----------------------|    /-------------------------------
   |            | msgFlags              |   / | msgAuthoritativeEngineID    |
scope of        |-----------------------|  /  |-----------------------------|

authentication | msgSecurityModel | / | msgAuthoritativeEngineBoots |

 |            |-----------------------|/    |-----------------------------|
 |            |                       |     | msgAuthoritativeEngineTime  |
 |            | msgSecurityParameters |     |-----------------------------|
 |            |                       |     | msgUserName                 |
 |            |-----------------------|\    |-----------------------------|
 |     /|\    |                       | \   | msgAuthenticationParameters |
 |      |     |                       |  \  |-----------------------------|
 |      |     |                       |   \ | msgPrivacyParameters        |
 |  scope of  | scopedPDU             |    \-------------------------------
 | encryption |                       |
 |      |     |                       |
 |      |     |                       |
 |      |     |                       |
\|/    \|/    |                       |
              -------------------------

func (*MessageV3) Authentication added in v1.1.0

func (h *MessageV3) Authentication() bool

func (*MessageV3) Marshal added in v1.1.0

func (msg *MessageV3) Marshal() (b []byte, err error)

func (*MessageV3) Privacy added in v1.1.0

func (h *MessageV3) Privacy() bool

func (*MessageV3) Reportable added in v1.1.0

func (h *MessageV3) Reportable() bool

func (*MessageV3) SetAuthentication added in v1.1.0

func (h *MessageV3) SetAuthentication(b bool)

func (*MessageV3) SetPrivacy added in v1.1.0

func (h *MessageV3) SetPrivacy(b bool)

func (*MessageV3) SetReportable added in v1.1.0

func (h *MessageV3) SetReportable(b bool)

func (*MessageV3) String added in v1.1.0

func (msg *MessageV3) String() string

func (*MessageV3) Unmarshal added in v1.1.0

func (msg *MessageV3) Unmarshal(b []byte) (rest []byte, err error)

type NoSucheInstance

type NoSucheInstance struct {
	Null
}

func NewNoSucheInstance

func NewNoSucheInstance() *NoSucheInstance

func (*NoSucheInstance) Bytes added in v1.1.0

func (v *NoSucheInstance) Bytes() []byte

func (*NoSucheInstance) ErrorMessage added in v1.1.0

func (v *NoSucheInstance) ErrorMessage() string

func (*NoSucheInstance) IsError added in v1.1.0

func (v *NoSucheInstance) IsError() bool

func (*NoSucheInstance) Marshal

func (v *NoSucheInstance) Marshal() ([]byte, error)

func (*NoSucheInstance) MarshalJSON added in v1.1.0

func (v *NoSucheInstance) MarshalJSON() ([]byte, error)

func (*NoSucheInstance) String added in v1.1.0

func (v *NoSucheInstance) String() string

func (*NoSucheInstance) Syntex added in v1.1.0

func (v *NoSucheInstance) Syntex() int

func (*NoSucheInstance) Unmarshal

func (v *NoSucheInstance) Unmarshal(b []byte) (rest []byte, err error)

type NoSucheObject

type NoSucheObject struct {
	Null
}

func NewNoSucheObject

func NewNoSucheObject() *NoSucheObject

func (*NoSucheObject) Bytes added in v1.1.0

func (v *NoSucheObject) Bytes() []byte

func (*NoSucheObject) ErrorMessage added in v1.1.0

func (v *NoSucheObject) ErrorMessage() string

func (*NoSucheObject) IsError added in v1.1.0

func (v *NoSucheObject) IsError() bool

func (*NoSucheObject) Marshal

func (v *NoSucheObject) Marshal() ([]byte, error)

func (*NoSucheObject) MarshalJSON added in v1.1.0

func (v *NoSucheObject) MarshalJSON() ([]byte, error)

func (*NoSucheObject) String added in v1.1.0

func (v *NoSucheObject) String() string

func (*NoSucheObject) Syntex added in v1.1.0

func (v *NoSucheObject) Syntex() int

func (*NoSucheObject) Unmarshal

func (v *NoSucheObject) Unmarshal(b []byte) (rest []byte, err error)

type Null

type Null struct{}

func NewNull

func NewNull() *Null

func (*Null) Bytes added in v1.1.0

func (v *Null) Bytes() []byte

func (*Null) ErrorMessage added in v1.1.0

func (v *Null) ErrorMessage() string

func (*Null) Int added in v1.1.0

func (v *Null) Int() int64

func (*Null) IsError added in v1.1.0

func (v *Null) IsError() bool

func (*Null) Marshal

func (v *Null) Marshal() ([]byte, error)

func (*Null) MarshalJSON added in v1.1.0

func (v *Null) MarshalJSON() ([]byte, error)

func (*Null) String

func (v *Null) String() string

func (*Null) Syntex added in v1.1.0

func (v *Null) Syntex() int

func (*Null) ToString added in v1.1.0

func (v *Null) ToString() string

func (*Null) Uint added in v1.1.0

func (v *Null) Uint() uint64

func (*Null) Unmarshal

func (v *Null) Unmarshal(b []byte) (rest []byte, err error)

type OctetString

type OctetString struct {
	Value []byte
}

func NewOctetString

func NewOctetString(b []byte) *OctetString

func (*OctetString) Bytes added in v1.1.0

func (v *OctetString) Bytes() []byte

func (*OctetString) ErrorMessage added in v1.1.0

func (v *OctetString) ErrorMessage() string

func (*OctetString) Int added in v1.1.0

func (v *OctetString) Int() int64

func (*OctetString) IsError added in v1.1.0

func (v *OctetString) IsError() bool

func (*OctetString) Marshal

func (v *OctetString) Marshal() ([]byte, error)

func (*OctetString) MarshalJSON added in v1.1.0

func (v *OctetString) MarshalJSON() ([]byte, error)

func (*OctetString) String

func (v *OctetString) String() string

func (*OctetString) Syntex added in v1.1.0

func (v *OctetString) Syntex() int

func (*OctetString) ToString added in v1.1.0

func (v *OctetString) ToString() string

func (*OctetString) Uint added in v1.1.0

func (v *OctetString) Uint() uint64

func (*OctetString) Unmarshal

func (v *OctetString) Unmarshal(b []byte) (rest []byte, err error)

type Oid

type Oid struct {
	Value []int
}
var EmptyOID Oid

func ConcatOidString added in v1.1.0

func ConcatOidString(oid Oid, s string) Oid

func MustParseOidFromString added in v1.1.0

func MustParseOidFromString(s string) Oid

MustNewOid is like NewOid but panics if argument cannot be parsed

func NewOid

func NewOid(oid []int) Oid

func ParseOidFromString added in v1.1.0

func ParseOidFromString(s string) (Oid, error)

func (*Oid) AppendSubIds

func (v *Oid) AppendSubIds(subs []int) Oid

Returns Oid with additional sub-ids

func (*Oid) Bytes added in v1.1.0

func (v *Oid) Bytes() []byte

func (*Oid) Compare

func (v *Oid) Compare(o *Oid) int

Returns 0 this OID is equal to the specified OID, -1 this OID is lexicographically less than the specified OID, 1 this OID is lexicographically greater than the specified OID

func (*Oid) Contains

func (v *Oid) Contains(o *Oid) bool

Returns true if this OID contains the specified OID

func (*Oid) Equal

func (v *Oid) Equal(o *Oid) bool

Returns true if this OID is same the specified OID

func (*Oid) ErrorMessage added in v1.1.0

func (v *Oid) ErrorMessage() string

func (*Oid) Int added in v1.1.0

func (v *Oid) Int() int64

func (*Oid) IsError added in v1.1.0

func (v *Oid) IsError() bool

func (*Oid) Marshal

func (v *Oid) Marshal() ([]byte, error)

func (*Oid) MarshalJSON added in v1.1.0

func (v *Oid) MarshalJSON() ([]byte, error)

func (*Oid) String

func (v *Oid) String() string

func (*Oid) Syntex added in v1.1.0

func (v *Oid) Syntex() int

func (*Oid) ToString added in v1.1.0

func (v *Oid) ToString() string

func (*Oid) Uint added in v1.1.0

func (v *Oid) Uint() uint64

func (*Oid) Unmarshal

func (v *Oid) Unmarshal(b []byte) (rest []byte, err error)

type OidAndValue added in v1.1.0

type OidAndValue struct {
	Oid   Oid
	Value Variable
}

type Oids

type Oids []Oid

func NewOids

func NewOids(s []string) (oids Oids, err error)

func (Oids) Sort

func (o Oids) Sort() Oids

Sort a Oid list

func (Oids) Uniq

func (o Oids) Uniq() Oids

Filter out adjacent OID list

func (Oids) UniqBase

func (o Oids) UniqBase() Oids

Filter out adjacent OID list with the same prefix

type Opaque

type Opaque struct {
	OctetString
}

func NewOpaque

func NewOpaque(b []byte) *Opaque

func (*Opaque) Marshal

func (v *Opaque) Marshal() ([]byte, error)

func (*Opaque) MarshalJSON added in v1.1.0

func (v *Opaque) MarshalJSON() ([]byte, error)

func (*Opaque) String

func (v *Opaque) String() string

func (*Opaque) Syntex added in v1.1.0

func (v *Opaque) Syntex() int

func (*Opaque) ToString added in v1.1.0

func (v *Opaque) ToString() string

func (*Opaque) Unmarshal

func (v *Opaque) Unmarshal(b []byte) (rest []byte, err error)

type PDU added in v1.1.0

type PDU interface {
	PduType() PduType
	RequestId() int
	SetRequestId(int)
	ErrorStatus() ErrorStatus
	SetErrorStatus(ErrorStatus)
	ErrorIndex() int
	SetErrorIndex(int)
	SetNonrepeaters(int)
	SetMaxRepetitions(int)
	AppendVariableBinding(Oid, Variable)
	VariableBindings() VariableBindings
	Marshal() ([]byte, error)
	Unmarshal([]byte) (rest []byte, err error)
	String() string
}

The protocol data unit of SNMP The PduV1 is used by SNMP V1 and V2c, other than the SNMP V1 Trap

trap pdu +------------+--------------+------------+----------------+---------------+-------------+---------------------+ | PDU Type | enterprise | agent addr | generic trap | specific trap | time stamp | variable bindings | +------------+--------------+------------+----------------+---------------+-------------+---------------------+

reponse pdu +------------+--------------+----------------+---------------+----------------------+ | PDU Type | request id | error status | error index | variable bindings | +------------+--------------+----------------+---------------+----------------------+

request pdu +------------+--------------+----------------+---------------+----------------------+ | PDU Type | request id | 0 | 0 | variable bindings | +------------+--------------+----------------+---------------+----------------------+

func NewPdu

func NewPdu(ver SnmpVersion, t PduType) (pdu PDU)

func NewPduWithOids

func NewPduWithOids(ver SnmpVersion, t PduType, oids Oids) (pdu PDU)

func NewPduWithVarBinds

func NewPduWithVarBinds(ver SnmpVersion, t PduType, VariableBindings VariableBindings) (pdu PDU)

type PduType

type PduType int
const (
	GetRequest PduType = iota
	GetNextRequest
	GetResponse
	SetRequest
	Trap
	GetBulkRequest
	InformRequest
	SNMPTrapV2
	Report
)

func (PduType) String

func (t PduType) String() string

type PduV1

type PduV1 struct {
	Enterprise   Oid
	AgentAddress Ipaddress
	GenericTrap  int
	SpecificTrap int
	Timestamp    int
	// contains filtered or unexported fields
}

The PduV1 is used by SNMP V1 and V2c, other than the SNMP V1 Trap

func (*PduV1) AppendVariableBinding added in v1.1.0

func (pdu *PduV1) AppendVariableBinding(oid Oid, variable Variable)

func (*PduV1) ErrorIndex

func (pdu *PduV1) ErrorIndex() int

func (*PduV1) ErrorStatus

func (pdu *PduV1) ErrorStatus() ErrorStatus

func (*PduV1) Marshal

func (pdu *PduV1) Marshal() (b []byte, err error)

func (*PduV1) PduType

func (pdu *PduV1) PduType() PduType

func (*PduV1) RequestId

func (pdu *PduV1) RequestId() int

func (*PduV1) SetErrorIndex

func (pdu *PduV1) SetErrorIndex(i int)

func (*PduV1) SetErrorStatus

func (pdu *PduV1) SetErrorStatus(i ErrorStatus)

func (*PduV1) SetMaxRepetitions

func (pdu *PduV1) SetMaxRepetitions(i int)

func (*PduV1) SetNonrepeaters

func (pdu *PduV1) SetNonrepeaters(i int)

func (*PduV1) SetRequestId

func (pdu *PduV1) SetRequestId(i int)

func (*PduV1) String

func (pdu *PduV1) String() string

func (*PduV1) Unmarshal

func (pdu *PduV1) Unmarshal(b []byte) (rest []byte, err error)

func (*PduV1) VariableBindings added in v1.1.0

func (pdu *PduV1) VariableBindings() VariableBindings

type PingResult added in v1.1.0

type PingResult struct {
	Id        int
	Addr      net.Addr
	Version   SnmpVersion
	Community string
	Username  string
	Error     error
	Timestamp time.Time
}

type Pinger added in v1.1.0

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

func NewPinger added in v1.1.0

func NewPinger(network, laddr string, capacity int) (*Pinger, error)

func (*Pinger) Close added in v1.1.0

func (self *Pinger) Close()

func (*Pinger) GetChannel added in v1.1.0

func (self *Pinger) GetChannel() <-chan *PingResult

func (*Pinger) Recv added in v1.1.0

func (self *Pinger) Recv(timeout time.Duration) (net.Addr, SnmpVersion, error)

func (*Pinger) Send added in v1.1.0

func (self *Pinger) Send(id int, ra *net.UDPAddr, args *Arguments) error

func (*Pinger) SendV2 added in v1.1.0

func (self *Pinger) SendV2(id int, ra *net.UDPAddr, version SnmpVersion, community string) error

func (*Pinger) SendV2With added in v1.1.0

func (self *Pinger) SendV2With(id int, raddr string, version SnmpVersion, community string) error

func (*Pinger) SendV3 added in v1.1.0

func (self *Pinger) SendV3(id int, raddr, username string) error

type Pingers added in v1.1.0

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

func NewPingers added in v1.1.0

func NewPingers(capacity int) *Pingers

func (*Pingers) Close added in v1.1.0

func (self *Pingers) Close()

func (*Pingers) GetChannel added in v1.1.0

func (self *Pingers) GetChannel() <-chan *PingResult

func (*Pingers) Length added in v1.1.0

func (self *Pingers) Length() int

func (*Pingers) Listen added in v1.1.0

func (self *Pingers) Listen(network, laddr string, version SnmpVersion, community string) error

func (*Pingers) ListenV3 added in v1.1.0

func (self *Pingers) ListenV3(network, laddr, userName string) error

func (*Pingers) Recv added in v1.1.0

func (self *Pingers) Recv(timeout time.Duration) (net.Addr, SnmpVersion, error)

func (*Pingers) Send added in v1.1.0

func (self *Pingers) Send(idx int, raddr string) error

func (*Pingers) SendWith added in v1.1.0

func (self *Pingers) SendWith(idx int, raddr *net.UDPAddr) error

type PrivProtocol

type PrivProtocol string
const (
	Des PrivProtocol = "DES"
	Aes PrivProtocol = "AES"
)

func ParsePrivProtocol added in v1.1.0

func ParsePrivProtocol(s string) (PrivProtocol, error)

type ResponseError

type ResponseError struct {
	Cause   error  // Cause of the error
	Message string // Error message
	Detail  string // Detail of the error for debugging
}

A ResponseError suggests that the response from the remote agent is wrong or is not obtained

func (ResponseError) Error

func (e ResponseError) Error() string

type SNMP

type SNMP struct {
	Network string
	Address string
	// contains filtered or unexported fields
}

SNMP Object provides functions for the SNMP Client

func NewSNMP

func NewSNMP(network, address string, args Arguments) (*SNMP, error)

Create a SNMP Object

func (*SNMP) Close

func (s *SNMP) Close()

Close a connection

func (*SNMP) GetBulkRequest

func (s *SNMP) GetBulkRequest(oids Oids, nonRepeaters, maxRepetitions int) (result PDU, err error)

func (*SNMP) GetBulkWalk

func (s *SNMP) GetBulkWalk(oids Oids, nonRepeaters, maxRepetitions int) (result PDU, err error)

This method inquire about OID subtrees by repeatedly using GetBulkRequest. Returned PDU contains the VariableBinding list of all subtrees. however, if the ErrorStatus of PDU is not the NoError, return only the last query result.

func (*SNMP) GetNextRequest

func (s *SNMP) GetNextRequest(oids Oids) (result PDU, err error)

func (*SNMP) GetRequest

func (s *SNMP) GetRequest(oids Oids) (result PDU, err error)

func (*SNMP) InformRequest

func (s *SNMP) InformRequest(VariableBindings VariableBindings) error

func (*SNMP) Open

func (s *SNMP) Open() (err error)

Open a connection

func (*SNMP) SetRequest added in v1.1.0

func (s *SNMP) SetRequest(variableBindings VariableBindings) (result PDU, err error)

func (*SNMP) String

func (s *SNMP) String() string

func (*SNMP) V1Trap added in v1.1.0

func (s *SNMP) V1Trap(enterprise Oid, agentAddress Ipaddress, genericTrap int,
	specificTrap int, VariableBindings VariableBindings) error

func (*SNMP) V2Trap

func (s *SNMP) V2Trap(VariableBindings VariableBindings) error

type ScopedPdu

type ScopedPdu struct {
	ContextEngineId []byte
	ContextName     []byte
	PduV1
}

The ScopedPdu is used by SNMP V3. Includes the PduV1, and contains a SNMP context parameter

func (*ScopedPdu) Marshal

func (pdu *ScopedPdu) Marshal() (b []byte, err error)

func (*ScopedPdu) String

func (pdu *ScopedPdu) String() string

func (*ScopedPdu) Unmarshal

func (pdu *ScopedPdu) Unmarshal(b []byte) (rest []byte, err error)

type Security added in v1.1.0

type Security interface {
	GenerateRequestMessage(*Arguments, Message) error
	ProcessIncomingMessage(*Arguments, Message) error
	//Discover(*Arguments) error
	String() string
}

func NewCommunity added in v1.1.0

func NewCommunity() Security

func NewUsm added in v1.1.0

func NewUsm() Security

type SecurityLevel

type SecurityLevel int
const (
	NoAuthNoPriv SecurityLevel = iota
	AuthNoPriv
	AuthPriv
)

func ParseSecurityLevel added in v1.1.0

func ParseSecurityLevel(s string) (SecurityLevel, error)

func (SecurityLevel) String

func (s SecurityLevel) String() string

type SnmpVersion added in v1.1.0

type SnmpVersion int
const (
	V1  SnmpVersion = 0
	V2c SnmpVersion = 1
	V3  SnmpVersion = 3
)

func ParseVersion added in v1.1.0

func ParseVersion(v string) (SnmpVersion, error)

func (SnmpVersion) String added in v1.1.0

func (s SnmpVersion) String() string

func (SnmpVersion) ToString added in v1.1.0

func (s SnmpVersion) ToString() string

type TimeTicks

type TimeTicks struct {
	Counter32
}

func NewTimeTicks

func NewTimeTicks(i uint32) *TimeTicks

func (*TimeTicks) Marshal

func (v *TimeTicks) Marshal() ([]byte, error)

func (*TimeTicks) MarshalJSON added in v1.1.0

func (v *TimeTicks) MarshalJSON() ([]byte, error)

func (*TimeTicks) String added in v1.1.0

func (v *TimeTicks) String() string

func (*TimeTicks) Syntex added in v1.1.0

func (v *TimeTicks) Syntex() int

func (*TimeTicks) Unmarshal

func (v *TimeTicks) Unmarshal(b []byte) (rest []byte, err error)

type Tree added in v1.1.0

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

func NewMibTree added in v1.1.0

func NewMibTree() *Tree

func NewTree added in v1.1.0

func NewTree(compare CompareFunc) *Tree

Create a new empty tree.

func (*Tree) DeleteWithIterator added in v1.1.0

func (root *Tree) DeleteWithIterator(iter Iterator)

Delete the current item.

REQUIRES: !iter.Limit() && !iter.NegativeLimit()

func (*Tree) DeleteWithKey added in v1.1.0

func (root *Tree) DeleteWithKey(key Item) bool

Delete an item with the given key. Return true iff the item was found.

func (*Tree) FindGE added in v1.1.0

func (root *Tree) FindGE(key Item) Iterator

Find the smallest element N such that N >= key, and return the iterator pointing to the element. If no such element is found, return root.Limit().

func (*Tree) FindLE added in v1.1.0

func (root *Tree) FindLE(key Item) Iterator

Find the largest element N such that N <= key, and return the iterator pointing to the element. If no such element is found, return iter.NegativeLimit().

func (*Tree) Get added in v1.1.0

func (root *Tree) Get(key Item) Item

A convenience function for finding an element equal to key. Return nil if not found.

func (*Tree) Insert added in v1.1.0

func (root *Tree) Insert(item Item) bool

Insert an item. If the item is already in the tree, do nothing and return false. Else return true.

func (*Tree) Len added in v1.1.0

func (root *Tree) Len() int

Return the number of elements in the tree.

func (*Tree) Limit added in v1.1.0

func (root *Tree) Limit() Iterator

Create an iterator that points beyond the maximum item in the tree

func (*Tree) Max added in v1.1.0

func (root *Tree) Max() Iterator

Create an iterator that points at the maximum item in the tree

If the tree is empty, return NegativeLimit()

func (*Tree) Min added in v1.1.0

func (root *Tree) Min() Iterator

Create an iterator that points to the minimum item in the tree If the tree is empty, return Limit()

func (*Tree) NegativeLimit added in v1.1.0

func (root *Tree) NegativeLimit() Iterator

Create an iterator that points before the minimum item in the tree

type USM added in v1.1.0

type USM struct {
	//DiscoveryStatus DiscoveryStatus
	AuthEngineId    []byte
	AuthEngineBoots int64
	AuthEngineTime  int64
	// AuthKey         []byte
	// PrivKey         []byte
	UpdatedTime time.Time
}

func (*USM) CheckTimeliness added in v1.1.0

func (u *USM) CheckTimeliness(engineBoots, engineTime int64) error

func (*USM) GenerateRequestMessage added in v1.1.0

func (u *USM) GenerateRequestMessage(args *Arguments, sendMsg Message) (err error)

func (*USM) IsDiscover added in v1.1.0

func (u *USM) IsDiscover() bool

func (*USM) ProcessIncomingMessage added in v1.1.0

func (u *USM) ProcessIncomingMessage(args *Arguments, recvMsg Message) (err error)

func (*USM) String added in v1.1.0

func (u *USM) String() string

func (*USM) SynchronizeEngineBootsTime added in v1.1.0

func (u *USM) SynchronizeEngineBootsTime(engineBoots, engineTime int64)

func (*USM) UpdateEngineBootsTime added in v1.1.0

func (u *USM) UpdateEngineBootsTime() error

type UdpServer added in v1.1.0

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

******************************************

It is for test.

func NewUdpServerFromFile added in v1.1.0

func NewUdpServerFromFile(nm, addr, file string, is_update_mibs bool) (*UdpServer, error)

func NewUdpServerFromString added in v1.1.0

func NewUdpServerFromString(nm, addr, mibs string, is_update_mibs bool) (*UdpServer, error)

func (*UdpServer) Close added in v1.1.0

func (self *UdpServer) Close() error

func (*UdpServer) GetIntPort added in v1.2.0

func (self *UdpServer) GetIntPort() int

func (*UdpServer) GetNextValueByOid added in v1.1.0

func (self *UdpServer) GetNextValueByOid(mibs *Tree, oid Oid) (*Oid, Variable)

func (*UdpServer) GetPort added in v1.1.0

func (self *UdpServer) GetPort() string

func (*UdpServer) GetValueByOid added in v1.1.0

func (self *UdpServer) GetValueByOid(mibs *Tree, oid Oid) Variable

func (*UdpServer) LoadFile added in v1.1.0

func (self *UdpServer) LoadFile(file string) error

func (*UdpServer) LoadFileTo added in v1.1.0

func (self *UdpServer) LoadFileTo(engineID, filename string, isReset bool) error

func (*UdpServer) LoadMibsFromString added in v1.1.0

func (self *UdpServer) LoadMibsFromString(mibs string) error

func (*UdpServer) LoadMibsIntoEngine added in v1.1.0

func (self *UdpServer) LoadMibsIntoEngine(engineID string, rd io.Reader, isReset bool) error

func (*UdpServer) Pause added in v1.1.0

func (self *UdpServer) Pause() error

func (*UdpServer) ReloadMibsFromFile added in v1.1.0

func (self *UdpServer) ReloadMibsFromFile(file string) error

func (*UdpServer) ReloadMibsFromString added in v1.1.0

func (self *UdpServer) ReloadMibsFromString(mibs string) error

func (*UdpServer) Restart added in v1.1.0

func (self *UdpServer) Restart() error

func (*UdpServer) Resume added in v1.1.0

func (self *UdpServer) Resume() error

func (*UdpServer) ReturnErrorIfOidNotExists added in v1.1.0

func (self *UdpServer) ReturnErrorIfOidNotExists(status bool) *UdpServer

func (*UdpServer) SetCommunity added in v1.1.0

func (self *UdpServer) SetCommunity(community string)

func (*UdpServer) SetMiss added in v1.1.0

func (self *UdpServer) SetMiss(miss int)

type Variable

type Variable interface {
	Int() int64
	Uint() uint64
	Bytes() []byte
	// Return a string representation of this Variable
	ToString() string
	String() string

	IsError() bool
	ErrorMessage() string

	// Return a string of type
	Syntex() int
	Marshal() ([]byte, error)
	Unmarshal([]byte) (rest []byte, err error)
}

func NewCounter32FromString added in v1.1.0

func NewCounter32FromString(s string) (Variable, error)

func NewCounter64FromString added in v1.1.0

func NewCounter64FromString(s string) (Variable, error)

func NewGauge32FromString added in v1.1.0

func NewGauge32FromString(s string) (Variable, error)

func NewIPAddressFromString added in v1.1.0

func NewIPAddressFromString(s string) (Variable, error)

func NewIntegerFromString added in v1.1.0

func NewIntegerFromString(s string) (Variable, error)

func NewOctetStringFromString added in v1.1.0

func NewOctetStringFromString(s string) (Variable, error)

func NewOidFromString added in v1.1.0

func NewOidFromString(s string) (Variable, error)

func NewOpaqueFromString added in v1.1.0

func NewOpaqueFromString(s string) (Variable, error)

func NewTimeticksFromString added in v1.1.0

func NewTimeticksFromString(s string) (Variable, error)

func NewVariable added in v1.1.0

func NewVariable(s string) (Variable, error)

func ParseHexString added in v1.1.0

func ParseHexString(ss []string, is_end bool, vs string) (Variable, []string, error)

func ParseString added in v1.1.0

func ParseString(ss []string, is_end bool, vs string) (Variable, []string, error)

type VariableBinding added in v1.1.0

type VariableBinding struct {
	Oid      Oid
	Variable Variable
}

func NewVarBind

func NewVarBind(oid Oid, val Variable) VariableBinding

func (*VariableBinding) Marshal added in v1.1.0

func (v *VariableBinding) Marshal() (b []byte, err error)

func (*VariableBinding) String added in v1.1.0

func (v *VariableBinding) String() string

func (*VariableBinding) Unmarshal added in v1.1.0

func (v *VariableBinding) Unmarshal(b []byte) (rest []byte, err error)

type VariableBindings added in v1.1.0

type VariableBindings []VariableBinding

func (VariableBindings) MatchBaseOids added in v1.1.0

func (v VariableBindings) MatchBaseOids(prefix Oid) VariableBindings

Gets a VariableBinding list that matches the prefix

func (VariableBindings) MatchOid added in v1.1.0

func (v VariableBindings) MatchOid(oid Oid) *VariableBinding

Gets a VariableBinding that matches

func (VariableBindings) Sort added in v1.1.0

Sort a VariableBinding list by OID

func (VariableBindings) String added in v1.1.0

func (v VariableBindings) String() string

func (VariableBindings) Uniq added in v1.1.0

Filter out adjacent VariableBinding list

Directories

Path Synopsis
Package asn1 implements parsing of DER-encoded ASN.1 data structures, as defined in ITU-T Rec X.690.
Package asn1 implements parsing of DER-encoded ASN.1 data structures, as defined in ITU-T Rec X.690.
cmd

Jump to

Keyboard shortcuts

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