core

package
v0.0.0-...-5607193 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAuthProtocol = errors.New("unsupported SNMP auth protocol specified")
	ErrInvalidPrivProtocol = errors.New("unsupported SNMP privacy protocol specified")
	ErrInvalidSNMPVersion  = errors.New("invalid SNMP version specified")
	ErrInvalidMessageFlag  = errors.New("invalid security message flag specified")
)

Errors for utility functions, largely around parsing SNMP configurations.

View Source
var (
	ErrNonV3SecurityParams = errors.New("cannot define security parameters for SNMP versions other than v3")
)

Errors relating to SNMP plugin client creation and usage.

Functions

func BytesIfaceToASCII

func BytesIfaceToASCII(b interface{}) (string, error)

BytesIfaceToASCII converts an interface, which should resolve to a byte array, to a (printable) ASCII string, if possible. This is needed since there is no differentiation between strings and byte arrays in the SNMP protocol.

If a call to this function fails, the caller should just keep the raw byte array.

This function makes no attempt to support extended (8-bit) ASCII.

func GetAuthProtocol

func GetAuthProtocol(s string) (gosnmp.SnmpV3AuthProtocol, error)

GetAuthProtocol gets the SNMP v3 authentication protocol constant corresponding to the given string.

func GetPrivProtocol

func GetPrivProtocol(s string) (gosnmp.SnmpV3PrivProtocol, error)

GetPrivProtocol gets the SNMP v3 privacy protocol constant corresponding to the given string.

func GetSNMPVersion

func GetSNMPVersion(s string) (gosnmp.SnmpVersion, error)

GetSNMPVersion gets the version of SNMP corresponding to the given string.

func GetSecurityFlags

func GetSecurityFlags(s string) (gosnmp.SnmpV3MsgFlags, error)

GetSecurityFlags gets the SNMP v3 security message flags constant corresponding to the given string.

func TagOrPanic

func TagOrPanic(tag string) *sdk.Tag

TagOrPanic is a utility function which creates a new SDK Tag or it panics.

This is useful when you know the format of the tag is correct ahead of time and you which skip the error check.

Types

type Client

type Client struct {
	*gosnmp.GoSNMP
	// contains filtered or unexported fields
}

Client is a wrapper around a GoSNMP struct which adds some utility functions around it. Notably, it enables lazy connecting to the client, so the SNMP agent does not need to be reachable at plugin startup.

func NewClient

func NewClient(cfg *SnmpTargetConfiguration) (*Client, error)

NewClient creates a new instance of an SNMP Client for the given SNMP target configuration. The SNMP target configuration is defined in the dynamic configuration block for the plugin.

func (*Client) Close

func (c *Client) Close()

Close the client connection.

func (*Client) GetOid

func (c *Client) GetOid(oid string) (*gosnmp.SnmpPDU, error)

GetOid gets the value for a specified OID.

func (*Client) GetSupportedDevices

func (c *Client) GetSupportedDevices(rootOid string) (map[string]struct{}, error)

GetSupportedDevices gets all the OIDs for devices found on the target. This may not always be the full set of devices that a MIB defines.

This returns a map of OIDs to empty struct. This map should be used during device creation to filter the MIB to only register those devices that a target supports. It is returned as a map to make OID lookups easier than iterating over a slice. Presence in the map means the device is supported, absence means it is not.

type SnmpTargetConfiguration

type SnmpTargetConfiguration struct {
	MIB       string          `yaml:"mib,omitempty"`
	Version   string          `yaml:"version,omitempty"`
	Agent     string          `yaml:"agent,omitempty"`
	Community string          `yaml:"community,omitempty"`
	Timeout   time.Duration   `yaml:"timeout,omitempty"`
	Retries   int             `yaml:"retries,omitempty"`
	Security  *SnmpV3Security `yaml:"security,omitempty"`
}

SnmpTargetConfiguration defines the configuration for individual SNMP servers, which are defined in the plugin config's dynamicRegistration block.

func LoadTargetConfiguration

func LoadTargetConfiguration(raw map[string]interface{}) (*SnmpTargetConfiguration, error)

LoadTargetConfiguration loads a map of data, which should be read in from the plugin config's dynamicRegistration block, into an SnmpTargetConfiguration struct.

type SnmpV3Security

type SnmpV3Security struct {
	Level          string                        `yaml:"level,omitempty"`
	Context        string                        `yaml:"context,omitempty"`
	Username       string                        `yaml:"username,omitempty"`
	Authentication *SnmpV3SecurityAuthentication `yaml:"authentication,omitempty"`
	Privacy        *SnmpV3SecurityPrivacy        `yaml:"privacy,omitempty"`
}

SnmpV3Security defines the security configuration for the SNMP connection. Only v3 of the SNMP protocol supports these security parameters.

type SnmpV3SecurityAuthentication

type SnmpV3SecurityAuthentication struct {
	Protocol   string `yaml:"protocol,omitempty"`
	Passphrase string `yaml:"passphrase,omitempty"`
}

SnmpV3SecurityAuthentication defines the authentication parameters for SNMP v3 security, when auth is enabled.

type SnmpV3SecurityPrivacy

type SnmpV3SecurityPrivacy struct {
	Protocol   string `yaml:"protocol,omitempty"`
	Passphrase string `yaml:"passphrase,omitempty"`
}

SnmpV3SecurityPrivacy defines the privacy parameters for SNMP v3 security, when privacy is enabled.

Jump to

Keyboard shortcuts

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