The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/services/ngalert/validator.go

34 lines
831 B

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
}