mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
类型是onecloud的notifier增加webconsole的alert
This commit is contained in:
@@ -114,6 +114,11 @@ func GetNotifyTemplateConfig(ctx *alerting.EvalContext) monitor.NotificationTemp
|
||||
|
||||
// Notify sends the alert notification.
|
||||
func (oc *OneCloudNotifier) Notify(ctx *alerting.EvalContext, _ jsonutils.JSONObject) error {
|
||||
//onecloud 默认向webconsole发送消息
|
||||
if err := WebConsoleNotify(ctx, oc.Setting.UserIds); err != nil {
|
||||
log.Errorf("failed to send webconsole %s: %v", oc.GetNotifierId(), err)
|
||||
}
|
||||
|
||||
log.Infof("Sending alert notification %s to onecloud", ctx.GetRuleTitle())
|
||||
config := GetNotifyTemplateConfig(ctx)
|
||||
contentConfig := oc.buildContent(config)
|
||||
@@ -144,3 +149,24 @@ func (oc *OneCloudNotifier) Notify(ctx *alerting.EvalContext, _ jsonutils.JSONOb
|
||||
func (oc *OneCloudNotifier) buildContent(config monitor.NotificationTemplateConfig) *templates.TemplateConfig {
|
||||
return templates.NewTemplateConfig(config)
|
||||
}
|
||||
|
||||
func WebConsoleNotify(ctx *alerting.EvalContext, ids []string) error {
|
||||
log.Infof("Sending alert notification %s to webconsole", ctx.GetRuleTitle())
|
||||
config := GetNotifyTemplateConfig(ctx)
|
||||
contentConfig := templates.NewTemplateConfig(config)
|
||||
content, err := contentConfig.GenerateMarkdown()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "build content")
|
||||
}
|
||||
|
||||
msg := notify.SNotifyMessage{
|
||||
Uid: ids,
|
||||
ContactType: notify.NotifyByWebConsole,
|
||||
Topic: config.Title,
|
||||
Priority: notify.TNotifyPriority(config.Priority),
|
||||
Msg: content,
|
||||
Broadcast: true,
|
||||
}
|
||||
session := auth.GetAdminSession(ctx.Ctx, "", "")
|
||||
return notify.Notifications.Send(session, msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user