mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 03:11:01 -06:00
43b15b92ad
* propagate notificationservice down to the notifiers * replace dispatch in result handler * remove dispatch from the rule reader * remove dispatch from eval context * remove dispatch from alerting usage * remove dispatch from alerting usage * remove dispatch from notifier * attempt to fix tests in alerting * hello linter, my old friend; also disable some tests for now * use mocks to fix the tests * resolving wire providers * make linter happy * remove yet another bus.dispatch * fix tests using store mock
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package alerting
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
// AlertTest makes a test alert.
|
|
func (e *AlertEngine) AlertTest(orgID int64, dashboard *simplejson.Json, panelID int64, user *models.SignedInUser) (*EvalContext, error) {
|
|
dash := models.NewDashboardFromJson(dashboard)
|
|
|
|
extractor := NewDashAlertExtractor(dash, orgID, user)
|
|
alerts, err := extractor.GetAlerts(context.Background())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, alert := range alerts {
|
|
if alert.PanelId != panelID {
|
|
continue
|
|
}
|
|
rule, err := NewRuleFromDBAlert(context.Background(), alert, true)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
handler := NewEvalHandler(e.DataService)
|
|
|
|
context := NewEvalContext(context.Background(), rule, fakeRequestValidator{}, nil)
|
|
context.IsTestRun = true
|
|
context.IsDebug = true
|
|
|
|
handler.Eval(context)
|
|
context.Rule.State = context.GetNewState()
|
|
return context, nil
|
|
}
|
|
|
|
return nil, fmt.Errorf("could not find alert with panel ID %d", panelID)
|
|
}
|