Documentation ¶
Index ¶
- Constants
- Variables
- func InitMIBTranslator(mibPath string) ([]string, error)
- func ParserWorker(i int, wg *sync.WaitGroup, parseChan <-chan []byte, ...)
- type AuthConfig
- type AuthType
- type Community
- type Config
- type Correlate
- type Header
- type Message
- type MessageCompiler
- type Metadata
- type Payload
- type PrivacyProtocol
- type User
- type Value
- type ValueDetail
- type ValueType
Constants ¶
View Source
const ( PidFilePath = "/var/run/snmptrapd/snmptrapd.pid" DefaultBufferSize = 64000 )
Variables ¶
View Source
var Functions = []expr.Option{ expr.Function( "SHA256", func(params ...any) (any, error) { p, err := json.Marshal(params, json.Deterministic(true)) if err != nil { return nil, err } h := sha256.New() h.Write(p) return hex.EncodeToString(h.Sum(nil)), nil }, new(func(...any) string), ), expr.Function( "MergeMap", func(params ...any) (any, error) { if val, err := prepareValues(params[0]); err != nil { return nil, err } else { res := make(map[string]any) for _, m := range val { for k, v := range m { res[k] = v } } return res, nil } }, new(func([]map[string]any) map[string]any), ), expr.Function( "OidValueAny", func(params ...any) (any, error) { if val, ok := params[0].([]Value); !ok { return nil, errors.Errorf( "unexpected error, invalid first param type %s", reflect.TypeOf(params[0]), ) } else { prefix, ok := params[1].(string) if !ok { return nil, errors.Errorf( "unexpected error, invalid second param type %s", reflect.TypeOf(params[1]), ) } valOid := getOidValue(val, prefix) return valOid, nil } }, new(func([]Value, string) any), ), expr.Function( "OidValueNumber", func(params ...any) (any, error) { if val, ok := params[0].([]Value); !ok { return nil, errors.Errorf( "unexpected error, invalid first param type %s", reflect.TypeOf(params[0]), ) } else { prefix, ok := params[1].(string) if !ok { return nil, errors.Errorf( "unexpected error, invalid second param type %s", reflect.TypeOf(params[1]), ) } tryCast, ok := params[2].(bool) if !ok { return nil, errors.Errorf( "unexpected error, invalid third param type %s", reflect.TypeOf(params[2]), ) } valOid := getOidValue(val, prefix) switch v := valOid.(type) { case int: vFloat := float64(v) return &vFloat, nil case int8: vFloat := float64(v) return &vFloat, nil case int16: vFloat := float64(v) return &vFloat, nil case int32: vFloat := float64(v) return &vFloat, nil case int64: vFloat := float64(v) return &vFloat, nil case uint: vFloat := float64(v) return &vFloat, nil case uint8: vFloat := float64(v) return &vFloat, nil case uint16: vFloat := float64(v) return &vFloat, nil case uint32: vFloat := float64(v) return &vFloat, nil case uint64: vFloat := float64(v) return &vFloat, nil case float32: vFloat := float64(v) return &vFloat, nil case float64: return &v, nil case nil: return nil, nil default: if tryCast { if s, err := strconv.ParseFloat(fmt.Sprint(v), 64); err != nil { return nil, nil } else { return &s, nil } } else { return nil, nil } } } }, new(func([]Value, string, bool) *float64), ), expr.Function( "OidValueString", func(params ...any) (any, error) { if val, ok := params[0].([]Value); !ok { return nil, errors.Errorf( "unexpected error, invalid first param type %s", reflect.TypeOf(params[0]), ) } else { prefix, ok := params[1].(string) if !ok { return nil, errors.Errorf( "unexpected error, invalid second param type %s", reflect.TypeOf(params[1]), ) } tryCast, ok := params[2].(bool) if !ok { return nil, errors.Errorf( "unexpected error, invalid third param type %s", reflect.TypeOf(params[2]), ) } valOid := getOidValue(val, prefix) switch v := valOid.(type) { case string: return &v, nil case nil: return nil, nil default: if tryCast { s := fmt.Sprint(v) return &s, nil } else { return nil, nil } } } }, new(func([]Value, string, bool) *string), ), }
Functions ¶
func InitMIBTranslator ¶
Types ¶
type AuthConfig ¶
type Config ¶
type Config struct { Auth AuthConfig Listening []string AdditionalConfig string `mapstructure:"additional_config"` MagicBegin string `mapstructure:"magic_begin"` MagicEnd string `mapstructure:"magic_end"` BufferSize string `mapstructure:"buffer_size"` }
func (*Config) GetBufferSize ¶ added in v0.4.6
type Message ¶
func (*Message) Compile ¶ added in v0.2.0
func (m *Message) Compile(conf MessageCompiler)
func (*Message) ComputeEta ¶ added in v0.2.0
func (*Message) Copy ¶ added in v0.2.0
Copy is only a shallow copy, only the metadata is different between messages
func (*Message) UnmarshalText ¶
type MessageCompiler ¶ added in v0.2.0
type Payload ¶ added in v0.6.0
type Payload struct { Time time.Time `json:"time" expr:"time"` UptimeSeconds *float64 `json:"uptime_seconds" expr:"uptime_seconds"` SrcAddress string `json:"src_address" expr:"src_address"` SrcPort int `json:"src_port" expr:"src_port"` DstAddress string `json:"dst_address" expr:"dst_address"` DstPort int `json:"dst_port" expr:"dst_port"` AgentAddress *string `json:"agent_address" expr:"agent_address"` PDUVersion string `json:"pdu_version" expr:"pdu_version"` SNMPVersion string `json:"snmp_version" expr:"snmp_version"` Community *string `json:"community" expr:"community"` EnterpriseOID *string `json:"enterprise_oid" expr:"enterprise_oid"` EnterpriseMIBName *string `json:"enterprise_mib_name" expr:"enterprise_mib_name"` User *string `json:"user" expr:"user"` Context *string `json:"context" expr:"context"` Description *string `json:"description" expr:"description"` TrapType *int64 `json:"trap_type" expr:"trap_type"` TrapSubType *int64 `json:"trap_sub_type" expr:"trap_sub_type"` Values []Value `json:"values" expr:"value_list"` Correlate *Correlate `json:"correlate" expr:"correlate"` }
type PrivacyProtocol ¶
type PrivacyProtocol int8
const ( PrivAES PrivacyProtocol = iota PrivDES PrivAES128 PrivAES192 PrivAES256 )
func (*PrivacyProtocol) String ¶
func (p *PrivacyProtocol) String() string
func (*PrivacyProtocol) UnmarshalText ¶
func (p *PrivacyProtocol) UnmarshalText(text []byte) error
type User ¶
type User struct { Username string NoAuth bool `mapstructure:"no_auth"` RequirePrivacy bool `mapstructure:"require_privacy"` EngineID string `mapstructure:"engine_id"` AuthType AuthType `mapstructure:"auth_type"` AuthPassphrase string `mapstructure:"auth_passphrase"` PrivacyProtocol PrivacyProtocol `mapstructure:"privacy_protocol"` PrivacyPassphrase string `mapstructure:"privacy_passphrase"` }
func (User) SecurityLevel ¶
type Value ¶
type Value struct { OID string `json:"oid" expr:"oid"` MIBName string `json:"mib_name" expr:"mib_name"` Type ValueType `json:"type" expr:"type"` NativeType string `json:"native_type" expr:"native_type"` Value any `json:"value" expr:"value"` ValueDetail ValueDetail `json:"value_detail" expr:"value_detail"` }
func (Value) HasOIDPrefix ¶
type ValueDetail ¶
Click to show internal directories.
Click to hide internal directories.