mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 20:50:06 +00:00
implement notification group (#450)
* implement notification group * some fixes * fix sql * add listNotification * retrieve notification from map * create notification_group_notification if non-exist * NotificationIDToGroup -> NotificationIDToGroups * clean
This commit is contained in:
@@ -173,16 +173,7 @@ func (ma *memberAPI) delete(c *gin.Context) {
|
||||
|
||||
var err error
|
||||
switch c.Param("model") {
|
||||
case "notification":
|
||||
err = singleton.DB.Unscoped().Delete(&model.Notification{}, "id = ?", id).Error
|
||||
if err == nil {
|
||||
singleton.OnDeleteNotification(id)
|
||||
}
|
||||
case "ddns":
|
||||
err = singleton.DB.Unscoped().Delete(&model.DDNSProfile{}, "id = ?", id).Error
|
||||
if err == nil {
|
||||
singleton.OnDDNSUpdate()
|
||||
}
|
||||
|
||||
case "nat":
|
||||
err = singleton.DB.Unscoped().Delete(&model.NAT{}, "id = ?", id).Error
|
||||
if err == nil {
|
||||
@@ -224,13 +215,13 @@ func (ma *memberAPI) delete(c *gin.Context) {
|
||||
}
|
||||
|
||||
type monitorForm struct {
|
||||
ID uint64
|
||||
Name string
|
||||
Target string
|
||||
Type uint8
|
||||
Cover uint8
|
||||
Notify string
|
||||
NotificationTag string
|
||||
ID uint64
|
||||
Name string
|
||||
Target string
|
||||
Type uint8
|
||||
Cover uint8
|
||||
Notify string
|
||||
//NotificationTag string
|
||||
SkipServersRaw string
|
||||
Duration uint64
|
||||
MinLatency float32
|
||||
@@ -254,7 +245,7 @@ func (ma *memberAPI) addOrEditMonitor(c *gin.Context) {
|
||||
m.SkipServersRaw = mf.SkipServersRaw
|
||||
m.Cover = mf.Cover
|
||||
m.Notify = mf.Notify == "on"
|
||||
m.NotificationTag = mf.NotificationTag
|
||||
//m.NotificationTag = mf.NotificationTag
|
||||
m.Duration = mf.Duration
|
||||
m.LatencyNotify = mf.LatencyNotify == "on"
|
||||
m.MinLatency = mf.MinLatency
|
||||
@@ -267,9 +258,9 @@ func (ma *memberAPI) addOrEditMonitor(c *gin.Context) {
|
||||
}
|
||||
if err == nil {
|
||||
// 保证NotificationTag不为空
|
||||
if m.NotificationTag == "" {
|
||||
m.NotificationTag = "default"
|
||||
}
|
||||
//if m.NotificationTag == "" {
|
||||
// m.NotificationTag = "default"
|
||||
//}
|
||||
err = utils.Json.Unmarshal([]byte(mf.FailTriggerTasksRaw), &m.FailTriggerTasks)
|
||||
}
|
||||
if err == nil {
|
||||
@@ -327,7 +318,7 @@ func (ma *memberAPI) addOrEditCron(c *gin.Context) {
|
||||
cr.Command = cf.Command
|
||||
cr.ServersRaw = cf.ServersRaw
|
||||
cr.PushSuccessful = cf.PushSuccessful == "on"
|
||||
cr.NotificationTag = cf.NotificationTag
|
||||
//cr.NotificationTag = cf.NotificationTag
|
||||
cr.ID = cf.ID
|
||||
cr.Cover = cf.Cover
|
||||
err = utils.Json.Unmarshal([]byte(cf.ServersRaw), &cr.Servers)
|
||||
@@ -346,9 +337,9 @@ func (ma *memberAPI) addOrEditCron(c *gin.Context) {
|
||||
tx := singleton.DB.Begin()
|
||||
if err == nil {
|
||||
// 保证NotificationTag不为空
|
||||
if cr.NotificationTag == "" {
|
||||
cr.NotificationTag = "default"
|
||||
}
|
||||
//if cr.NotificationTag == "" {
|
||||
// cr.NotificationTag = "default"
|
||||
//}
|
||||
if cf.ID == 0 {
|
||||
err = tx.Create(&cr).Error
|
||||
} else {
|
||||
@@ -507,7 +498,6 @@ func (ma *memberAPI) forceUpdate(c *gin.Context) {
|
||||
type notificationForm struct {
|
||||
ID uint64
|
||||
Name string
|
||||
Tag string // 分组名
|
||||
URL string
|
||||
RequestMethod int
|
||||
RequestType int
|
||||
@@ -523,7 +513,6 @@ func (ma *memberAPI) addOrEditNotification(c *gin.Context) {
|
||||
err := c.ShouldBindJSON(&nf)
|
||||
if err == nil {
|
||||
n.Name = nf.Name
|
||||
n.Tag = nf.Tag
|
||||
n.RequestMethod = nf.RequestMethod
|
||||
n.RequestType = nf.RequestType
|
||||
n.RequestHeader = nf.RequestHeader
|
||||
@@ -543,10 +532,6 @@ func (ma *memberAPI) addOrEditNotification(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
// 保证Tag不为空
|
||||
if n.Tag == "" {
|
||||
n.Tag = "default"
|
||||
}
|
||||
if n.ID == 0 {
|
||||
err = singleton.DB.Create(&n).Error
|
||||
} else {
|
||||
@@ -730,7 +715,7 @@ func (ma *memberAPI) addOrEditAlertRule(c *gin.Context) {
|
||||
r.RulesRaw = arf.RulesRaw
|
||||
r.FailTriggerTasksRaw = arf.FailTriggerTasksRaw
|
||||
r.RecoverTriggerTasksRaw = arf.RecoverTriggerTasksRaw
|
||||
r.NotificationTag = arf.NotificationTag
|
||||
//r.NotificationTag = arf.NotificationTag
|
||||
enable := arf.Enable == "on"
|
||||
r.TriggerMode = arf.TriggerMode
|
||||
r.Enable = &enable
|
||||
@@ -744,9 +729,9 @@ func (ma *memberAPI) addOrEditAlertRule(c *gin.Context) {
|
||||
}
|
||||
//保证NotificationTag不为空
|
||||
if err == nil {
|
||||
if r.NotificationTag == "" {
|
||||
r.NotificationTag = "default"
|
||||
}
|
||||
//if r.NotificationTag == "" {
|
||||
// r.NotificationTag = "default"
|
||||
//}
|
||||
if r.ID == 0 {
|
||||
err = singleton.DB.Create(&r).Error
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user