Просмотр исходного кода

Add values to the hipchat card

Joseph Weigl 8 лет назад
Родитель
Сommit
9666f45e9c
1 измененных файлов с 16 добавлено и 15 удалено
  1. 16 15
      pkg/services/alerting/notifiers/hipchat.go

+ 16 - 15
pkg/services/alerting/notifiers/hipchat.go

@@ -84,15 +84,13 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
 		return err
 	}
 
-	message := evalContext.GetNotificationTitle() + " in state " + evalContext.GetStateModel().Text + "<br><a href=" + ruleUrl + ">Check Dasboard</a>"
-	fields := make([]map[string]interface{}, 0)
-	message += "<br>"
+	attributes := make([]map[string]interface{}, 0)
 	for index, evt := range evalContext.EvalMatches {
-		message += evt.Metric + " :: " + strconv.FormatFloat(evt.Value.Float64, 'f', -1, 64) + "<br>"
-		fields = append(fields, map[string]interface{}{
-			"title": evt.Metric,
-			"value": evt.Value,
-			"short": true,
+		attributes = append(attributes, map[string]interface{}{
+			"label": evt.Metric,
+			"value": map[string]interface{}{
+				"label": strconv.FormatFloat(evt.Value.Float64, 'f', -1, 64),
+			},
 		})
 		if index > maxFieldCount {
 			break
@@ -100,13 +98,15 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
 	}
 
 	if evalContext.Error != nil {
-		fields = append(fields, map[string]interface{}{
-			"title": "Error message",
-			"value": evalContext.Error.Error(),
-			"short": false,
+		attributes = append(attributes, map[string]interface{}{
+			"label": "Error message",
+			"value": map[string]interface{}{
+				"label": evalContext.Error.Error(),
+			},
 		})
 	}
 
+	message := ""
 	if evalContext.Rule.State != models.AlertStateOK { //dont add message when going back to alert state ok.
 		message += " " + evalContext.Rule.Message
 	}
@@ -123,15 +123,16 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
 
 	// Add a card with link to the dashboard
 	card := map[string]interface{}{
-		"style":       "link",
+		"style":       "application",
 		"url":         ruleUrl,
 		"id":          "1",
 		"title":       evalContext.GetNotificationTitle(),
-		"description": evalContext.GetNotificationTitle() + " in state " + evalContext.GetStateModel().Text,
+		"description": message,
 		"icon": map[string]interface{}{
 			"url": "https://grafana.com/assets/img/fav32.png",
 		},
-		"date": evalContext.EndTime.Unix(),
+		"date":       evalContext.EndTime.Unix(),
+		"attributes": attributes,
 	}
 
 	body := map[string]interface{}{