Skip to content

Commit

Permalink
refactor: update notify channel api (#2508)
Browse files Browse the repository at this point in the history
  • Loading branch information
710leo authored Mar 5, 2025
1 parent 0166405 commit 52b7890
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions alert/dispatch/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ func (e *Dispatch) HandleEventNotify(event *models.AlertCurEvent, isSubscribe bo
return
}

if len(rule.NotifyRuleIds) > 0 {
event.NotifyRuleIDs = rule.NotifyRuleIds
}

if e.blockEventNotify(rule, event) {
logger.Infof("block event notify: rule_id:%d event:%+v", rule.Id, event)
return
Expand Down
2 changes: 1 addition & 1 deletion center/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (rt *Router) Config(r *gin.Engine) {
pages.GET("/notify-channel-configs", rt.auth(), rt.user(), rt.perm("/notification-channels"), rt.notifyChannelsGet)
pages.GET("/simplified-notify-channel-configs", rt.notifyChannelsGetForNormalUser)
pages.GET("/flashduty-channel-list/:id", rt.auth(), rt.user(), rt.flashDutyNotifyChannelsGet)
pages.GET("/notify-channel-config", rt.auth(), rt.user(), rt.perm("/notification-channels"), rt.notifyChannelGetBy)
pages.GET("/notify-channel-config", rt.auth(), rt.user(), rt.notifyChannelGetBy)
}

r.GET("/api/n9e/versions", func(c *gin.Context) {
Expand Down
3 changes: 3 additions & 0 deletions center/router/router_notify_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (rt *Router) notifyChannelGetBy(c *gin.Context) {
ginx.Bomb(http.StatusNotFound, "notify channel not found")
}

nc.ParamConfig = &models.NotifyParamConfig{}
nc.RequestConfig = &models.RequestConfig{}

ginx.NewRender(c).Data(nc, nil)
}

Expand Down
8 changes: 4 additions & 4 deletions center/router/router_notify_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (rt *Router) notifyRuleGet(c *gin.Context) {
}

func (rt *Router) notifyRulesGetByService(c *gin.Context) {
ginx.NewRender(c).Data(models.NotifyRulesGet(rt.Ctx, "", nil))
ginx.NewRender(c).Data(models.NotifyRulesGet(rt.Ctx, "enable = ?", "true"))
}

func (rt *Router) notifyRulesGet(c *gin.Context) {
Expand Down Expand Up @@ -193,7 +193,7 @@ func (rt *Router) notifyTest(c *gin.Context) {
}
}
logger.Infof("channel_name: %v, event:%+v, tplContent:%s, customParams:%v, respBody: %v, err: %v", notifyChannel.Name, events[0], tplContent, customParams, resp, err)
ginx.NewRender(c).Message(err)
ginx.NewRender(c).Data(resp, err)
case "http":
client, err := models.GetHTTPClient(notifyChannel)
ginx.Dangerous(err)
Expand All @@ -214,15 +214,15 @@ func (rt *Router) notifyTest(c *gin.Context) {
if err != nil {
logger.Errorf("failed to send http notify: %v", err)
}
ginx.NewRender(c).Message(err)
ginx.NewRender(c).Data(resp, err)
}
case "smtp":
err := notifyChannel.SendEmail2(events, tplContent, userInfos)
ginx.NewRender(c).Message(err)
case "script":
resp, _, err := notifyChannel.SendScript(events, tplContent, customParams, userInfos)
logger.Infof("channel_name: %v, event:%+v, tplContent:%s, customParams:%v, respBody: %v, err: %v", notifyChannel.Name, events[0], tplContent, customParams, resp, err)
ginx.NewRender(c).Message(err)
ginx.NewRender(c).Data(resp, err)
default:
logger.Errorf("unsupported request type: %v", notifyChannel.RequestType)
ginx.NewRender(c).Message(errors.New("unsupported request type"))
Expand Down

0 comments on commit 52b7890

Please sign in to comment.