Ejemplo n.º 1
0
func (this *WebhookNotifier) Notify(context *alerting.EvalContext) {
	this.log.Info("Sending webhook")
	metrics.M_Alerting_Notification_Sent_Webhook.Inc(1)

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

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

	imageUrl, err := context.GetImageUrl()
	if err == nil {
		bodyJSON.Set("image_url", imageUrl)
	}

	body, _ := bodyJSON.MarshalJSON()

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

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