snmp

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PidFilePath = "/var/run/snmptrapd/snmptrapd.pid"
)

Variables

View Source
var Functions = []expr.Option{
	expr.Function(
		"MergeMap",
		func(params ...any) (any, error) {
			switch vList := params[0].(type) {
			case []map[string]any:
				res := make(map[string]any)
				for _, m := range vList {
					for k, v := range m {
						res[k] = v
					}
				}
				return res, nil
			case []any:
				res := make(map[string]any)
				for _, m := range vList {
					if mCast, ok := m.(map[string]any); !ok {
						return nil, errors.Errorf("incorrect type passed %s", reflect.TypeOf(m))
					} else {
						for k, v := range mCast {
							res[k] = v
						}
					}
				}
				return res, nil
			default:
				return nil, errors.Errorf("incorrect type passed %s", reflect.TypeOf(params[0]))
			}
		},
		new(func([]map[string]any) map[string]any),
	),
}

Functions

func InitMIBTranslator

func InitMIBTranslator(mibPath string) ([]string, error)

func ParserWorker

func ParserWorker(
	i int,
	wg *sync.WaitGroup,
	parseChan <-chan []byte,
	messageChan chan<- Message,
)

Types

type AuthConfig

type AuthConfig struct {
	// Enable auth for v1 and v2. v3 still needs users to be defined
	Enable bool
	// Community for snmp V1 and V2
	Community []Community
	// User for snmp v3
	User []User
}

type AuthType

type AuthType int8
const (
	AuthSHA AuthType = iota
	AuthMD5
)

func (*AuthType) String

func (a *AuthType) String() string

func (*AuthType) UnmarshalText

func (a *AuthType) UnmarshalText(text []byte) error

type Community

type Community struct {
	Name string
}

type Config

type Config struct {
	Auth             AuthConfig
	Listening        []string
	AdditionalConfig string `mapstructure:"additional_config"`
	MagicBegin       string `mapstructure:"magic_begin"`
	MagicEnd         string `mapstructure:"magic_end"`
}

func (*Config) Serialize

func (c *Config) Serialize(path string) error
type Header int8
const (
	HeaderAgentAddress Header = iota
	HeaderConnection
	HeaderTime
	HeaderUptime
	HeaderDescription
	HeaderEnterprise
	HeaderSecurity
	HeaderTrapType
	HeaderTrapSubType
	HeaderVarBinds
)

type Message

type Message struct {
	Time              TimeLayout  `json:"time"`
	UptimeSeconds     null.Float  `json:"uptime_seconds"`
	SrcAddress        string      `json:"src_address"`
	SrcPort           int         `json:"src_port"`
	DstAddress        string      `json:"dst_address"`
	DstPort           int         `json:"dst_port"`
	AgentAddress      null.String `json:"agent_address"`
	PDUVersion        string      `json:"pdu_version"`
	SNMPVersion       string      `json:"snmp_version"`
	Community         null.String `json:"community"`
	EnterpriseOID     null.String `json:"enterprise_oid"`
	EnterpriseMIBName null.String `json:"enterprise_mib_name"`
	User              null.String `json:"user"`
	Context           null.String `json:"context"`
	Description       null.String `json:"description"`
	TrapType          null.Int    `json:"trap_type"`
	TrapSubType       null.Int    `json:"trap_sub_type"`
	Values            []Value     `json:"values"`

	Retries         int             `json:"-"`
	Eta             time.Time       `json:"-"`
	Skip            bool            `json:"-"`
	MessageCompiled MessageCompiled `json:"-"`
	MessageJSON     []byte          `json:"-"`
	// contains filtered or unexported fields
}

func (*Message) Compare added in v0.2.0

func (m *Message) Compare(other queue.Item) int

func (*Message) Compile added in v0.2.0

func (m *Message) Compile(conf MessageCompiler)

func (*Message) ComputeEta added in v0.2.0

func (m *Message) ComputeEta(minDelay, maxDelay time.Duration) time.Time

func (*Message) Copy added in v0.2.0

func (m *Message) Copy() Message

func (*Message) UnmarshalText

func (m *Message) UnmarshalText(text []byte) error

type MessageCompiled added in v0.2.0

type MessageCompiled struct {
	Time              any             `expr:"time"`
	UptimeSeconds     *float64        `expr:"uptime_seconds"`
	SrcAddress        string          `expr:"src_address"`
	SrcPort           int             `expr:"src_port"`
	DstAddress        string          `expr:"dst_address"`
	DstPort           int             `expr:"dst_port"`
	AgentAddress      *string         `expr:"agent_address"`
	PDUVersion        string          `expr:"pdu_version"`
	SNMPVersion       string          `expr:"snmp_version"`
	Community         *string         `expr:"community"`
	EnterpriseOID     *string         `expr:"enterprise_oid"`
	EnterpriseMIBName *string         `expr:"enterprise_mib_name"`
	User              *string         `expr:"user"`
	Context           *string         `expr:"context"`
	Description       *string         `expr:"description"`
	TrapType          *int64          `expr:"trap_type"`
	TrapSubType       *int64          `expr:"trap_sub_type"`
	Values            []ValueCompiled `expr:"values"`
}

type MessageCompiler added in v0.2.0

type MessageCompiler struct {
	TimeFormat     string
	TimeAsTimezone string
	Filter         *vm.Program
	JSONFormat     *vm.Program
	Logger         zerolog.Logger
}

type PrivacyProtocol

type PrivacyProtocol int8
const (
	PrivAES PrivacyProtocol = iota
	PrivDES
)

func (*PrivacyProtocol) String

func (p *PrivacyProtocol) String() string

func (*PrivacyProtocol) UnmarshalText

func (p *PrivacyProtocol) UnmarshalText(text []byte) error

type TimeLayout added in v0.2.0

type TimeLayout struct {
	time.Time
	// contains filtered or unexported fields
}

func (*TimeLayout) MarshalJSON added in v0.2.0

func (t *TimeLayout) MarshalJSON() ([]byte, error)

func (*TimeLayout) MarshalNative added in v0.2.0

func (t *TimeLayout) MarshalNative() any

func (*TimeLayout) SetLayout added in v0.2.0

func (t *TimeLayout) SetLayout(layout string)

func (*TimeLayout) SetTimezone added in v0.2.0

func (t *TimeLayout) SetTimezone(tz string)

func (*TimeLayout) String added in v0.2.0

func (t *TimeLayout) String() string

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

func (u User) SecurityLevel() string

type Value

type Value struct {
	OID         string      `json:"oid"`
	MIBName     null.String `json:"mib_name"`
	Type        ValueType   `json:"type"`
	NativeType  string      `json:"native_type"`
	Value       any         `json:"value"`
	ValueDetail ValueDetail `json:"value_detail"`
}

func (Value) Compile added in v0.2.0

func (v Value) Compile(conf MessageCompiler) ValueCompiled

func (Value) HasOIDPrefix

func (v Value) HasOIDPrefix(prefix string) bool

func (Value) SnmpCmd

func (v Value) SnmpCmd() (cmd []string)

type ValueCompiled added in v0.2.0

type ValueCompiled struct {
	OID         string      `expr:"oid"`
	MIBName     string      `expr:"mib_name"`
	Type        string      `expr:"type"`
	NativeType  string      `expr:"native_type"`
	Value       any         `expr:"value"`
	ValueDetail ValueDetail `expr:"value_detail"`
}

type ValueDetail

type ValueDetail struct {
	Raw any    `json:"raw,omitempty" expr:"raw"`
	Hex string `json:"hex,omitempty" expr:"hex"`
}

type ValueType

type ValueType int8
const (
	TypeUnknown ValueType = iota
	TypeInteger
	TypeDuration
	TypeEnum
	TypeIpAddress
	TypeOID
	TypeString
	TypeBytes
	TypeBits
	TypeDateAndTime
	TypeNull
)

func (*ValueType) FromMIB

func (v *ValueType) FromMIB(text string) error

func (*ValueType) FromSNMP

func (v *ValueType) FromSNMP(text string) error

func (*ValueType) MarshalJSON

func (v *ValueType) MarshalJSON() ([]byte, error)

func (*ValueType) Parse

func (v *ValueType) Parse(text string) (any, ValueDetail, error)

func (*ValueType) String

func (v *ValueType) String() string

Jump to

Keyboard shortcuts

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