event

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	ID      string           `bson:"_id" json:"id"`    // 事件ID
	Time    ftime.Time       `bson:"time" json:"time"` // 事件发生时间(毫秒)
	Type    Type             `bson:"type" json:"type"` // 事件类型
	*Header `bson:",inline"` // 事件头
	Body    interface{}      `bson:"body" json:"body"` // 事件数据
	// contains filtered or unexported fields
}

Event 事件数据结构

func NewDefaultEvent added in v0.4.0

func NewDefaultEvent() *Event

NewDefaultEvent todo

func NewOperateEvent added in v0.4.0

func NewOperateEvent(header *Header, e *OperateEvent) *Event

NewOperateEvent 实例

func (*Event) Context added in v0.3.4

func (e *Event) Context() context.Context

Context 返回事件的上下文

func (*Event) ParseBody added in v0.4.0

func (e *Event) ParseBody() error

ParseBody todo

func (*Event) Validate added in v0.5.7

func (e *Event) Validate() error

Validate 校验事件是否合法

func (*Event) WithContext added in v0.3.4

func (e *Event) WithContext(ctx context.Context)

WithContext 添加上下文

type Header struct {
	Source string            `bson:"source" json:"source"` // 事件来源, 比如cmdb
	Level  Level             `bson:"level" json:"level"`   // 事件等级
	Label  map[string]string `bson:"label" json:"label"`   // 标签
	Meta   Meta              `bson:"meta" json:"meta"`     // 事件的元数据
}

Header todo

func NewHeader added in v0.4.0

func NewHeader() *Header

NewHeader todo

type Level

type Level uint

Level 事件基本

const (
	// Trace (trace)
	Trace Level = iota
	// Debug (debug)
	Debug
	// Info (info)
	Info
	// Warn (warn)
	Warn
	// Error (error)
	Error
	// Critical (critical)
	Critical
	// Disaster (disaster)
	Disaster
)

func ParseLevel added in v0.3.3

func ParseLevel(str string) (Level, error)

ParseLevel Parse Level from string

func (Level) Is added in v0.3.3

func (t Level) Is(target Level) bool

Is todo

func (Level) MarshalJSON added in v0.3.3

func (t Level) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (Level) String added in v0.3.3

func (t Level) String() string

String stringer

func (*Level) UnmarshalJSON added in v0.3.3

func (t *Level) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type Meta added in v0.3.3

type Meta interface {
	// Put associates the specified value with the specified key. If the map
	// previously contained a mapping for the key, the old value is replaced and
	// returned. The key can be expressed in dot-notation (e.g. x.y) to put a value
	// into a nested map.
	//
	// If you need insert keys containing dots then you must use bracket notation
	// to insert values (e.g. m[key] = value).
	Put(key string, value interface{}) (interface{}, error)
	// Delete deletes the given key from the map.
	Delete(key string) error
	// GetValue 获取值
	Get(key string) (interface{}, error)
}

Meta todo

type OperateEvent added in v0.4.0

type OperateEvent struct {
	OperateSession string      `bson:"operate_session" json:"operate_session"` // 回话ID
	OperateUser    string      `bson:"operate_user" json:"operate_user"`       // 操作人
	ResourceType   string      `bson:"resource_type" json:"resource_type"`     // 资源类型,
	ResourceUUID   string      `bson:"resource_uuid" json:"resource_uuid"`     // 资源UUID
	ResourceName   string      `bson:"resource_name" json:"resource_name"`     // 资源名称
	Action         string      `bson:"action" json:"action"`                   // 操作
	Data           interface{} `bson:"data" json:"data,omitempty"`             // 事件数据
}

OperateEvent 事件具体数据

func ParseOperateEventFromBytes added in v0.4.0

func ParseOperateEventFromBytes(data []byte) (*OperateEvent, error)

ParseOperateEventFromBytes todo

type StatusEvent added in v0.5.6

type StatusEvent struct {
	Reason       string      `bson:"reason" json:"reason,omitempty"`     // 触发原因, 比如 创建/删除/绑定/告警/恢复
	Message      string      `bson:"message" json:"message,omitempty"`   // 事件消息,
	ResourceType string      `bson:"resource_type" json:"resource_type"` // 资源类型,
	ResourceUUID string      `bson:"resource_uuid" json:"resource_uuid"` // 资源UUID
	ResourceName string      `bson:"resource_name" json:"resource_name"` // 资源名称
	Data         interface{} `bson:"data" json:"data,omitempty"`         // 事件数据
}

StatusEvent 事件具体数据

func ParseStatusEventFromBytes added in v0.5.7

func ParseStatusEventFromBytes(data []byte) (*StatusEvent, error)

ParseStatusEventFromBytes todo

type Type added in v0.4.0

type Type uint

Type 事件类型

const (
	// OperateEventType (operate) 资源操作事件
	OperateEventType Type = iota
	// StatusEventType (status) 告警事件
	StatusEventType
)

func ParseType added in v0.4.0

func ParseType(str string) (Type, error)

ParseType Parse Type from string

func (Type) Is added in v0.4.0

func (t Type) Is(target Type) bool

Is todo

func (Type) MarshalJSON added in v0.4.0

func (t Type) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (Type) String added in v0.4.0

func (t Type) String() string

String stringer

func (*Type) UnmarshalJSON added in v0.4.0

func (t *Type) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

Jump to

Keyboard shortcuts

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