@@ -15,18 +15,23 @@ import (
1515// NewEvent 实例
1616func NewEvent () * Event {
1717 return & Event {
18- Header : Header {
19- ID : xid .New ().String (),
20- Time : ftime .Now (),
21- Label : make (map [string ]string ),
22- },
18+ ID : xid .New ().String (),
19+ Time : ftime .Now (),
20+ Label : make (map [string ]string ),
2321 }
2422}
2523
2624// Event 事件数据结构
2725type Event struct {
28- Header
29- Body
26+ ID string `bson:"_id" json:"id"` // 事件ID
27+ Time ftime.Time `bson:"time" json:"time"` // 事件发生时间(毫秒)
28+ Source string `bson:"source" json:"source"` // 事件来源, 比如cmdb
29+ Level Level `bson:"level" json:"level"` // 事件等级
30+ Label map [string ]string `bson:"label" json:"label"` // 标签
31+ Meta Meta `bson:"meta" json:"meta"` // 事件的元数据
32+ Type Type `bson:"type" json:"type"` // 事件类型
33+ Body interface {} `bson:"body" json:"body"` // 事件数据
34+
3035 ctx context.Context
3136}
3237
@@ -40,24 +45,23 @@ func (e *Event) Context() context.Context {
4045 return e .ctx
4146}
4247
43- // Header 事件元数据
44- type Header struct {
45- ID string `bson:"_id" json:"id,omitempty"` // 事件ID
46- Time ftime.Time `bson:"time" json:"time,omitempty"` // 事件发生时间(毫秒)
47- Source string `bson:"source" json:"source,omitempty"` // 事件来源, 比如cmdb
48- Level Level `bson:"level" json:"level,omitempty"` // 事件等级
49- Label map [string ]string `bson:"label" json:"label,omitempty"` // 标签
50- Meta Meta `bson:"meta" json:"meta,omitempty"` // 事件的元数据
48+ // OperateEvent 事件具体数据
49+ type OperateEvent struct {
50+ ResourceType string `bson:"resource_type" json:"resource_type"` // 资源类型,
51+ ResourceUUID string `bson:"resource_uuid" json:"resource_uuid"` // 资源UUID
52+ ResourceName string `bson:"resource_name" json:"resource_name"` // 资源名称
53+ Action string `bson:"action" json:"action"` // 操作
54+ Data interface {} `bson:"data" json:"data,omitempty"` // 事件数据
5155}
5256
53- // Body 事件具体数据
54- type Body struct {
57+ // AlertEvent 事件具体数据
58+ type AlertEvent struct {
5559 Reason string `bson:"reason" json:"reason,omitempty"` // 触发原因, 比如 创建/删除/绑定/告警/恢复
5660 Message string `bson:"message" json:"message,omitempty"` // 事件消息,
5761 ResourceType string `bson:"resource_type" json:"resource_type"` // 资源类型,
5862 ResourceUUID string `bson:"resource_uuid" json:"resource_uuid"` // 资源UUID
5963 ResourceName string `bson:"resource_name" json:"resource_name"` // 资源名称
60- Data interface {} `bson:"data" json:"data,omitempty"` // 事件具体数据
64+ Data interface {} `bson:"data" json:"data,omitempty"` // 事件数据
6165}
6266
6367// Meta todo
0 commit comments