forwarder

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartForwarders

func StartForwarders(wg *sync.WaitGroup, c []Config, messageChan <-chan *snmp.Message)

Types

type Base

type Base struct {
	CompilerConf snmp.MessageCompiler
	// contains filtered or unexported fields
}

func NewBase

func NewBase(c Config, idx int) Base

func (*Base) Close

func (b *Base) Close()

func (*Base) Config added in v0.6.0

func (b *Base) Config() Config

func (*Base) Done

func (b *Base) Done() <-chan struct{}

func (*Base) ReceiveChannel added in v0.6.0

func (b *Base) ReceiveChannel() <-chan *snmp.Message

func (*Base) Retry added in v0.2.0

func (b *Base) Retry(message *snmp.Message, err error)

func (*Base) Send

func (b *Base) Send(m *snmp.Message)

type Cmd added in v0.2.0

type Cmd struct {
	Commands []string
	Message  *snmp.Message
}

type Config

type Config struct {
	// ID identifies forwarder name, also used for prometheus labelling
	ID string
	// QueueSize defines the size of queue of each forwarder, when queue is full (might be caused
	// by slow forwarder) the message is dropped
	QueueSize int `mapstructure:"queue_size"`
	// TimeFormat specifies golang time format for casting time related fields to string
	TimeFormat string `mapstructure:"time_format"`
	// TimeAsTimezone will cast any time field to specified timezone
	TimeAsTimezone   string          `mapstructure:"time_as_timezone"`
	ShutdownWaitTime helper.Duration `mapstructure:"shutdown_wait_time"`
	// Filter, JSONFormat utilizes antonmedv/expr expressions
	Filter        string
	JSONFormat    string           `mapstructure:"json_format"`
	AutoRetry     helper.AutoRetry `mapstructure:"auto_retry"`
	Mock          *MockConfig
	File          *FileConfig
	Kafka         *KafkaConfig
	MQTT          *MQTTConfig
	Trap          *SNMPTrapConfig
	HTTP          *HTTPConfig
	ZabbixTrapper *ZabbixTrapperConfig `mapstructure:"zabbix_trapper"`
}

func (*Config) Type

func (c *Config) Type() string

type File

type File struct {
	Base
}

func (*File) Run

func (f *File) Run()

type FileConfig

type FileConfig struct {
	// Path for json log. Make sure the user has sufficient permission to write
	Path string
}

type Forwarder

type Forwarder interface {
	// Send will send the trap message to its corresponding forwarder.
	// Does nothing if the queue buffer is full or forwarder is already closed
	Send(*snmp.Message)
	// ReceiveChannel is used inside the forwarder to receive data
	// from SendChannel
	ReceiveChannel() <-chan *snmp.Message
	// Close informs the forwarder to stop processing any new messages
	Close()
	// Done informs the caller if forwarder is done processing
	Done() <-chan struct{}
	// Config returns the forwarder config
	Config() Config
}

func NewFile

func NewFile(c Config, idx int) Forwarder

func NewHTTP added in v0.5.0

func NewHTTP(c Config, idx int) Forwarder

func NewKafka

func NewKafka(c Config, idx int) Forwarder

func NewMQTT

func NewMQTT(c Config, idx int) Forwarder

func NewMock added in v0.2.0

func NewMock(c Config, idx int) Forwarder

func NewSNMPTrap

func NewSNMPTrap(c Config, idx int) Forwarder

func NewZabbixTrapper

func NewZabbixTrapper(c Config, idx int) Forwarder

type HTTP added in v0.5.0

type HTTP struct {
	Base
	// contains filtered or unexported fields
}

func (*HTTP) Run added in v0.5.0

func (h *HTTP) Run()

type HTTPBasicAuth added in v0.5.0

type HTTPBasicAuth struct {
	Username string
	Password string
}

type HTTPConfig added in v0.5.0

type HTTPConfig struct {
	URL       string `mapstructure:"url"`
	Method    HTTPMethod
	Headers   map[string][]string
	BasicAuth *HTTPBasicAuth `mapstructure:"basic_auth"`
	Tls       *Tls
	Proxy     string
	Timeout   helper.Duration
}

type HTTPMethod added in v0.5.0

type HTTPMethod int
const (
	HTTPMethodPost HTTPMethod = iota
	HTTPMethodGet
	HTTPMethodPut
)

func (*HTTPMethod) String added in v0.5.0

func (h *HTTPMethod) String() string

func (*HTTPMethod) UnmarshalText added in v0.5.0

func (h *HTTPMethod) UnmarshalText(text []byte) error

type Kafka

type Kafka struct {
	Base
	// contains filtered or unexported fields
}

func (*Kafka) Run

func (k *Kafka) Run()

type KafkaConfig

type KafkaConfig struct {
	RequiredAcks kafka.RequiredAcks `mapstructure:"required_acks"`
	KeyField     string             `mapstructure:"key_field"`
	Hosts        []string
	Topic        string
	Tls          *Tls
	Sasl         *KafkaSasl
	BatchSize    int             `mapstructure:"batch_size"`
	BatchTimeout helper.Duration `mapstructure:"batch_timeout"`
}

type KafkaSasl added in v0.4.8

type KafkaSasl struct {
	Username  string
	Password  string
	Mechanism KafkaSaslMechanism
}

type KafkaSaslMechanism added in v0.4.8

type KafkaSaslMechanism int
const (
	KafkaSaslPlain KafkaSaslMechanism = iota
	KafkaSaslSha256
	KafkaSaslSha512
)

func (*KafkaSaslMechanism) String added in v0.4.8

func (k *KafkaSaslMechanism) String() string

func (*KafkaSaslMechanism) UnmarshalText added in v0.4.8

func (k *KafkaSaslMechanism) UnmarshalText(text []byte) error

type LookupResult

type LookupResult struct {
	Server   *ProxyConf
	Hostname string
}

type LookupStrategy

type LookupStrategy int8
const (
	// LookupFromAgentAddress will use the agent address as hostname, or search for interface
	// ip/dns if db_url config is specified
	LookupFromAgentAddress LookupStrategy = iota
	// LookupFromSourceAddress will use the source address as hostname, or search for interface
	// ip/dns if db_url config is specified
	LookupFromSourceAddress
	// LookupFromOID will use the value of a given OID as the hostname. If db_url config is specified,
	// this will check for host existence before sending, and send it using default_hostname if it's not found
	LookupFromOID
)

func (*LookupStrategy) String

func (l *LookupStrategy) String() string

func (*LookupStrategy) UnmarshalText

func (l *LookupStrategy) UnmarshalText(text []byte) error

type MQTT

type MQTT struct {
	Base
}

func (*MQTT) Run

func (m *MQTT) Run()

type MQTTConfig

type MQTTConfig struct {
	Hosts    []string
	ClientID string `mapstructure:"client_id"`
	Username string
	Password string
	Ordered  *bool
	TLS      *TlsConfig
	Topic    string
	Qos      uint8
}

type Mock added in v0.2.0

type Mock struct {
	Base
}

func (*Mock) Run added in v0.2.0

func (m *Mock) Run()

type MockConfig added in v0.2.0

type MockConfig struct {
	OutChannel chan *snmp.Message
	Timeout    helper.Duration
}

type ProxyConf

type ProxyConf struct {
	Hostname string
	Address  string
	Port     int
}

ProxyConf is the list of available proxies in a zabbix system. In case of HA zabbix server, you need to include it here with its HANodeName

type QueryResult

type QueryResult struct {
	IPOrDNS       string         `db:"ip_or_dns"`
	Hostname      string         `db:"hostname"`
	ProxyHostname sql.NullString `db:"proxy_hostname"`
}

type SNMPTrap

type SNMPTrap struct {
	Base
	// contains filtered or unexported fields
}

func (*SNMPTrap) Run

func (s *SNMPTrap) Run()

type SNMPTrapConfig

type SNMPTrapConfig struct {
	Workers      int
	EnableInform bool `mapstructure:"enable_inform"`
	Host         string
	Version      string
	Community    string
	Context      string
	User         snmp.User
}

type Tls added in v0.5.0

type Tls struct {
	InsecureSkipVerify bool   `mapstructure:"insecure_skip_verify"`
	CaCert             string `mapstructure:"ca_cert"`
	ClientCert         string `mapstructure:"client_cert"`
	ClientKey          string `mapstructure:"client_key"`
}

type TlsConfig

type TlsConfig struct {
	InsecureSkipVerify bool `mapstructure:"insecure_skip_verify"`
}

type ZSAdvancedConfig

type ZSAdvancedConfig struct {
	Proxies []ProxyConf

	// for example:
	// - postgres://user:pass@127.0.0.1:5432/dbname?param1=value1&param2=value2
	// - mysql://user:pass@127.0.0.1:3306/dbname?param1=value1&param2=value2
	DBUrl             string          `mapstructure:"db_url"`
	DBRefreshInterval helper.Duration `mapstructure:"db_refresh_interval"`
	DBQueryTimeout    helper.Duration `mapstructure:"db_query_timeout"`
	// contains filtered or unexported fields
}

type ZabbixLookup

type ZabbixLookup struct {
	// contains filtered or unexported fields
}

func NewZabbixLookup

func NewZabbixLookup(
	c *ZabbixTrapperConfig,
	logger zerolog.Logger,
	ctx context.Context,
) *ZabbixLookup

func (*ZabbixLookup) Lookup

func (z *ZabbixLookup) Lookup(m *snmp.Message, strategy LookupStrategy) (LookupResult, error)

func (*ZabbixLookup) Refresh

func (z *ZabbixLookup) Refresh()

type ZabbixTrapper

type ZabbixTrapper struct {
	Base
	// contains filtered or unexported fields
}

func (*ZabbixTrapper) Run

func (z *ZabbixTrapper) Run()

type ZabbixTrapperConfig

type ZabbixTrapperConfig struct {
	// default_* is used whenever host lookup fails:
	// - no advanced config defined
	// - proxy is defined in zabbix, but not defined in configuration
	// - can't find monitored hostname
	// - lookup strategy fails
	// DefaultAddress and DefaultPort are also used in case the host
	// is monitored directly with zabbix server and zabbix server
	// is not configured as HA
	DefaultAddress         string         `mapstructure:"default_address"`
	DefaultPort            int            `mapstructure:"default_port"`
	DefaultHostname        string         `mapstructure:"default_hostname"`
	ItemKey                string         `mapstructure:"item_key"`
	HostnameLookupStrategy LookupStrategy `mapstructure:"hostname_lookup_strategy"`
	OIDLookup              string         `mapstructure:"oid_lookup"`
	// Advanced config is for systems with proxies setup
	Advanced *ZSAdvancedConfig
}

Jump to

Keyboard shortcuts

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