/
notice.go
59 lines (52 loc) · 1.96 KB
/
notice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package notices
import (
"fmt"
"github.com/TeaWeb/code/teadb/shared"
"hash/crc32"
"time"
)
// 通知
type Notice struct {
Id shared.ObjectId `bson:"_id" json:"id"` // 数据库存储的ID
Proxy ProxyCond `bson:"proxy" json:"proxy"` // 代理相关参数
Agent AgentCond `bson:"agent" json:"agent"` // 主机相关参数
Timestamp int64 `bson:"timestamp" json:"timestamp"` // 时间戳
Message string `bson:"message" json:"message"` // 消息内容
MessageHash string `bson:"messageHash" json:"messageHash"` // 消息内容Hash:crc32(message)
IsRead bool `bson:"isRead" json:"isRead"` // 已读
IsNotified bool `bson:"isNotified" json:"isNotified"` // 是否发送通知
Receivers []string `bson:"receivers" json:"receivers"` // 接收人ID列表
}
// Proxy条件
type ProxyCond struct {
ServerId string `bson:"serverId" json:"serverId"`
Websocket bool `bson:"websocket" json:"websocket"`
LocationId string `bson:"locationId" json:"serverId"`
RewriteId string `bson:"rewriteId" json:"serverId"`
BackendId string `bson:"backendId" json:"serverId"`
FastcgiId string `bson:"fastcgiId" json:"serverId"`
Level uint8 `bson:"level" json:"level"`
}
// Agent条件
type AgentCond struct {
AgentId string `bson:"agentId" json:"agentId"`
AppId string `bson:"appId" json:"appId"`
TaskId string `bson:"taskId" json:"taskId"`
ItemId string `bson:"itemId" json:"itemId"`
Level uint8 `bson:"level" json:"level"`
Threshold string `bson:"threshold" json:"threshold"`
}
// 获取通知对象
func NewNotice() *Notice {
return &Notice{
Id: shared.NewObjectId(),
}
}
// 设置时间
func (this *Notice) SetTime(t time.Time) {
this.Timestamp = time.Now().Unix()
}
// 计算Hash
func (this *Notice) Hash() {
this.MessageHash = fmt.Sprintf("%d", crc32.ChecksumIEEE([]byte(this.Message)))
}