Files
akvorado/inlet/flow/config.go
Vincent Bernat 0239cd0a9f common: remove MarshalJSON helpers for mapstructure
They are not needed anymore since we don't exchange configuration files
using JSON, since baac495b9c.
2024-07-20 14:51:40 +02:00

67 lines
2.0 KiB
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package flow
import (
"golang.org/x/time/rate"
"akvorado/common/helpers"
"akvorado/inlet/flow/decoder"
"akvorado/inlet/flow/input"
"akvorado/inlet/flow/input/file"
"akvorado/inlet/flow/input/udp"
)
// Configuration describes the configuration for the flow component
type Configuration struct {
// Inputs define a list of input modules to enable
Inputs []InputConfiguration `validate:"dive"`
// RateLimit defines a rate limit on the number of flows per
// second. The limit is per-exporter.
RateLimit rate.Limit `validate:"isdefault|min=100"`
}
// DefaultConfiguration represents the default configuration for the flow component
func DefaultConfiguration() Configuration {
return Configuration{
Inputs: []InputConfiguration{{
TimestampSource: decoder.TimestampSourceUDP,
Decoder: "netflow",
Config: udp.DefaultConfiguration(),
}, {
TimestampSource: decoder.TimestampSourceUDP,
Decoder: "sflow",
Config: udp.DefaultConfiguration(),
}},
}
}
// InputConfiguration represents the configuration for an input.
type InputConfiguration struct {
// Decoder is the decoder to associate to the input.
Decoder string
// UseSrcAddrForExporterAddr replaces the exporter address by the transport
// source address.
UseSrcAddrForExporterAddr bool
// TimestampSource identify the source to use to timestamp the flows
TimestampSource decoder.TimestampSource
// Config is the actual configuration of the input.
Config input.Configuration
}
// MarshalYAML undoes ConfigurationUnmarshallerHook().
func (ic InputConfiguration) MarshalYAML() (interface{}, error) {
return helpers.ParametrizedConfigurationMarshalYAML(ic, inputs)
}
var inputs = map[string](func() input.Configuration){
"udp": udp.DefaultConfiguration,
"file": file.DefaultConfiguration,
}
func init() {
helpers.RegisterMapstructureUnmarshallerHook(
helpers.ParametrizedConfigurationUnmarshallerHook(InputConfiguration{}, inputs))
}