mirror of
https://github.com/grafana/grafana.git
synced 2025-01-17 12:03:26 -06:00
63b2dd06a5
When, and currently only when using a classic condition, evaluation information is added (which is like the EvalMatches from dashboard alerting). This is returned via the API and can be included in notifications by reading the `__value__` label attached `.Alerts` in the template. It is a string.
33 lines
1.0 KiB
Go
33 lines
1.0 KiB
Go
package schedule
|
|
|
|
import (
|
|
"github.com/go-openapi/strfmt"
|
|
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
|
"github.com/prometheus/alertmanager/api/v2/models"
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
|
"github.com/grafana/grafana/pkg/services/ngalert/state"
|
|
)
|
|
|
|
func FromAlertStateToPostableAlerts(firingStates []*state.State) apimodels.PostableAlerts {
|
|
alerts := apimodels.PostableAlerts{PostableAlerts: make([]models.PostableAlert, 0, len(firingStates))}
|
|
|
|
for _, alertState := range firingStates {
|
|
if alertState.State == eval.Alerting {
|
|
nL := alertState.Labels.Copy()
|
|
if len(alertState.Results) > 0 {
|
|
nL["__value__"] = alertState.Results[0].EvaluationString
|
|
}
|
|
alerts.PostableAlerts = append(alerts.PostableAlerts, models.PostableAlert{
|
|
Annotations: alertState.Annotations,
|
|
StartsAt: strfmt.DateTime(alertState.StartsAt),
|
|
EndsAt: strfmt.DateTime(alertState.EndsAt),
|
|
Alert: models.Alert{
|
|
Labels: models.LabelSet(nL),
|
|
},
|
|
})
|
|
}
|
|
}
|
|
return alerts
|
|
}
|