beats: Index | Files

package mapstriface

import ""

Package mapstriface contains utilities for transforming map[string]interface{} objects into metricbeat events. For example, given this input object:

input := map[string]interface{}{
	"testString":       "hello",
	"testInt":          42,
	"testIntFromFloat": 42.0,
	"testIntFromInt64": int64(42),
	"testBool":         true,
	"testObj": map[string]interface{}{
		"testObjString": "hello, object",
	"testNonNestedObj": "hello from top level",

And the requirement to transform it into this one:

	"test_string":         "hello",
	"test_int":            int64(42),
	"test_int_from_float": int64(42),
	"test_int_from_int64": int64(42),
	"test_bool":           true,
	"test_time":           common.Time(ts),
	"test_obj_1": common.MapStr{
		"test": "hello from top level",
	"test_obj_2": common.MapStr{
		"test": "hello, object",

It can be done with the following code:

schema := s.Schema{
	"test_string":         Str("testString"),
	"test_int":            Int("testInt"),
	"test_int_from_float": Int("testIntFromFloat"),
	"test_int_from_int64": Int("testIntFromInt64"),
	"test_bool":           Bool("testBool"),
	"test_time":           Time("testTime"),
	"test_obj_1": s.Object{
		"test": Str("testNonNestedObj"),
	"test_obj_2": Dict("testObj", s.Schema{
		"test": Str("testObjString"),
output := schema.Apply(input)

Note that this allows for converting, renaming, and restructuring the data.


Package Files


func Bool Uses

func Bool(key string, opts ...schema.SchemaOption) schema.Conv

Bool creates a Conv object for converting booleans.

func Float Uses

func Float(key string, opts ...schema.SchemaOption) schema.Conv

Float creates a Conv object for converting floats. Acceptable input types are int64, int, and float64.

func Ifc Uses

func Ifc(key string, opts ...schema.SchemaOption) schema.Conv

Ifc creates a schema.Conv object for converting the given data to interface.

func Int Uses

func Int(key string, opts ...schema.SchemaOption) schema.Conv

Int creates a Conv object for converting integers. Acceptable input types are int64, int, and float64.

func Str Uses

func Str(key string, opts ...schema.SchemaOption) schema.Conv

Str creates a schema.Conv object for converting strings.

func StrFromNum Uses

func StrFromNum(key string, opts ...schema.SchemaOption) schema.Conv

StrFromNum creates a schema.Conv object that transforms numbers to strings.

func Time Uses

func Time(key string, opts ...schema.SchemaOption) schema.Conv

Time creates a Conv object for converting Time objects.

type ConvMap Uses

type ConvMap struct {
    Key      string        // The key in the data map
    Schema   schema.Schema // The schema describing how to convert the sub-map
    Optional bool
    Required bool

func Dict Uses

func Dict(key string, s schema.Schema, opts ...DictSchemaOption) ConvMap

func DictOptional Uses

func DictOptional(c ConvMap) ConvMap

DictOptional sets the optional flag, which suppresses the error in case the key doesn't exist or results in an error.

func DictRequired Uses

func DictRequired(c ConvMap) ConvMap

DictRequired sets the required flag, which forces an error even if fields are optional by default

func (ConvMap) HasKey Uses

func (convMap ConvMap) HasKey(key string) bool

func (ConvMap) Map Uses

func (convMap ConvMap) Map(key string, event common.MapStr, data map[string]interface{}) multierror.Errors

Map drills down in the data dictionary by using the key

type DictSchemaOption Uses

type DictSchemaOption func(c ConvMap) ConvMap

SchemaOption is for adding optional parameters to the conversion functions

Package mapstriface imports 7 packages (graph) and is imported by 707 packages. Updated 2018-07-16. Refresh now. Tools for package owners.