Documentation
¶
Index ¶
- Constants
- Variables
- func AddSubscribeResponseTarget(rsp *gnmi.SubscribeResponse, meta Meta, addTarget string, ...) (*gnmi.SubscribeResponse, error)
- func AddSubscriptionTarget(msg proto.Message, meta Meta, addTarget string, tpl *template.Template) (proto.Message, error)
- func BindLogger(parent *slog.Logger, outputType, name string) *slog.Logger
- func DecodeConfig(src, dst any) error
- func ExecTemplate(content []byte, tpl *template.Template) ([]byte, error)
- func Marshal(pmsg protoreflect.ProtoMessage, meta map[string]string, ...) ([][]byte, error)
- func Register(name string, initFn Initializer)
- func UpdateProcessorInSlice(logger *slog.Logger, storeObj store.Store[any], eventProcessors []string, ...) ([]formatters.EventProcessor, bool, error)
- func ValidateAddTarget(v any) error
- type BaseOutput
- func (b *BaseOutput) Close() error
- func (b *BaseOutput) Init(context.Context, string, map[string]any, ...Option) error
- func (b *BaseOutput) String() string
- func (b *BaseOutput) Update(context.Context, map[string]any) error
- func (b *BaseOutput) UpdateProcessor(string, map[string]any) error
- func (b *BaseOutput) Validate(map[string]any) error
- func (b *BaseOutput) Write(context.Context, proto.Message, Meta)
- func (b *BaseOutput) WriteEvent(context.Context, *formatters.EventMsg)
- type Initializer
- type Meta
- type Option
- type Output
- type OutputOptions
- type ProtoMsg
Constants ¶
const ( // AddTargetOverwrite always sets Prefix.Target from the target template. AddTargetOverwrite = "overwrite" // AddTargetIfNotPresent sets Prefix.Target from the target template only // when the received message has an empty target. AddTargetIfNotPresent = "if-not-present" )
Variables ¶
var ( DefaultTargetTemplate = template.Must( template.New("target-template"). Funcs(TemplateFuncs). Parse(defaultTargetTemplateString)) TemplateFuncs = template.FuncMap{ "host": utils.GetHost, } )
var OutputTypes = map[string]struct{}{
"asciigraph": {},
"clickhouse": {},
"file": {},
"influxdb": {},
"kafka": {},
"nats": {},
"otlp": {},
"prometheus": {},
"prometheus_write": {},
"tcp": {},
"udp": {},
"gnmi": {},
"jetstream": {},
"snmp": {},
}
var Outputs = map[string]Initializer{}
Functions ¶
func AddSubscribeResponseTarget ¶
func AddSubscribeResponseTarget(rsp *gnmi.SubscribeResponse, meta Meta, addTarget string, tpl *template.Template) (*gnmi.SubscribeResponse, error)
AddSubscribeResponseTarget sets the Prefix.Target of a SubscribeResponse update according to addTarget (see AddTargetOverwrite and AddTargetIfNotPresent), using tpl rendered with meta as the target value.
Responses that need no change (addTarget empty or unknown, sync-responses, updates that already carry a target with AddTargetIfNotPresent) are returned as they were received: the function never returns nil for a non-nil input. When the response is modified, the input is left untouched and a modified copy is returned. On template error the original response is returned along with the error.
func AddSubscriptionTarget ¶
func AddSubscriptionTarget(msg proto.Message, meta Meta, addTarget string, tpl *template.Template) (proto.Message, error)
AddSubscriptionTarget is the proto.Message form of AddSubscribeResponseTarget. Messages that are not a *gnmi.SubscribeResponse are returned as they were received: the function never returns a nil message for a non-nil input.
func BindLogger ¶ added in v0.46.0
BindLogger returns a non-nil *slog.Logger annotated with the output kind and instance name. Centralises the
if options.Logger != nil { o.logger = options.Logger.With(...) }
boilerplate that every output used to repeat. When parent is nil, a discarding logger is returned so callers never need a nil check.
func DecodeConfig ¶
DecodeConfig decodes an output configuration map into dst.
On top of the mapstructure decoding, it validates the fields shared by several output types (currently `add-target`), so that a typo in one of them is rejected at load time instead of silently changing the output behavior at runtime.
func Marshal ¶
func Marshal(pmsg protoreflect.ProtoMessage, meta map[string]string, mo *formatters.MarshalOptions, splitEvents bool, evps ...formatters.EventProcessor) ([][]byte, error)
func Register ¶
func Register(name string, initFn Initializer)
func UpdateProcessorInSlice ¶ added in v0.43.0
func UpdateProcessorInSlice( logger *slog.Logger, storeObj store.Store[any], eventProcessors []string, currentEvps []formatters.EventProcessor, processorName string, pcfg map[string]any, ) ([]formatters.EventProcessor, bool, error)
func ValidateAddTarget ¶
ValidateAddTarget checks the value of an output `add-target` field. An empty string (or nil) disables the feature and is valid.
Types ¶
type BaseOutput ¶ added in v0.42.1
type BaseOutput struct {
}
func (*BaseOutput) Close ¶ added in v0.42.1
func (b *BaseOutput) Close() error
func (*BaseOutput) String ¶ added in v0.42.1
func (b *BaseOutput) String() string
func (*BaseOutput) UpdateProcessor ¶ added in v0.43.0
func (b *BaseOutput) UpdateProcessor(string, map[string]any) error
func (*BaseOutput) WriteEvent ¶ added in v0.42.1
func (b *BaseOutput) WriteEvent(context.Context, *formatters.EventMsg)
type Initializer ¶
type Initializer func() Output
type Option ¶
type Option func(*OutputOptions) error
func WithClusterName ¶
func WithLogger ¶
func WithRegistry ¶
func WithRegistry(reg *prometheus.Registry) Option
type Output ¶
type Output interface {
// initialize the output
Init(context.Context, string, map[string]any, ...Option) error
// validate the config
Validate(map[string]any) error
// update the config
Update(context.Context, map[string]any) error
// update a processor
UpdateProcessor(string, map[string]any) error
// write a protobuf message to the output
Write(context.Context, proto.Message, Meta)
// write an event message to the output
WriteEvent(context.Context, *formatters.EventMsg)
// close the output
Close() error
// return a string representation of the output
String() string
}