类型是onecloud的notifier增加webconsole的alert

This commit is contained in:
zhaoxiangchun
2020-05-22 12:07:11 +08:00
parent fb4206d904
commit 62fe7d977d
@@ -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)
}