Back to godoc.org
bosun.org / snmp

Package snmp

v0.0.0-...-8a7cd2d
Latest Go to latest

The latest major version is .

Published: Jun 18, 2020 | License: MIT | Module: bosun.org

Overview

Package snmp provides an implementation of the SNMP specification.

Index

Variables

var Timeout = 30

Timeout is the number of seconds to use for conn.SetReadDeadline

func Get

func Get(host, community string, nameval ...interface{}) error

Get is a wrapper for SNMP.Get.

type Rows

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

Rows is the result of a walk. Its cursor starts before the first row of the result set. Use Next to advance through the rows:

rows, err := snmp.Walk(host, community, "ifName")
...
for rows.Next() {
    var name []byte
    err = rows.Scan(&name)
    ...
}
err = rows.Err() // get any error encountered during iteration
...

func Walk

func Walk(host, community string, oids ...string) (*Rows, error)

Walk is a wrapper for SNMP.Walk.

func (*Rows) Err

func (rows *Rows) Err() error

Err returns the error, if any, that was encountered during iteration.

func (*Rows) Next

func (rows *Rows) Next() bool

Next prepares the next result row for reading with the Scan method. It returns true on success, false if there is no next result row. Every call to Scan, even the first one, must be preceded by a call to Next.

func (*Rows) Scan

func (rows *Rows) Scan(v ...interface{}) (id interface{}, err error)

Scan copies the columns in the current row into the values pointed at by v. On success, the id return variable will hold the row id of the current row. It is typically an integer or a string.

type SNMP

type SNMP struct {
	// Community is the SNMP community.
	Community string
	// Addr is the UDP address of the SNMP host.
	Addr *net.UDPAddr
}

SNMP performs SNMPv2 requests as defined by RFC 3416.

func New

func New(host, community string) (*SNMP, error)

New creates a new SNMP which connects to host with specified community.

func (*SNMP) Get

func (s *SNMP) Get(nameval ...interface{}) error

Get retrieves an object by its name. Nameval is a pair of: object name or OID (string), and the corresponding target value (pointer to int, string, etc.). To retrieve multiple objects in a single transaction, provide multiple name, value pairs.

func (*SNMP) Walk

func (s *SNMP) Walk(oids ...string) (*Rows, error)

Walk executes a query against host authenticated by the community string, retrieving the MIB sub-tree defined by the the given root oids.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier