schema

package
v6.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package schema contains helper utilities to parse, convert, rename, and reorganize data from the format returned by the various monitored systems to the data model used by Metricbeat.

See the docs in the mapstrstr and mapstriface sub-packages for usage examples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conv

type Conv struct {
	Func     Converter // Convertor function
	Key      string    // The key in the data map
	Optional bool      // Whether to log errors if the key is not found
}

A Conv object represents a conversion mechanism from the data map to the event map.

func Optional

func Optional(c Conv) Conv

The optional flag suppresses the error message in case the key doesn't exist or results in an error.

func SetOptions

func SetOptions(c Conv, opts []SchemaOption) Conv

setOptions adds the optional flags to the Conv object

func (Conv) HasKey

func (conv Conv) HasKey(key string) bool

func (Conv) Map

func (conv Conv) Map(key string, event common.MapStr, data map[string]interface{}) *Errors

Map applies the conversion on the data and adds the result to the event on the key.

type Converter

type Converter func(key string, data map[string]interface{}) (interface{}, error)

Convertor function type

type Error

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

func NewError

func NewError(key string, message string) *Error

func (*Error) Error

func (err *Error) Error() string

func (*Error) IsType

func (err *Error) IsType(errorType ErrorType) bool

func (*Error) SetType

func (err *Error) SetType(errorType ErrorType)

type ErrorType

type ErrorType int
const (
	RequiredType ErrorType = iota
	OptionalType ErrorType = iota
)

type Errors

type Errors []Error

func NewErrors

func NewErrors() *Errors

func (*Errors) AddError

func (errs *Errors) AddError(err *Error)

func (*Errors) AddErrors

func (errs *Errors) AddErrors(errors *Errors)

func (*Errors) Error

func (errs *Errors) Error() string

func (*Errors) ErrorDebug

func (errs *Errors) ErrorDebug() string

func (*Errors) HasRequiredErrors

func (errs *Errors) HasRequiredErrors() bool

type Mapper

type Mapper interface {
	// Map applies the Mapper conversion on the data and adds the result
	// to the event on the key.
	Map(key string, event common.MapStr, data map[string]interface{}) *Errors

	HasKey(key string) bool
}

Mapper interface represents a valid type to be used in a schema.

type Object

type Object map[string]Mapper

implements Mapper interface for structure

func (Object) HasKey

func (o Object) HasKey(key string) bool

func (Object) Map

func (o Object) Map(key string, event common.MapStr, data map[string]interface{}) *Errors

type Schema

type Schema map[string]Mapper

Schema describes how a map[string]interface{} object can be parsed and converted into an event. The conversions can be described using an (optionally nested) common.MapStr that contains Conv objects.

func (Schema) Apply

func (s Schema) Apply(data map[string]interface{}) (common.MapStr, *Errors)

Apply converts the fields extracted from data, using the schema, into a new map and reports back the errors.

func (Schema) ApplyTo

func (s Schema) ApplyTo(event common.MapStr, data map[string]interface{}) (common.MapStr, *Errors)

ApplyTo adds the fields extracted from data, converted using the schema, to the event map.

func (Schema) HasKey

func (s Schema) HasKey(key string) bool

HasKey checks if the key is part of the schema

type SchemaOption

type SchemaOption func(c Conv) Conv

SchemaOption is for adding optional parameters to the conversion functions

Directories

Path Synopsis
Package mapstriface contains utilities for transforming map[string]interface{} objects into metricbeat events.
Package mapstriface contains utilities for transforming map[string]interface{} objects into metricbeat events.
Package mapstrstr contains utilities for transforming map[string]string objects into metricbeat events.
Package mapstrstr contains utilities for transforming map[string]string objects into metricbeat events.

Jump to

Keyboard shortcuts

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