Skip to content

Commit

Permalink
类型是onecloud的notifier增加webconsole的alert
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoxiangchun committed May 27, 2020
1 parent 6c87cd3 commit 0a7b381
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/monitor/alerting/notifiers/onecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

0 comments on commit 0a7b381

Please sign in to comment.