当前位置: 首页>>代码示例>>Golang>>正文


Golang EvalContext.GetNotificationTitle方法代码示例

本文整理汇总了Golang中github.com/grafana/grafana/pkg/services/alerting.EvalContext.GetNotificationTitle方法的典型用法代码示例。如果您正苦于以下问题:Golang EvalContext.GetNotificationTitle方法的具体用法?Golang EvalContext.GetNotificationTitle怎么用?Golang EvalContext.GetNotificationTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/grafana/grafana/pkg/services/alerting.EvalContext的用法示例。


在下文中一共展示了EvalContext.GetNotificationTitle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Notify

func (this *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
	this.log.Info("Sending alert notification to", "bot_token", this.BotToken)
	this.log.Info("Sending alert notification to", "chat_id", this.ChatID)
	metrics.M_Alerting_Notification_Sent_Telegram.Inc(1)

	bodyJSON := simplejson.New()

	bodyJSON.Set("chat_id", this.ChatID)
	bodyJSON.Set("parse_mode", "html")

	message := fmt.Sprintf("%s\nState: %s\nMessage: %s\n", evalContext.GetNotificationTitle(), evalContext.Rule.Name, evalContext.Rule.Message)

	ruleUrl, err := evalContext.GetRuleUrl()
	if err == nil {
		message = message + fmt.Sprintf("URL: %s\n", ruleUrl)
	}
	bodyJSON.Set("text", message)

	url := fmt.Sprintf(telegeramApiUrl, this.BotToken, "sendMessage")
	body, _ := bodyJSON.MarshalJSON()

	cmd := &m.SendWebhookSync{
		Url:        url,
		Body:       string(body),
		HttpMethod: "POST",
	}

	if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
		this.log.Error("Failed to send webhook", "error", err, "webhook", this.Name)
		return err
	}

	return nil
}
开发者ID:yuvaraj951,项目名称:grafana,代码行数:34,代码来源:telegram.go

示例2: Notify

func (this *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error {
	this.log.Info("Sending webhook")
	metrics.M_Alerting_Notification_Sent_Webhook.Inc(1)

	bodyJSON := simplejson.New()
	bodyJSON.Set("title", evalContext.GetNotificationTitle())
	bodyJSON.Set("ruleId", evalContext.Rule.Id)
	bodyJSON.Set("ruleName", evalContext.Rule.Name)
	bodyJSON.Set("state", evalContext.Rule.State)
	bodyJSON.Set("evalMatches", evalContext.EvalMatches)

	ruleUrl, err := evalContext.GetRuleUrl()
	if err == nil {
		bodyJSON.Set("rule_url", ruleUrl)
	}

	if evalContext.ImagePublicUrl != "" {
		bodyJSON.Set("image_url", evalContext.ImagePublicUrl)
	}

	body, _ := bodyJSON.MarshalJSON()

	cmd := &m.SendWebhookSync{
		Url:      this.Url,
		User:     this.User,
		Password: this.Password,
		Body:     string(body),
	}

	if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
		this.log.Error("Failed to send webhook", "error", err, "webhook", this.Name)
	}

	return nil
}
开发者ID:roman-vynar,项目名称:grafana,代码行数:35,代码来源:webhook.go

示例3: Notify

func (this *EmailNotifier) Notify(context *alerting.EvalContext) {
	this.log.Info("Sending alert notification to", "addresses", this.Addresses)
	metrics.M_Alerting_Notification_Sent_Email.Inc(1)

	ruleUrl, err := context.GetRuleUrl()
	if err != nil {
		this.log.Error("Failed get rule link", "error", err)
		return
	}

	cmd := &m.SendEmailCommand{
		Data: map[string]interface{}{
			"Title":        context.GetNotificationTitle(),
			"State":        context.Rule.State,
			"Name":         context.Rule.Name,
			"StateModel":   context.GetStateModel(),
			"Message":      context.Rule.Message,
			"RuleUrl":      ruleUrl,
			"ImageLink":    context.ImagePublicUrl,
			"AlertPageUrl": setting.AppUrl + "alerting",
			"EvalMatches":  context.EvalMatches,
		},
		To:       this.Addresses,
		Template: "alert_notification.html",
	}

	if err := bus.Dispatch(cmd); err != nil {
		this.log.Error("Failed to send alert notification email", "error", err)
	}
}
开发者ID:replay,项目名称:grafana,代码行数:30,代码来源:email.go

示例4: Notify

func (this *EmailNotifier) Notify(evalContext *alerting.EvalContext) error {
	this.log.Info("Sending alert notification to", "addresses", this.Addresses)
	metrics.M_Alerting_Notification_Sent_Email.Inc(1)

	ruleUrl, err := evalContext.GetRuleUrl()
	if err != nil {
		this.log.Error("Failed get rule link", "error", err)
		return err
	}

	cmd := &m.SendEmailCommandSync{
		SendEmailCommand: m.SendEmailCommand{
			Subject: evalContext.GetNotificationTitle(),
			Data: map[string]interface{}{
				"Title":        evalContext.GetNotificationTitle(),
				"State":        evalContext.Rule.State,
				"Name":         evalContext.Rule.Name,
				"StateModel":   evalContext.GetStateModel(),
				"Message":      evalContext.Rule.Message,
				"RuleUrl":      ruleUrl,
				"ImageLink":    "",
				"EmbededImage": "",
				"AlertPageUrl": setting.AppUrl + "alerting",
				"EvalMatches":  evalContext.EvalMatches,
			},
			To:           this.Addresses,
			Template:     "alert_notification.html",
			EmbededFiles: []string{},
		},
	}

	if evalContext.ImagePublicUrl != "" {
		cmd.Data["ImageLink"] = evalContext.ImagePublicUrl
	} else {
		file, err := os.Stat(evalContext.ImageOnDiskPath)
		if err == nil {
			cmd.EmbededFiles = []string{evalContext.ImageOnDiskPath}
			cmd.Data["EmbededImage"] = file.Name()
		}
	}

	err = bus.DispatchCtx(evalContext.Ctx, cmd)

	if err != nil {
		this.log.Error("Failed to send alert notification email", "error", err)
		return err
	}
	return nil

}
开发者ID:mapr,项目名称:grafana,代码行数:50,代码来源:email.go

示例5: Notify

func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
	this.log.Info("Executing slack notification", "ruleId", evalContext.Rule.Id, "notification", this.Name)
	metrics.M_Alerting_Notification_Sent_Slack.Inc(1)

	ruleUrl, err := evalContext.GetRuleUrl()
	if err != nil {
		this.log.Error("Failed get rule link", "error", err)
		return err
	}

	fields := make([]map[string]interface{}, 0)
	fieldLimitCount := 4
	for index, evt := range evalContext.EvalMatches {
		fields = append(fields, map[string]interface{}{
			"title": evt.Metric,
			"value": evt.Value,
			"short": true,
		})
		if index > fieldLimitCount {
			break
		}
	}

	if evalContext.Error != nil {
		fields = append(fields, map[string]interface{}{
			"title": "Error message",
			"value": evalContext.Error.Error(),
			"short": false,
		})
	}

	message := ""
	if evalContext.Rule.State != m.AlertStateOK { //dont add message when going back to alert state ok.
		message = evalContext.Rule.Message
	}

	body := map[string]interface{}{
		"attachments": []map[string]interface{}{
			{
				"color":       evalContext.GetStateModel().Color,
				"title":       evalContext.GetNotificationTitle(),
				"title_link":  ruleUrl,
				"text":        message,
				"fields":      fields,
				"image_url":   evalContext.ImagePublicUrl,
				"footer":      "Grafana v" + setting.BuildVersion,
				"footer_icon": "http://grafana.org/assets/img/fav32.png",
				"ts":          time.Now().Unix(),
			},
		},
	}

	data, _ := json.Marshal(&body)
	cmd := &m.SendWebhookSync{Url: this.Url, Body: string(data)}

	if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
		this.log.Error("Failed to send slack notification", "error", err, "webhook", this.Name)
	}

	return nil
}
开发者ID:sbouchex,项目名称:grafana,代码行数:61,代码来源:slack.go

示例6: Notify

func (this *SlackNotifier) Notify(context *alerting.EvalContext) {
	this.log.Info("Executing slack notification", "ruleId", context.Rule.Id, "notification", this.Name)
	metrics.M_Alerting_Notification_Sent_Slack.Inc(1)

	ruleUrl, err := context.GetRuleUrl()
	if err != nil {
		this.log.Error("Failed get rule link", "error", err)
		return
	}

	fields := make([]map[string]interface{}, 0)
	fieldLimitCount := 4
	for index, evt := range context.EvalMatches {
		fields = append(fields, map[string]interface{}{
			"title": evt.Metric,
			"value": evt.Value,
			"short": true,
		})
		if index > fieldLimitCount {
			break
		}
	}

	if context.Error != nil {
		fields = append(fields, map[string]interface{}{
			"title": "Error message",
			"value": context.Error.Error(),
			"short": false,
		})
	}

	message := ""
	if context.Rule.State != m.AlertStateOK { //dont add message when going back to alert state ok.
		message = context.Rule.Message
	}

	body := map[string]interface{}{
		"attachments": []map[string]interface{}{
			{
				"color":       context.GetStateModel().Color,
				"title":       context.GetNotificationTitle(),
				"title_link":  ruleUrl,
				"text":        message,
				"fields":      fields,
				"image_url":   context.ImagePublicUrl,
				"footer":      "Grafana v" + setting.BuildVersion,
				"footer_icon": "http://grafana.org/assets/img/fav32.png",
				"ts":          time.Now().Unix(),
				//"pretext":     "Optional text that appears above the attachment block",
				// "author_name": "Bobby Tables",
				// "author_link": "http://flickr.com/bobby/",
				// "author_icon": "http://flickr.com/icons/bobby.jpg",
				// "thumb_url":   "http://example.com/path/to/thumb.png",
			},
		},
	}

	data, _ := json.Marshal(&body)
	cmd := &m.SendWebhook{Url: this.Url, Body: string(data)}

	if err := bus.Dispatch(cmd); err != nil {
		this.log.Error("Failed to send slack notification", "error", err, "webhook", this.Name)
	}
}
开发者ID:replay,项目名称:grafana,代码行数:64,代码来源:slack.go


注:本文中的github.com/grafana/grafana/pkg/services/alerting.EvalContext.GetNotificationTitle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。