mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Initial commit for state tracking * basic state transition logic and tests * constructor. test and interface fixup * use new sig for sch.definitionRoutine() * test fixup * make the linter happy * more minor linting cleanup * Alerting: Send alerts from state tracker to notifier * Add evaluation time and test Add evaluation time and test * Add cleanup routine and logging * Pull in compact.go and reconcile differences * Save alert transitions and save all state on shutdown * pr feedback * WIP * WIP * Persist alerts on evaluation and shutdown. Warm cache on startup * Filter non-firing alerts before sending to notifier Co-authored-by: Josue Abreu <josue@grafana.com>
29 lines
1.0 KiB
Go
29 lines
1.0 KiB
Go
package schedule
|
|
|
|
import (
|
|
"github.com/go-openapi/strfmt"
|
|
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
|
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
|
|
"github.com/grafana/grafana/pkg/services/ngalert/state"
|
|
"github.com/prometheus/alertmanager/api/v2/models"
|
|
)
|
|
|
|
func FromAlertStateToPostableAlerts(firingStates []state.AlertState) []*notifier.PostableAlert {
|
|
alerts := make([]*notifier.PostableAlert, 0, len(firingStates))
|
|
for _, alertState := range firingStates {
|
|
if alertState.State == eval.Alerting {
|
|
alerts = append(alerts, ¬ifier.PostableAlert{
|
|
PostableAlert: models.PostableAlert{
|
|
Annotations: models.LabelSet{}, //TODO: add annotations to evaluation results, add them to the alertState struct, and then set them before sending to the notifier
|
|
StartsAt: strfmt.DateTime(alertState.StartsAt),
|
|
EndsAt: strfmt.DateTime(alertState.EndsAt),
|
|
Alert: models.Alert{
|
|
Labels: models.LabelSet(alertState.Labels),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
}
|
|
return alerts
|
|
}
|