switchcase

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

README

SwitchCase Processor Plugin

The switchcase processor allows the mapping of labels and fields between it's values.

Just like switch-case in Go:

field, _ := event.GetField("status.code")
switch field {
case "0", "1", "2":
    event.SetField("status.code", "success")
case "3", "4", "5":
    event.SetField("status.code", "faled")
}

[!WARNING]
Due to runtime panic-safety this plugin works only with strings. The Converter processor can help you here.

Configuration

[[processors]]
  # "labels" is a "label name" <- "mappings" dict
  [processors.switchcase.labels.region]

    # each mapping is a "new value" <- "old values" dict
    # if label exists and it value in "old values" list, 
    # it will be replaced with "new value"
    "west" = [ "w-1", "w-2", "w-3" ]
    "east" = [ "e-1", "e-2", "e-3" ]
  [processors.switchcase.labels.stage]
    "test" = [ "test", "feature", "integration", "load" ]

  # "fields" is a "field path" <- "mappings" dict
  # it works just like "labels"
  # if field exists, it is a string and it value in "old values" list, 
  # it will be replaced with "new value"
  [processors.switchcase.fields."status.code"]
    "success" = [ "0", "1", "2" ]
    "failed"  = [ "3", "4", "5" ]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapping

type Mapping map[string][]string

type SwitchCase

type SwitchCase struct {
	*core.BaseProcessor `mapstructure:"-"`
	Labels              map[string]Mapping `mapstructure:"labels"`
	Fields              map[string]Mapping `mapstructure:"fields"`
	// contains filtered or unexported fields
}

func (*SwitchCase) Close

func (p *SwitchCase) Close() error

func (*SwitchCase) Init

func (p *SwitchCase) Init() error

func (*SwitchCase) Run

func (p *SwitchCase) Run()

Jump to

Keyboard shortcuts

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