event

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 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"`     // 事件类型
	Source string            `bson:"source" json:"source"` // 事件来源, 比如cmdb
	Level  Level             `bson:"level" json:"level"`   // 事件等级
	Meta   map[string]string `bson:"label" json:"label"`   // 标签
	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(e *OperateEvent) *Event

NewOperateEvent 实例

func (*Event) Context added in v0.3.4

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

Context 返回事件的上下文

func (*Event) GetMeta added in v0.9.0

func (e *Event) GetMeta(key string) string

GetMeta 获取meta信息

func (*Event) ParseBody added in v0.4.0

func (e *Event) ParseBody() error

ParseBody todo

func (*Event) SetLevel added in v0.9.0

func (e *Event) SetLevel(l Level)

SetLevel 设置事件级别

func (*Event) SetMeta added in v0.9.0

func (e *Event) SetMeta(key, value string)

SetMeta 设置meta信息

func (*Event) SetSource added in v0.9.0

func (e *Event) SetSource(src string)

SetSource 设置事件来源

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 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 OperateEvent added in v0.4.0

type OperateEvent struct {
	Session      string      `bson:"session" json:"session"`             // 回话ID
	Account      string      `bson:"account" json:"account"`             // 操作人
	RequestID    string      `bson:"request_id" json:"request_id"`       // 请求ID
	IPAddress    string      `bson:"ip_address" json:"ip_address"`       // 操作者IP
	UserAgent    string      `bson:"user_agent" json:"user_agent"`       // 用户UA
	UserName     string      `bson:"user_name" json:"user_name"`         // 用户名称
	UserType     string      `bson:"user_type" json:"user_type"`         // 用户类型
	UserDomain   string      `bson:"user_domain" json:"user_domain"`     // 操作的域
	ServiceName  string      `bson:"service_name" json:"service_name"`   // 服务名称
	FeaturePath  string      `bson:"feature_path" json:"feature_path"`   // 功能路径
	ResourceType string      `bson:"resource_type" json:"resource_type"` // 资源类型
	Action       string      `bson:"action" json:"action"`               // 操作动作
	Request      interface{} `bson:"request" json:"request,omitempty"`   // 事件数据
	Response     interface{} `bson:"response" json:"response,omitempty"` // 事件数据
}

OperateEvent 事件具体数据

func ParseOperateEventFromBytes added in v0.4.0

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

ParseOperateEventFromBytes 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