Documentation
¶
Overview ¶
Package snmptrapreceiver listens for SNMP traps and informs and emits OpenTelemetry logs.
Index ¶
- func CommunityAllowed(allow []string, got string) bool
- func GoSNMPParams(cfg ListenConfig, log *slog.Logger) (*gosnmp.GoSNMP, error)
- func ListenChanged(old, new ListenConfig) bool
- func NewFactory() receiver.Factory
- func NormalizeOID(oid string) string
- func PDUKind(t gosnmp.PDUType) string
- type Config
- type DecodeOptions
- type GosmiTranslator
- type ListenConfig
- type Lookup
- type NoopTranslator
- type Record
- type Translator
- type V3Config
- type Varbind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommunityAllowed ¶
CommunityAllowed reports whether a v1/v2c community is accepted. An empty allowlist accepts every community.
func GoSNMPParams ¶
GoSNMPParams builds gosnmp listener parameters. v3 is optional; omit it for v1/v2c. When V3 is set the listener is v3-only.
func ListenChanged ¶
func ListenChanged(old, new ListenConfig) bool
ListenChanged reports whether the UDP bind / auth / MIB tree changed.
func NewFactory ¶
NewFactory creates a factory for the SNMP trap receiver.
Types ¶
type Config ¶
type Config struct {
// ListenAddress is the UDP host:port. Default 0.0.0.0:1620.
ListenAddress string `mapstructure:"listen_address"`
// Communities is a v1/v2c allowlist. Empty accepts every community.
Communities []string `mapstructure:"communities"`
// IncludeCommunity puts the community string on the log record.
IncludeCommunity bool `mapstructure:"include_community"`
// DropUndefined drops traps whose trap OID did not resolve via MIBs.
DropUndefined bool `mapstructure:"drop_undefined"`
// MIBPaths are directories of SMI/MIB files for optional gosmi enrichment.
MIBPaths []string `mapstructure:"mib_paths"`
// Attributes are extra log attributes stamped on every record.
Attributes map[string]string `mapstructure:"attributes"`
// V3 is an optional USM user. When set, the listener is v3-only.
V3 *V3Config `mapstructure:"v3"`
}
Config is the receiver config in the collector config.yaml.
type DecodeOptions ¶
type DecodeOptions struct {
IncludeCommunity bool
Translator Translator
}
DecodeOptions control optional fields on the record.
type GosmiTranslator ¶
type GosmiTranslator struct {
// contains filtered or unexported fields
}
GosmiTranslator looks up OIDs with gosmi. Init and module load are process-global.
type ListenConfig ¶
type ListenConfig struct {
ListenAddress string
Communities []string
IncludeCommunity bool
DropUndefined bool
MIBPaths []string
V3 *V3Config
}
ListenConfig is the UDP listener + USM settings shared by the OTel receiver.
type Record ¶
type Record struct {
Time time.Time `json:"time"`
Source string `json:"source"`
Version string `json:"version"`
PDUType string `json:"pdu_type"`
TrapOID string `json:"trap_oid"`
TrapName string `json:"trap_name,omitempty"`
MIB string `json:"mib,omitempty"`
Community string `json:"community,omitempty"`
EngineID string `json:"engine_id,omitempty"`
ContextName string `json:"context_name,omitempty"`
AgentAddress string `json:"agent_address,omitempty"`
Enterprise string `json:"enterprise,omitempty"`
GenericTrap *int `json:"generic_trap,omitempty"`
SpecificTrap *int `json:"specific_trap,omitempty"`
SysUpTime uint `json:"sys_up_time,omitempty"`
Varbinds []Varbind `json:"varbinds"`
}
Record is one trap or inform, ready to marshal as an OTel log body.
func Decode ¶
func Decode(packet *gosnmp.SnmpPacket, addr *net.UDPAddr, now time.Time, opts DecodeOptions) Record
Decode turns a gosnmp trap/inform packet into a Record.
func (Record) MarshalJSONLine ¶
MarshalJSONLine is compact JSON for the OTel log body.
type Translator ¶
Translator resolves OIDs to textual names. Misses must not be fatal.
func NewGosmiTranslator ¶
func NewGosmiTranslator(paths []string, log *slog.Logger) (Translator, error)
NewGosmiTranslator initializes gosmi (once) and loads modules from dirs. Load failures are logged and skipped. An empty path list returns NoopTranslator.
type V3Config ¶
type V3Config struct {
User string `mapstructure:"user"`
SecurityLevel string `mapstructure:"security_level"`
AuthProtocol string `mapstructure:"auth_protocol"`
AuthPassword string `mapstructure:"auth_password"`
PrivProtocol string `mapstructure:"priv_protocol"`
PrivPassword string `mapstructure:"priv_password"`
}
V3Config is a single USM user for SNMPv3 traps/informs.