From 7284db0e5494e7ba423ad188cec953951ded637e Mon Sep 17 00:00:00 2001 From: Joseph Weigl Date: Wed, 4 Oct 2017 16:07:13 +0200 Subject: [PATCH] Fix empty message and toolong attribute names Use default state message if no message is provided by the user Slice attribute name to maximum of 50 chars --- pkg/services/alerting/notifiers/hipchat.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/services/alerting/notifiers/hipchat.go b/pkg/services/alerting/notifiers/hipchat.go index 757120db25b..c131b80c578 100644 --- a/pkg/services/alerting/notifiers/hipchat.go +++ b/pkg/services/alerting/notifiers/hipchat.go @@ -86,8 +86,12 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error { attributes := make([]map[string]interface{}, 0) for index, evt := range evalContext.EvalMatches { + metricName := evt.Metric + if len(metricName) > 50 { + metricName = metricName[:50] + } attributes = append(attributes, map[string]interface{}{ - "label": evt.Metric, + "label": metricName, "value": map[string]interface{}{ "label": strconv.FormatFloat(evt.Value.Float64, 'f', -1, 64), }, @@ -110,6 +114,11 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error { if evalContext.Rule.State != models.AlertStateOK { //dont add message when going back to alert state ok. message += " " + evalContext.Rule.Message } + + if len(message) < 1 { + message = evalContext.GetNotificationTitle() + " in state " + evalContext.GetStateModel().Text + } + //HipChat has a set list of colors var color string switch evalContext.Rule.State { @@ -153,6 +162,7 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error { hipUrl := fmt.Sprintf("%s/v2/room/%s/notification?auth_token=%s", this.Url, this.RoomId, this.ApiKey) data, _ := json.Marshal(&body) + this.log.Debug(string(data)) cmd := &models.SendWebhookSync{Url: hipUrl, Body: string(data)} if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {