interpreter

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: Apache-2.0 Imports: 8 Imported by: 6

README

interpreter

Interpreter validates events and can be used in projects that aim to generate aggregate or individual device metrics.

Build Status codecov.io Go Report Card Apache V2 License Quality Gate Status GitHub release PkgGoDev

Summary

Interpreter provides different validations for validating:

  • Events are valid (e.g. having a proper boot-time, etc.)
  • Boot-cycles are as expected.

Table of Contents

Code of Conduct

This project and everyone participating in it are governed by the XMiDT Code Of Conduct. By participating, you agree to this Code.

Install

go get -u github.com/xmidt-org/interpreter

Contributing

Refer to CONTRIBUTING.md.

Documentation

Index

Constants

View Source
const (
	BootTimeKey = "/boot-time"

	TypeSubexpName      = "type"
	IDSubexpName        = "ID"
	AuthoritySubexpName = "authority"
	EventSubexpName     = "event"
	SchemeSubexpName    = "scheme"
)

Variables

View Source
var (
	ErrParseDeviceID    = errors.New("error getting device ID from event")
	ErrBirthdateParse   = errors.New("unable to parse birthdate from payload")
	ErrBootTimeParse    = errors.New("unable to parse boot-time")
	ErrBootTimeNotFound = errors.New("boot-time not found")
	ErrEventRegex       = errors.New("event regex is wrong")
	ErrTypeNotFound     = errors.New("type not found")

	// EventRegex is the regex that an event's destination must match in order to parse the device id properly.
	EventRegex = regexp.MustCompile(fmt.Sprintf(`^(?P<%s>[^/]+)/(?P<%s>(?P<%s>(?i)mac|uuid|dns|serial):(?P<%s>[^/]+))/(?P<%s>[^/\s]+)`, EventSubexpName, IDSubexpName, SchemeSubexpName, AuthoritySubexpName, TypeSubexpName))

	// DeviceIDRegex is used to parse a device id from anywhere.
	DeviceIDRegex = regexp.MustCompile(fmt.Sprintf(`(?P<%s>(?i)mac|uuid|dns|serial):(?P<%s>[^/]+)`, SchemeSubexpName, AuthoritySubexpName))

	OnlineEventType          = "online"
	OfflineEventType         = "offline"
	RebootPendingEventType   = "reboot-pending"
	FullyManageableEventType = "fully-manageable"
	OperationalEventType     = "operational"
)

Functions

This section is empty.

Types

type Event

type Event struct {
	MsgType         int               `json:"msg_type"`
	Source          string            `json:"source"`
	Destination     string            `json:"dest,omitempty"`
	TransactionUUID string            `json:"transaction_uuid,omitempty"`
	ContentType     string            `json:"content_type,omitempty"`
	Metadata        map[string]string `json:"metadata"`
	Payload         string            `json:"payload,omitempty"`
	Birthdate       int64             `json:"birth_date"`
	PartnerIDs      []string          `json:"partner_ids,omitempty"`
	SessionID       string            `json:"sessionID"`
}

Event is the struct that contains the wrp.Message fields along with the birthdate that is parsed from the payload.

func NewEvent

func NewEvent(msg wrp.Message) (Event, error)

NewEvent creates an Event from a wrp.Message and also parses the Birthdate from the message payload. A new Event will always be returned from this function, but if the birthdate cannot be parsed from the payload, it will return an error along with the Event created.

func (Event) BootTime

func (e Event) BootTime() (int64, error)

BootTime parses the boot-time from an event, returning an error if the boot-time doesn't exist or cannot be parsed.

func (Event) DeviceID

func (e Event) DeviceID() (string, error)

DeviceID gets the device id from the event's destination based on the event regex.

func (Event) EventType added in v0.0.3

func (e Event) EventType() (string, error)

EventType returns the event type from the event's destination.

func (Event) GetMetadataValue

func (e Event) GetMetadataValue(key string) (string, bool)

GetMetadataValue checks the metadata map for a specific key, allowing for keys with or without forward-slash.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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