snmputil

package module
v0.0.0-...-67d24ef Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2016 License: BSD-2-Clause Imports: 19 Imported by: 1

README

snmputil

GoDoc

snmputil is a library focused on managing bulk polling of SNMP devices

It supports:

  • SNMP versions 1, 2, 2c, 3
  • Bulk polling of tabular data
  • Regexp filtering by name of resulting data
  • Auto generating OID name lookup and processing (if net-snmp-utils is installed)
  • Auto conversion of INTEGER and BIT formats to their named types
  • Optional processing of counter data (deltas and differentials)
  • Overide column aliases with custom labels
  • Auto throttling of requests - never poll faster than device can respond

Documentation

Overview

Package snmputil provides helper routines for gosnmp

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugLogger

func DebugLogger(logger *log.Logger)

DebugLogger logs all SNMP debug data to the given logger

func LoadMIBs

func LoadMIBs(filename, mibs string) error

LoadMIBs loads saved mib data or creates it if the file does not exist

func OIDList

func OIDList(mib string, oids []string, w io.Writer) error

OIDList generates a list of OIDs and their details

func Octets

func Octets(in string) []int

Octets converts a string of octets into an array of ints

func Poller

func Poller(p Profile, c Criteria, s Sender, fn ErrFunc, l *log.Logger) error

Poller does a bulkwalk on the device specified in the Profile

func Quit

func Quit()

Quit exits all active Pollers

func Sampler

func Sampler(p Profile, c Criteria, s Sender) error

Sampler does a single bulkwalk on the device specified using the given Profile

Types

type Collector

type Collector struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Collector collects unique strings (OIDs)

func NewCollector

func NewCollector(mibs string) *Collector

NewCollector returns a Collector to inspect OIDs used

func (*Collector) List

func (c *Collector) List() []string

List returns a unique list of all OIDs seen

func (*Collector) Poll

func (c *Collector) Poll(p Profile, oid string) error

Poll actively collects OIDs from the SNMP device

type Criteria

type Criteria struct {
	OID     string            // OID can be dotted string or symbolic name
	Index   string            // OID of table index
	Tags    map[string]string // any additional tags to associate
	Aliases map[string]string // optional column aliases
	Rename  map[string]string // rename from key to value
	Regexps []string          // list of regular expressions to filter by name
	Keep    bool              // Keep matched names if true, discard matches if false
	OIDTag  bool              // add OID as a tag
	Suffix  bool              // save suffix portion of OID as tag["suffix"]
	Count   int               // how many times to poll for data (0 is forever)
	Freq    int               // how often to poll for data (in seconds)
	Refresh int               // how often to refresh column data (in seconds)
}

Criteria specifies what to query and what to keep

type ErrFunc

type ErrFunc func(error)

ErrFunc processes errors and may be nil if desired

type MibInfo

type MibInfo struct {
	Name        string
	OID         string
	Syntax      string
	Default     string
	Hint        string
	Index       string
	Units       string
	Access      string
	Augments    string
	Status      string
	Description string
}

MibInfo contains all the details of a MIB entry

type Profile

type Profile struct {
	Host, Community, Version string
	Port, Timeout, Retries   int
	// for SNMP v3
	SecLevel, AuthUser, AuthPass, AuthProto, PrivProto, PrivPass string
}

Profile contains the settings needed to establish an SNMP connection

type Recipe

type Recipe struct {
	Rename string // new name to give data (if set)
	Orig   bool   // send original data as well if set
	Rate   bool   // calculate rate instead of difference
}

Recipe describes how to "cook" the data

type Recipies

type Recipies map[string]Recipe

Recipies is a map of recipies to apply calculations to data

type Sender

type Sender func(string, map[string]string, interface{}, TimeStamp) error

Sender sends the interpreted PDU value to be saved or whathaveyou

func CalcSender

func CalcSender(sender Sender, cook Recipies) Sender

CalcSender returns a sender that optionally "cooks" the data It requires OIDTag to be true in the snmp criteria to track state

A example:

   r := snmp.Recipies{
	   "ifHCInOctets": {"OCTETS_PER_SECOND", true, true},
   }
   sender := snmp.SampleSender(hostname)
   sender = snmp.StripTags(sender, []string{"oid"})
   sender = snmp.CalcSender(sender, r)
   Bulkwalker(profile, criteria, freq, sender, nil, nil) error {

func DebugSender

func DebugSender(sender Sender, logger *log.Logger) (Sender, error)

DebugSender returns a Sender that prints out data sent to it

func IntegerSender

func IntegerSender(sender Sender) Sender

IntegerSender returns a sender that makes unsigned counters signed integers

func RegexpSender

func RegexpSender(sender Sender, regexps []string, keep bool) (Sender, error)

RegexpSender returns a Sender that filters results based on name

func SplitSender

func SplitSender(s1, s2 Sender) (Sender, error)

SplitSender returns a Sender that sends data to two senders

func StripSender

func StripSender(sender Sender, taglist []string) Sender

StripSender returns a sender that strips matching tags

type TimeStamp

type TimeStamp struct {
	Start, Stop time.Time
}

TimeStamp tracks execution time

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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