2021-03-08 14:19:21 -06:00
|
|
|
package api
|
2020-11-12 07:11:30 -06:00
|
|
|
|
|
|
|
import (
|
2021-01-27 07:51:00 -06:00
|
|
|
"fmt"
|
2021-03-08 14:19:21 -06:00
|
|
|
"time"
|
|
|
|
|
|
|
|
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/schedule"
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
2021-01-27 07:51:00 -06:00
|
|
|
|
2020-11-12 07:11:30 -06:00
|
|
|
"github.com/go-macaron/binding"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
2021-01-15 07:43:20 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
2020-11-12 07:11:30 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2021-03-08 00:02:49 -06:00
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
2021-03-03 09:52:19 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/datasources"
|
2020-12-17 08:00:09 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
2021-03-03 09:52:19 -06:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2020-11-12 07:11:30 -06:00
|
|
|
"github.com/grafana/grafana/pkg/tsdb"
|
|
|
|
"github.com/grafana/grafana/pkg/util"
|
|
|
|
)
|
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
// timeNow makes it possible to test usage of time
|
|
|
|
var timeNow = time.Now
|
|
|
|
|
|
|
|
// API handlers.
|
|
|
|
type API struct {
|
|
|
|
Cfg *setting.Cfg
|
|
|
|
DatasourceCache datasources.CacheService
|
|
|
|
RouteRegister routing.RouteRegister
|
2021-03-08 00:02:49 -06:00
|
|
|
DataService *tsdb.Service
|
2021-03-08 14:19:21 -06:00
|
|
|
Schedule schedule.ScheduleService
|
|
|
|
Store store.Store
|
2021-03-03 09:52:19 -06:00
|
|
|
}
|
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
// RegisterAPIEndpoints registers API handlers
|
|
|
|
func (api *API) RegisterAPIEndpoints() {
|
2021-03-03 09:52:19 -06:00
|
|
|
api.RouteRegister.Group("/api/alert-definitions", func(alertDefinitions routing.RouteRegister) {
|
|
|
|
alertDefinitions.Get("", middleware.ReqSignedIn, routing.Wrap(api.listAlertDefinitions))
|
|
|
|
alertDefinitions.Get("/eval/:alertDefinitionUID", middleware.ReqSignedIn, api.validateOrgAlertDefinition, routing.Wrap(api.alertDefinitionEvalEndpoint))
|
2021-03-08 14:19:21 -06:00
|
|
|
alertDefinitions.Post("/eval", middleware.ReqSignedIn, binding.Bind(ngmodels.EvalAlertConditionCommand{}), routing.Wrap(api.conditionEvalEndpoint))
|
2021-03-03 09:52:19 -06:00
|
|
|
alertDefinitions.Get("/:alertDefinitionUID", middleware.ReqSignedIn, api.validateOrgAlertDefinition, routing.Wrap(api.getAlertDefinitionEndpoint))
|
|
|
|
alertDefinitions.Delete("/:alertDefinitionUID", middleware.ReqEditorRole, api.validateOrgAlertDefinition, routing.Wrap(api.deleteAlertDefinitionEndpoint))
|
2021-03-08 14:19:21 -06:00
|
|
|
alertDefinitions.Post("/", middleware.ReqEditorRole, binding.Bind(ngmodels.SaveAlertDefinitionCommand{}), routing.Wrap(api.createAlertDefinitionEndpoint))
|
|
|
|
alertDefinitions.Put("/:alertDefinitionUID", middleware.ReqEditorRole, api.validateOrgAlertDefinition, binding.Bind(ngmodels.UpdateAlertDefinitionCommand{}), routing.Wrap(api.updateAlertDefinitionEndpoint))
|
|
|
|
alertDefinitions.Post("/pause", middleware.ReqEditorRole, binding.Bind(ngmodels.UpdateAlertDefinitionPausedCommand{}), routing.Wrap(api.alertDefinitionPauseEndpoint))
|
|
|
|
alertDefinitions.Post("/unpause", middleware.ReqEditorRole, binding.Bind(ngmodels.UpdateAlertDefinitionPausedCommand{}), routing.Wrap(api.alertDefinitionUnpauseEndpoint))
|
2020-11-12 07:11:30 -06:00
|
|
|
})
|
|
|
|
|
2021-03-03 09:52:19 -06:00
|
|
|
api.RouteRegister.Group("/api/ngalert/", func(schedulerRouter routing.RouteRegister) {
|
|
|
|
schedulerRouter.Post("/pause", routing.Wrap(api.pauseScheduler))
|
|
|
|
schedulerRouter.Post("/unpause", routing.Wrap(api.unpauseScheduler))
|
2020-12-17 08:00:09 -06:00
|
|
|
}, middleware.ReqOrgAdmin)
|
2021-01-18 12:57:17 -06:00
|
|
|
|
2021-03-03 09:52:19 -06:00
|
|
|
api.RouteRegister.Group("/api/alert-instances", func(alertInstances routing.RouteRegister) {
|
|
|
|
alertInstances.Get("", middleware.ReqSignedIn, routing.Wrap(api.listAlertInstancesEndpoint))
|
2021-01-18 12:57:17 -06:00
|
|
|
})
|
2020-12-17 08:00:09 -06:00
|
|
|
}
|
2020-11-12 07:11:30 -06:00
|
|
|
|
2020-12-17 08:00:09 -06:00
|
|
|
// conditionEvalEndpoint handles POST /api/alert-definitions/eval.
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) conditionEvalEndpoint(c *models.ReqContext, cmd ngmodels.EvalAlertConditionCommand) response.Response {
|
2021-02-04 02:13:02 -06:00
|
|
|
evalCond := eval.Condition{
|
|
|
|
RefID: cmd.Condition,
|
|
|
|
OrgID: c.SignedInUser.OrgId,
|
|
|
|
QueriesAndExpressions: cmd.Data,
|
|
|
|
}
|
2021-03-03 09:52:19 -06:00
|
|
|
if err := api.validateCondition(evalCond, c.SignedInUser, c.SkipCache); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "invalid condition", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-02-04 02:13:02 -06:00
|
|
|
now := cmd.Now
|
|
|
|
if now.IsZero() {
|
|
|
|
now = timeNow()
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:52:19 -06:00
|
|
|
evaluator := eval.Evaluator{Cfg: api.Cfg}
|
2021-03-08 00:02:49 -06:00
|
|
|
evalResults, err := evaluator.ConditionEval(&evalCond, timeNow(), api.DataService)
|
2020-11-12 07:11:30 -06:00
|
|
|
if err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "Failed to evaluate conditions", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
frame := evalResults.AsDataFrame()
|
2021-03-08 00:02:49 -06:00
|
|
|
df := plugins.NewDecodedDataFrames([]*data.Frame{&frame})
|
2020-11-12 07:11:30 -06:00
|
|
|
instances, err := df.Encoded()
|
|
|
|
if err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "Failed to encode result dataframes", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.JSON(200, util.DynMap{
|
2020-11-12 07:11:30 -06:00
|
|
|
"instances": instances,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-03 09:52:19 -06:00
|
|
|
// alertDefinitionEvalEndpoint handles GET /api/alert-definitions/eval/:alertDefinitionUID.
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) alertDefinitionEvalEndpoint(c *models.ReqContext) response.Response {
|
2021-01-15 10:33:50 -06:00
|
|
|
alertDefinitionUID := c.Params(":alertDefinitionUID")
|
2020-11-12 07:11:30 -06:00
|
|
|
|
2021-03-03 09:52:19 -06:00
|
|
|
condition, err := api.LoadAlertCondition(alertDefinitionUID, c.SignedInUser.OrgId)
|
2020-11-12 07:11:30 -06:00
|
|
|
if err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "Failed to load alert definition conditions", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-03-03 09:52:19 -06:00
|
|
|
if err := api.validateCondition(*condition, c.SignedInUser, c.SkipCache); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "invalid condition", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-03-03 09:52:19 -06:00
|
|
|
evaluator := eval.Evaluator{Cfg: api.Cfg}
|
2021-03-08 00:02:49 -06:00
|
|
|
evalResults, err := evaluator.ConditionEval(condition, timeNow(), api.DataService)
|
2020-11-12 07:11:30 -06:00
|
|
|
if err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "Failed to evaluate alert", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
frame := evalResults.AsDataFrame()
|
|
|
|
|
2021-03-08 00:02:49 -06:00
|
|
|
df := plugins.NewDecodedDataFrames([]*data.Frame{&frame})
|
2020-12-17 08:00:09 -06:00
|
|
|
if err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "Failed to instantiate Dataframes from the decoded frames", err)
|
2020-12-17 08:00:09 -06:00
|
|
|
}
|
|
|
|
|
2020-11-12 07:11:30 -06:00
|
|
|
instances, err := df.Encoded()
|
|
|
|
if err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "Failed to encode result dataframes", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.JSON(200, util.DynMap{
|
2020-11-12 07:11:30 -06:00
|
|
|
"instances": instances,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-07 09:45:42 -06:00
|
|
|
// getAlertDefinitionEndpoint handles GET /api/alert-definitions/:alertDefinitionUID.
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) getAlertDefinitionEndpoint(c *models.ReqContext) response.Response {
|
2021-01-15 10:33:50 -06:00
|
|
|
alertDefinitionUID := c.Params(":alertDefinitionUID")
|
2020-11-12 07:11:30 -06:00
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
query := ngmodels.GetAlertDefinitionByUIDQuery{
|
2021-01-07 09:45:42 -06:00
|
|
|
UID: alertDefinitionUID,
|
|
|
|
OrgID: c.SignedInUser.OrgId,
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
if err := api.Store.GetAlertDefinitionByUID(&query); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(500, "Failed to get alert definition", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.JSON(200, &query.Result)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-01-07 09:45:42 -06:00
|
|
|
// deleteAlertDefinitionEndpoint handles DELETE /api/alert-definitions/:alertDefinitionUID.
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) deleteAlertDefinitionEndpoint(c *models.ReqContext) response.Response {
|
2021-01-15 10:33:50 -06:00
|
|
|
alertDefinitionUID := c.Params(":alertDefinitionUID")
|
2020-11-12 07:11:30 -06:00
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
cmd := ngmodels.DeleteAlertDefinitionByUIDCommand{
|
2021-01-07 09:45:42 -06:00
|
|
|
UID: alertDefinitionUID,
|
2020-11-12 07:11:30 -06:00
|
|
|
OrgID: c.SignedInUser.OrgId,
|
|
|
|
}
|
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
if err := api.Store.DeleteAlertDefinitionByUID(&cmd); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(500, "Failed to delete alert definition", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Success("Alert definition deleted")
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-01-07 09:45:42 -06:00
|
|
|
// updateAlertDefinitionEndpoint handles PUT /api/alert-definitions/:alertDefinitionUID.
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) updateAlertDefinitionEndpoint(c *models.ReqContext, cmd ngmodels.UpdateAlertDefinitionCommand) response.Response {
|
2021-01-15 10:33:50 -06:00
|
|
|
cmd.UID = c.Params(":alertDefinitionUID")
|
2020-12-17 08:00:09 -06:00
|
|
|
cmd.OrgID = c.SignedInUser.OrgId
|
|
|
|
|
2021-02-04 02:13:02 -06:00
|
|
|
evalCond := eval.Condition{
|
|
|
|
RefID: cmd.Condition,
|
|
|
|
OrgID: c.SignedInUser.OrgId,
|
|
|
|
QueriesAndExpressions: cmd.Data,
|
|
|
|
}
|
2021-03-03 09:52:19 -06:00
|
|
|
if err := api.validateCondition(evalCond, c.SignedInUser, c.SkipCache); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "invalid condition", err)
|
2020-12-17 08:00:09 -06:00
|
|
|
}
|
2020-11-12 07:11:30 -06:00
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
if err := api.Store.UpdateAlertDefinition(&cmd); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(500, "Failed to update alert definition", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.JSON(200, cmd.Result)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// createAlertDefinitionEndpoint handles POST /api/alert-definitions.
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) createAlertDefinitionEndpoint(c *models.ReqContext, cmd ngmodels.SaveAlertDefinitionCommand) response.Response {
|
2020-11-12 07:11:30 -06:00
|
|
|
cmd.OrgID = c.SignedInUser.OrgId
|
2020-12-17 08:00:09 -06:00
|
|
|
|
2021-02-04 02:13:02 -06:00
|
|
|
evalCond := eval.Condition{
|
|
|
|
RefID: cmd.Condition,
|
|
|
|
OrgID: c.SignedInUser.OrgId,
|
|
|
|
QueriesAndExpressions: cmd.Data,
|
|
|
|
}
|
2021-03-03 09:52:19 -06:00
|
|
|
if err := api.validateCondition(evalCond, c.SignedInUser, c.SkipCache); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "invalid condition", err)
|
2020-12-17 08:00:09 -06:00
|
|
|
}
|
2020-11-12 07:11:30 -06:00
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
if err := api.Store.SaveAlertDefinition(&cmd); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(500, "Failed to create alert definition", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.JSON(200, cmd.Result)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// listAlertDefinitions handles GET /api/alert-definitions.
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) listAlertDefinitions(c *models.ReqContext) response.Response {
|
|
|
|
query := ngmodels.ListAlertDefinitionsQuery{OrgID: c.SignedInUser.OrgId}
|
2020-11-12 07:11:30 -06:00
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
if err := api.Store.GetOrgAlertDefinitions(&query); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(500, "Failed to list alert definitions", err)
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.JSON(200, util.DynMap{"results": query.Result})
|
2020-12-17 08:00:09 -06:00
|
|
|
}
|
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) pauseScheduler() response.Response {
|
|
|
|
err := api.Schedule.Pause()
|
2020-12-17 08:00:09 -06:00
|
|
|
if err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(500, "Failed to pause scheduler", err)
|
2020-12-17 08:00:09 -06:00
|
|
|
}
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.JSON(200, util.DynMap{"message": "alert definition scheduler paused"})
|
2020-12-17 08:00:09 -06:00
|
|
|
}
|
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) unpauseScheduler() response.Response {
|
|
|
|
err := api.Schedule.Unpause()
|
2020-12-17 08:00:09 -06:00
|
|
|
if err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(500, "Failed to unpause scheduler", err)
|
2020-12-17 08:00:09 -06:00
|
|
|
}
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.JSON(200, util.DynMap{"message": "alert definition scheduler unpaused"})
|
2020-11-12 07:11:30 -06:00
|
|
|
}
|
2021-01-27 07:51:00 -06:00
|
|
|
|
|
|
|
// alertDefinitionPauseEndpoint handles POST /api/alert-definitions/pause.
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) alertDefinitionPauseEndpoint(c *models.ReqContext, cmd ngmodels.UpdateAlertDefinitionPausedCommand) response.Response {
|
2021-01-27 07:51:00 -06:00
|
|
|
cmd.OrgID = c.SignedInUser.OrgId
|
|
|
|
cmd.Paused = true
|
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
err := api.Store.UpdateAlertDefinitionPaused(&cmd)
|
2021-01-27 07:51:00 -06:00
|
|
|
if err != nil {
|
|
|
|
return response.Error(500, "Failed to pause alert definition", err)
|
|
|
|
}
|
|
|
|
return response.JSON(200, util.DynMap{"message": fmt.Sprintf("%d alert definitions paused", cmd.ResultCount)})
|
|
|
|
}
|
|
|
|
|
|
|
|
// alertDefinitionUnpauseEndpoint handles POST /api/alert-definitions/unpause.
|
2021-03-08 14:19:21 -06:00
|
|
|
func (api *API) alertDefinitionUnpauseEndpoint(c *models.ReqContext, cmd ngmodels.UpdateAlertDefinitionPausedCommand) response.Response {
|
2021-01-27 07:51:00 -06:00
|
|
|
cmd.OrgID = c.SignedInUser.OrgId
|
|
|
|
cmd.Paused = false
|
|
|
|
|
2021-03-08 14:19:21 -06:00
|
|
|
err := api.Store.UpdateAlertDefinitionPaused(&cmd)
|
2021-01-27 07:51:00 -06:00
|
|
|
if err != nil {
|
|
|
|
return response.Error(500, "Failed to unpause alert definition", err)
|
|
|
|
}
|
|
|
|
return response.JSON(200, util.DynMap{"message": fmt.Sprintf("%d alert definitions unpaused", cmd.ResultCount)})
|
|
|
|
}
|
2021-03-08 14:19:21 -06:00
|
|
|
|
|
|
|
// LoadAlertCondition returns a Condition object for the given alertDefinitionID.
|
|
|
|
func (api *API) LoadAlertCondition(alertDefinitionUID string, orgID int64) (*eval.Condition, error) {
|
|
|
|
q := ngmodels.GetAlertDefinitionByUIDQuery{UID: alertDefinitionUID, OrgID: orgID}
|
|
|
|
if err := api.Store.GetAlertDefinitionByUID(&q); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
alertDefinition := q.Result
|
|
|
|
|
|
|
|
err := api.Store.ValidateAlertDefinition(alertDefinition, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &eval.Condition{
|
|
|
|
RefID: alertDefinition.Condition,
|
|
|
|
OrgID: alertDefinition.OrgID,
|
|
|
|
QueriesAndExpressions: alertDefinition.Data,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API) validateCondition(c eval.Condition, user *models.SignedInUser, skipCache bool) error {
|
|
|
|
var refID string
|
|
|
|
|
|
|
|
if len(c.QueriesAndExpressions) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, query := range c.QueriesAndExpressions {
|
|
|
|
if c.RefID == query.RefID {
|
|
|
|
refID = c.RefID
|
|
|
|
}
|
|
|
|
|
|
|
|
datasourceUID, err := query.GetDatasource()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
isExpression, err := query.IsExpression()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if isExpression {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = api.DatasourceCache.GetDatasourceByUID(datasourceUID, user, skipCache)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to get datasource: %s: %w", datasourceUID, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if refID == "" {
|
|
|
|
return fmt.Errorf("condition %s not found in any query or expression", c.RefID)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|