* comes from grafana/gel-app * remove transform plugin code * move __expr__ and -100 constants to expr pkg * set OrgID on request plugin context * use gtime for resample duration * in resample, rename "rule" to "window", use gtime for duration, parse duration before exec * remove gel entry from plugins-bundled/external.json which creates an empty array for plugins
34 lines
831 B
Go
34 lines
831 B
Go
package ngalert
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/grafana/grafana/pkg/expr"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
// validateAlertDefinition validates that the alert definition contains at least one alert query
|
|
// and that alert queries refer to existing datasources.
|
|
func (ng *AlertNG) validateAlertDefinition(alertDefinition *AlertDefinition, signedInUser *models.SignedInUser, skipCache bool) error {
|
|
if len(alertDefinition.Data) == 0 {
|
|
return fmt.Errorf("no queries or expressions are found")
|
|
}
|
|
|
|
for _, query := range alertDefinition.Data {
|
|
datasourceID, err := query.GetDatasource()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if datasourceID == expr.DatasourceID {
|
|
return nil
|
|
}
|
|
|
|
_, err = ng.DatasourceCache.GetDatasource(datasourceID, signedInUser, skipCache)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|