mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-05 21:20:06 +00:00
🐛 fix(alert): 添加报警规则
This commit is contained in:
@@ -30,17 +30,19 @@ type NotificationHistory struct {
|
||||
|
||||
func Start() {
|
||||
alertsStore = make(map[uint64]map[uint64][][]interface{})
|
||||
notificationsLock.Lock()
|
||||
if err := dao.DB.Find(¬ifications).Error; err != nil {
|
||||
panic(err)
|
||||
}
|
||||
notificationsLock.Unlock()
|
||||
alertsLock.Lock()
|
||||
if err := dao.DB.Find(&alerts).Error; err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := dao.DB.Find(¬ifications).Error; err != nil {
|
||||
panic(err)
|
||||
}
|
||||
alertsLock.Unlock()
|
||||
for i := 0; i < len(alerts); i++ {
|
||||
alertsStore[alerts[i].ID] = make(map[uint64][][]interface{})
|
||||
}
|
||||
alertsLock.Unlock()
|
||||
|
||||
time.Sleep(time.Second * 10)
|
||||
go checkStatus()
|
||||
@@ -50,11 +52,16 @@ func OnRefreshOrAddAlert(alert model.AlertRule) {
|
||||
alertsLock.Lock()
|
||||
defer alertsLock.Unlock()
|
||||
delete(alertsStore, alert.ID)
|
||||
var isEdit bool
|
||||
for i := 0; i < len(alerts); i++ {
|
||||
if alerts[i].ID == alert.ID {
|
||||
alerts[i] = alert
|
||||
isEdit = true
|
||||
}
|
||||
}
|
||||
if !isEdit {
|
||||
alerts = append(alerts, alert)
|
||||
}
|
||||
alertsStore[alert.ID] = make(map[uint64][][]interface{})
|
||||
}
|
||||
|
||||
@@ -72,11 +79,16 @@ func OnDeleteAlert(id uint64) {
|
||||
func OnRefreshOrAddNotification(n model.Notification) {
|
||||
notificationsLock.Lock()
|
||||
defer notificationsLock.Unlock()
|
||||
var isEdit bool
|
||||
for i := 0; i < len(notifications); i++ {
|
||||
if notifications[i].ID == n.ID {
|
||||
notifications[i] = n
|
||||
isEdit = true
|
||||
}
|
||||
}
|
||||
if !isEdit {
|
||||
notifications = append(notifications, n)
|
||||
}
|
||||
}
|
||||
|
||||
func OnDeleteNotification(id uint64) {
|
||||
|
||||
Reference in New Issue
Block a user