snmpparse

package
v0.0.0-...-593c137 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package snmpparse extracts SNMP configurations from agent config data.

Index

Constants

View Source
const (
	// DefaultPort is the standard SNMP port
	DefaultPort = 161
	// DefaultCommunityString is the default on most v2 implementations
	DefaultCommunityString = "public"
)

Variables

View Source
var AuthOpts = NewOptions(OptPairs[gosnmp.SnmpV3AuthProtocol]{
	{"", gosnmp.NoAuth},
	{"MD5", gosnmp.MD5},
	{"SHA", gosnmp.SHA},
	{"SHA224", gosnmp.SHA224},
	{"SHA256", gosnmp.SHA256},
	{"SHA384", gosnmp.SHA384},
	{"SHA512", gosnmp.SHA512},
})

AuthOpts maps string names to gosnmp auth protocols

View Source
var LevelOpts = NewOptions(OptPairs[gosnmp.SnmpV3MsgFlags]{
	{"noAuthNoPriv", gosnmp.NoAuthNoPriv},
	{"authNoPriv", gosnmp.AuthNoPriv},
	{"authPriv", gosnmp.AuthPriv},
})

LevelOpts maps string names to gosnmp auth levels

View Source
var PrivOpts = NewOptions(OptPairs[gosnmp.SnmpV3PrivProtocol]{
	{"", gosnmp.NoPriv},
	{"DES", gosnmp.DES},
	{"AES", gosnmp.AES},
	{"AES192", gosnmp.AES192},
	{"AES192C", gosnmp.AES192C},
	{"AES256", gosnmp.AES256},
	{"AES256C", gosnmp.AES256C},
})

PrivOpts maps string names to gosnmp privacy protocols

View Source
var VersionOpts = NewOptions(OptPairs[gosnmp.SnmpVersion]{
	{"1", gosnmp.Version1},
	{"2c", gosnmp.Version2c},
	{"3", gosnmp.Version3},
})

VersionOpts maps string names to gosnmp versions

Functions

func NewSNMP

func NewSNMP(conf *SNMPConfig, logger log.Component) (*gosnmp.GoSNMP, error)

NewSNMP validates an SNMPConfig and builds a GoSNMP from it.

func SetDefault

func SetDefault(sc *SNMPConfig)

SetDefault sets the standard default config values

Types

type OptPairs

type OptPairs[T any] []struct {
	Key string
	Val T
}

OptPairs is just a useful type alias to avoid writing this out multiple times.

type Options

type Options[T any] struct {
	Options map[string]T
	Order   []string
}

Options represents an ordered map of case-insensitive choices. This is particularly useful for generating sensible error messages and command-line documentation.

func NewOptions

func NewOptions[T any](pairs OptPairs[T]) Options[T]

NewOptions creates a new Options object from a slice of pairs. We don't just create one directly from a map because map iteration order is random.

func (Options[T]) GetOpt

func (o Options[T]) GetOpt(choice string) (string, bool)

GetOpt returns the key that matches choice, case-insensitively. The key is found case-insensitively; the returned value will be the key as defined in the original list.

func (Options[T]) GetVal

func (o Options[T]) GetVal(choice string) (T, bool)

GetVal returns the value whose key matches choice, case-insensitively.

func (Options[T]) OptsStr

func (o Options[T]) OptsStr() string

OptsStr provides a '|'-delimited list of all nonempty options.

type SNMPConfig

type SNMPConfig struct {

	// General
	IPAddress string `yaml:"ip_address"`
	Port      uint16 `yaml:"port"`
	Version   string `yaml:"snmp_version"`
	Timeout   int    `yaml:"timeout"`
	Retries   int    `yaml:"retries"`
	// v1 &2
	CommunityString string `yaml:"community_string"`
	// v3
	Username     string `yaml:"user"`
	AuthProtocol string `yaml:"authProtocol"`
	AuthKey      string `yaml:"authKey"`
	PrivProtocol string `yaml:"privProtocol"`
	PrivKey      string `yaml:"privKey"`
	Context      string `yaml:"context_name"`
	// network
	NetAddress string `yaml:"network_address"`
	// These are omitted from the yaml because we don't let users configure
	// them, but there are cases where we use them (e.g. the snmpwalk command)
	SecurityLevel           string `yaml:"-"`
	UseUnconnectedUDPSocket bool   `yaml:"-"`
}

SNMPConfig is a generic container for configuration data specific to the SNMP integration.

func GetConfigCheckSnmp

func GetConfigCheckSnmp(conf config.Component) ([]SNMPConfig, error)

GetConfigCheckSnmp returns each SNMPConfig for all running config checks, by querying the local agent. If the agent isn't running or is unreachable, this will fail.

func GetIPConfig

func GetIPConfig(ipAddress string, SnmpConfigList []SNMPConfig) SNMPConfig

GetIPConfig finds the SNMPConfig for a specific IP address. If the IP is explicitly configured, that will be returned; if it isn't, but it is part of a configured subnet, then the subnet config will be returned. If there are no matches, this will return an empty SNMPConfig.

func ParseConfigSnmp

func ParseConfigSnmp(c integration.Config) []SNMPConfig

ParseConfigSnmp extracts all SNMPConfigs from an autodiscovery config. Any loading errors are logged but not returned.

Jump to

Keyboard shortcuts

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