Alerting notifier SensuGo: improvements in default message (#31428)

* add related metrics as default message

* fix CI linter error
This commit is contained in:
M4t3o 2021-02-25 10:52:34 +01:00 committed by GitHub
parent 584886fa46
commit 0bb4cbdb68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ import (
"fmt"
"strconv"
"strings"
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
@ -111,6 +112,11 @@ func (sn *SensuGoNotifier) Notify(evalContext *alerting.EvalContext) error {
var namespace string
customData := triggMetrString
for _, evt := range evalContext.EvalMatches {
customData += fmt.Sprintf("%s: %v\n", evt.Metric, evt.Value)
}
bodyJSON := simplejson.New()
// Sensu Go alerts require an entity and a check. We set it to the user-specified
// value (optional), else we fallback and use the grafana rule anme and ruleID.
@ -134,12 +140,14 @@ func (sn *SensuGoNotifier) Notify(evalContext *alerting.EvalContext) error {
bodyJSON.SetPath([]string{"entity", "metadata", "namespace"}, "default")
namespace = "default"
}
// Sensu Go needs check output
// Sensu Go needs check output, triggered metrics as default value
if evalContext.Rule.Message != "" {
bodyJSON.SetPath([]string{"check", "output"}, evalContext.Rule.Message)
} else {
bodyJSON.SetPath([]string{"check", "output"}, "Grafana Metric Condition Met")
bodyJSON.SetPath([]string{"check", "output"}, customData)
}
// Add timestamp detail in event
bodyJSON.SetPath([]string{"check", "issued"}, time.Now().Unix())
// Sensu GO requires that the check portion of the event have an interval
bodyJSON.SetPath([]string{"check", "interval"}, 86400)