Chore: Move ReqContext to contexthandler service (#62102)
* Chore: Move ReqContext to contexthandler service * Rename package to contextmodel * Generate ngalert files * Remove unused imports
This commit is contained in:
@@ -14,8 +14,8 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||
@@ -42,7 +42,7 @@ func (e UnknownReceiverError) Error() string {
|
||||
return fmt.Sprintf("unknown receiver: %s", e.UID)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetAMStatus(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetAMStatus(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -51,7 +51,7 @@ func (srv AlertmanagerSrv) RouteGetAMStatus(c *models.ReqContext) response.Respo
|
||||
return response.JSON(http.StatusOK, am.GetStatus())
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteCreateSilence(c *models.ReqContext, postableSilence apimodels.PostableSilence) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteCreateSilence(c *contextmodel.ReqContext, postableSilence apimodels.PostableSilence) response.Response {
|
||||
err := postableSilence.Validate(strfmt.Default)
|
||||
if err != nil {
|
||||
srv.log.Error("silence failed validation", "error", err)
|
||||
@@ -92,7 +92,7 @@ func (srv AlertmanagerSrv) RouteCreateSilence(c *models.ReqContext, postableSile
|
||||
})
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteDeleteAlertingConfig(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteDeleteAlertingConfig(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -106,7 +106,7 @@ func (srv AlertmanagerSrv) RouteDeleteAlertingConfig(c *models.ReqContext) respo
|
||||
return response.JSON(http.StatusAccepted, util.DynMap{"message": "configuration deleted; the default is applied"})
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteDeleteSilence(c *models.ReqContext, silenceID string) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteDeleteSilence(c *contextmodel.ReqContext, silenceID string) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -121,7 +121,7 @@ func (srv AlertmanagerSrv) RouteDeleteSilence(c *models.ReqContext, silenceID st
|
||||
return response.JSON(http.StatusOK, util.DynMap{"message": "silence deleted"})
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetAlertingConfig(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetAlertingConfig(c *contextmodel.ReqContext) response.Response {
|
||||
config, err := srv.mam.GetAlertmanagerConfiguration(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
if errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
@@ -132,7 +132,7 @@ func (srv AlertmanagerSrv) RouteGetAlertingConfig(c *models.ReqContext) response
|
||||
return response.JSON(http.StatusOK, config)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetAMAlertGroups(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetAMAlertGroups(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -156,7 +156,7 @@ func (srv AlertmanagerSrv) RouteGetAMAlertGroups(c *models.ReqContext) response.
|
||||
return response.JSON(http.StatusOK, groups)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetAMAlerts(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetAMAlerts(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -183,7 +183,7 @@ func (srv AlertmanagerSrv) RouteGetAMAlerts(c *models.ReqContext) response.Respo
|
||||
return response.JSON(http.StatusOK, alerts)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetSilence(c *models.ReqContext, silenceID string) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetSilence(c *contextmodel.ReqContext, silenceID string) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -200,7 +200,7 @@ func (srv AlertmanagerSrv) RouteGetSilence(c *models.ReqContext, silenceID strin
|
||||
return response.JSON(http.StatusOK, gettableSilence)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetSilences(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetSilences(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -217,7 +217,7 @@ func (srv AlertmanagerSrv) RouteGetSilences(c *models.ReqContext) response.Respo
|
||||
return response.JSON(http.StatusOK, gettableSilences)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RoutePostAlertingConfig(c *models.ReqContext, body apimodels.PostableUserConfig) response.Response {
|
||||
func (srv AlertmanagerSrv) RoutePostAlertingConfig(c *contextmodel.ReqContext, body apimodels.PostableUserConfig) response.Response {
|
||||
currentConfig, err := srv.mam.GetAlertmanagerConfiguration(c.Req.Context(), c.OrgID)
|
||||
// If a config is present and valid we proceed with the guard, otherwise we
|
||||
// just bypass the guard which is okay as we are anyway in an invalid state.
|
||||
@@ -248,7 +248,7 @@ func (srv AlertmanagerSrv) RoutePostAlertingConfig(c *models.ReqContext, body ap
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetReceivers(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetReceivers(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -258,7 +258,7 @@ func (srv AlertmanagerSrv) RouteGetReceivers(c *models.ReqContext) response.Resp
|
||||
return response.JSON(http.StatusOK, rcvs)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RoutePostTestReceivers(c *models.ReqContext, body apimodels.TestReceiversConfigBodyParams) response.Response {
|
||||
func (srv AlertmanagerSrv) RoutePostTestReceivers(c *contextmodel.ReqContext, body apimodels.TestReceiversConfigBodyParams) response.Response {
|
||||
if err := srv.crypto.LoadSecureSettings(c.Req.Context(), c.OrgID, body.Receivers); err != nil {
|
||||
var unknownReceiverError UnknownReceiverError
|
||||
if errors.As(err, &unknownReceiverError) {
|
||||
|
||||
@@ -16,9 +16,9 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
acMock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
@@ -166,7 +166,7 @@ func TestAlertmanagerConfig(t *testing.T) {
|
||||
sut := createSut(t, nil)
|
||||
|
||||
t.Run("assert 404 Not Found when applying config to nonexistent org", func(t *testing.T) {
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -183,7 +183,7 @@ func TestAlertmanagerConfig(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("assert 202 when config successfully applied", func(t *testing.T) {
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -200,7 +200,7 @@ func TestAlertmanagerConfig(t *testing.T) {
|
||||
|
||||
t.Run("assert 202 when alertmanager to configure is not ready", func(t *testing.T) {
|
||||
sut := createSut(t, nil)
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -330,7 +330,7 @@ func TestSilenceCreate(t *testing.T) {
|
||||
|
||||
for _, cas := range cases {
|
||||
t.Run(cas.name, func(t *testing.T) {
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -456,7 +456,7 @@ func TestRouteCreateSilence(t *testing.T) {
|
||||
ac := tesCase.accessControl()
|
||||
sut := createSut(t, ac)
|
||||
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -622,8 +622,8 @@ func withEmptyID(silence *apimodels.PostableSilence) {
|
||||
silence.ID = ""
|
||||
}
|
||||
|
||||
func createRequestCtxInOrg(org int64) *models.ReqContext {
|
||||
return &models.ReqContext{
|
||||
func createRequestCtxInOrg(org int64) *contextmodel.ReqContext {
|
||||
return &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
@@ -26,7 +26,7 @@ type ConfigSrv struct {
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RouteGetAlertmanagers(c *models.ReqContext) response.Response {
|
||||
func (srv ConfigSrv) RouteGetAlertmanagers(c *contextmodel.ReqContext) response.Response {
|
||||
urls := srv.alertmanagerProvider.AlertmanagersFor(c.OrgID)
|
||||
droppedURLs := srv.alertmanagerProvider.DroppedAlertmanagersFor(c.OrgID)
|
||||
ams := v1.AlertManagersResult{Active: make([]v1.AlertManager, len(urls)), Dropped: make([]v1.AlertManager, len(droppedURLs))}
|
||||
@@ -43,7 +43,7 @@ func (srv ConfigSrv) RouteGetAlertmanagers(c *models.ReqContext) response.Respon
|
||||
})
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RouteGetNGalertConfig(c *models.ReqContext) response.Response {
|
||||
func (srv ConfigSrv) RouteGetNGalertConfig(c *contextmodel.ReqContext) response.Response {
|
||||
if c.OrgRole != org.RoleAdmin {
|
||||
return accessForbiddenResp()
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (srv ConfigSrv) RouteGetNGalertConfig(c *models.ReqContext) response.Respon
|
||||
return response.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RoutePostNGalertConfig(c *models.ReqContext, body apimodels.PostableNGalertConfig) response.Response {
|
||||
func (srv ConfigSrv) RoutePostNGalertConfig(c *contextmodel.ReqContext, body apimodels.PostableNGalertConfig) response.Response {
|
||||
if c.OrgRole != org.RoleAdmin {
|
||||
return accessForbiddenResp()
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (srv ConfigSrv) RoutePostNGalertConfig(c *models.ReqContext, body apimodels
|
||||
return response.JSON(http.StatusCreated, util.DynMap{"message": "admin configuration updated"})
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RouteDeleteNGalertConfig(c *models.ReqContext) response.Response {
|
||||
func (srv ConfigSrv) RouteDeleteNGalertConfig(c *contextmodel.ReqContext) response.Response {
|
||||
if c.OrgRole != org.RoleAdmin {
|
||||
return accessForbiddenResp()
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func (srv ConfigSrv) externalAlertmanagers(ctx context.Context, orgID int64) ([]
|
||||
return alertmanagers, nil
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RouteGetAlertingStatus(c *models.ReqContext) response.Response {
|
||||
func (srv ConfigSrv) RouteGetAlertingStatus(c *contextmodel.ReqContext) response.Response {
|
||||
sendsAlertsTo := ngmodels.InternalAlertmanager
|
||||
|
||||
cfg, err := srv.store.GetAdminConfiguration(c.OrgID)
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
||||
@@ -32,7 +32,7 @@ type PrometheusSrv struct {
|
||||
|
||||
const queryIncludeInternalLabels = "includeInternalLabels"
|
||||
|
||||
func (srv PrometheusSrv) RouteGetAlertStatuses(c *models.ReqContext) response.Response {
|
||||
func (srv PrometheusSrv) RouteGetAlertStatuses(c *contextmodel.ReqContext) response.Response {
|
||||
alertResponse := apimodels.AlertResponse{
|
||||
DiscoveryBase: apimodels.DiscoveryBase{
|
||||
Status: "success",
|
||||
@@ -105,7 +105,7 @@ func getPanelIDFromRequest(r *http.Request) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (srv PrometheusSrv) RouteGetRuleStatuses(c *models.ReqContext) response.Response {
|
||||
func (srv PrometheusSrv) RouteGetRuleStatuses(c *contextmodel.ReqContext) response.Response {
|
||||
dashboardUID := c.Query("dashboard_uid")
|
||||
panelID, err := getPanelIDFromRequest(c.Req)
|
||||
if err != nil {
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
|
||||
alertingModels "github.com/grafana/alerting/alerting/models"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
@@ -93,7 +93,7 @@ func TestRouteGetAlertStatuses(t *testing.T) {
|
||||
_, _, _, api := setupAPI(t)
|
||||
req, err := http.NewRequest("GET", "/api/v1/alerts", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
|
||||
r := api.RouteGetAlertStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
@@ -112,7 +112,7 @@ func TestRouteGetAlertStatuses(t *testing.T) {
|
||||
fakeAIM.GenerateAlertInstances(1, util.GenerateShortUID(), 2)
|
||||
req, err := http.NewRequest("GET", "/api/v1/alerts", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
|
||||
r := api.RouteGetAlertStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
@@ -154,7 +154,7 @@ func TestRouteGetAlertStatuses(t *testing.T) {
|
||||
fakeAIM.GenerateAlertInstances(1, util.GenerateShortUID(), 2, withAlertingState())
|
||||
req, err := http.NewRequest("GET", "/api/v1/alerts", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
|
||||
r := api.RouteGetAlertStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
@@ -196,7 +196,7 @@ func TestRouteGetAlertStatuses(t *testing.T) {
|
||||
fakeAIM.GenerateAlertInstances(orgID, util.GenerateShortUID(), 2)
|
||||
req, err := http.NewRequest("GET", "/api/v1/alerts?includeInternalLabels=true", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
|
||||
r := api.RouteGetAlertStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
@@ -258,7 +258,7 @@ func TestRouteGetRuleStatuses(t *testing.T) {
|
||||
|
||||
req, err := http.NewRequest("GET", "/api/v1/rules", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID, OrgRole: org.RoleViewer}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID, OrgRole: org.RoleViewer}}
|
||||
|
||||
t.Run("with no rules", func(t *testing.T) {
|
||||
_, _, _, api := setupAPI(t)
|
||||
@@ -328,7 +328,7 @@ func TestRouteGetRuleStatuses(t *testing.T) {
|
||||
|
||||
req, err := http.NewRequest("GET", "/api/v1/rules?includeInternalLabels=true", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID, OrgRole: org.RoleViewer}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID, OrgRole: org.RoleViewer}}
|
||||
|
||||
r := api.RouteGetRuleStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
alerting_models "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/provisioning"
|
||||
@@ -62,7 +62,7 @@ type AlertRuleService interface {
|
||||
ReplaceRuleGroup(ctx context.Context, orgID int64, group alerting_models.AlertRuleGroup, userID int64, provenance alerting_models.Provenance) error
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetPolicyTree(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetPolicyTree(c *contextmodel.ReqContext) response.Response {
|
||||
policies, err := srv.policies.GetPolicyTree(c.Req.Context(), c.OrgID)
|
||||
if errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
return ErrResp(http.StatusNotFound, err, "")
|
||||
@@ -74,7 +74,7 @@ func (srv *ProvisioningSrv) RouteGetPolicyTree(c *models.ReqContext) response.Re
|
||||
return response.JSON(http.StatusOK, policies)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutPolicyTree(c *models.ReqContext, tree definitions.Route) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutPolicyTree(c *contextmodel.ReqContext, tree definitions.Route) response.Response {
|
||||
err := srv.policies.UpdatePolicyTree(c.Req.Context(), c.OrgID, tree, alerting_models.ProvenanceAPI)
|
||||
if errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
return ErrResp(http.StatusNotFound, err, "")
|
||||
@@ -89,7 +89,7 @@ func (srv *ProvisioningSrv) RoutePutPolicyTree(c *models.ReqContext, tree defini
|
||||
return response.JSON(http.StatusAccepted, util.DynMap{"message": "policies updated"})
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteResetPolicyTree(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteResetPolicyTree(c *contextmodel.ReqContext) response.Response {
|
||||
tree, err := srv.policies.ResetPolicyTree(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -97,7 +97,7 @@ func (srv *ProvisioningSrv) RouteResetPolicyTree(c *models.ReqContext) response.
|
||||
return response.JSON(http.StatusAccepted, tree)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetContactPoints(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetContactPoints(c *contextmodel.ReqContext) response.Response {
|
||||
q := provisioning.ContactPointQuery{
|
||||
Name: c.Query("name"),
|
||||
OrgID: c.OrgID,
|
||||
@@ -109,7 +109,7 @@ func (srv *ProvisioningSrv) RouteGetContactPoints(c *models.ReqContext) response
|
||||
return response.JSON(http.StatusOK, cps)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePostContactPoint(c *models.ReqContext, cp definitions.EmbeddedContactPoint) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePostContactPoint(c *contextmodel.ReqContext, cp definitions.EmbeddedContactPoint) response.Response {
|
||||
// TODO: provenance is hardcoded for now, change it later to make it more flexible
|
||||
contactPoint, err := srv.contactPointService.CreateContactPoint(c.Req.Context(), c.OrgID, cp, alerting_models.ProvenanceAPI)
|
||||
if errors.Is(err, provisioning.ErrValidation) {
|
||||
@@ -121,7 +121,7 @@ func (srv *ProvisioningSrv) RoutePostContactPoint(c *models.ReqContext, cp defin
|
||||
return response.JSON(http.StatusAccepted, contactPoint)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutContactPoint(c *models.ReqContext, cp definitions.EmbeddedContactPoint, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutContactPoint(c *contextmodel.ReqContext, cp definitions.EmbeddedContactPoint, UID string) response.Response {
|
||||
cp.UID = UID
|
||||
err := srv.contactPointService.UpdateContactPoint(c.Req.Context(), c.OrgID, cp, alerting_models.ProvenanceAPI)
|
||||
if errors.Is(err, provisioning.ErrValidation) {
|
||||
@@ -136,7 +136,7 @@ func (srv *ProvisioningSrv) RoutePutContactPoint(c *models.ReqContext, cp defini
|
||||
return response.JSON(http.StatusAccepted, util.DynMap{"message": "contactpoint updated"})
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteDeleteContactPoint(c *models.ReqContext, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteDeleteContactPoint(c *contextmodel.ReqContext, UID string) response.Response {
|
||||
err := srv.contactPointService.DeleteContactPoint(c.Req.Context(), c.OrgID, UID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -144,7 +144,7 @@ func (srv *ProvisioningSrv) RouteDeleteContactPoint(c *models.ReqContext, UID st
|
||||
return response.JSON(http.StatusAccepted, util.DynMap{"message": "contactpoint deleted"})
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetTemplates(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetTemplates(c *contextmodel.ReqContext) response.Response {
|
||||
templates, err := srv.templates.GetTemplates(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -156,7 +156,7 @@ func (srv *ProvisioningSrv) RouteGetTemplates(c *models.ReqContext) response.Res
|
||||
return response.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetTemplate(c *models.ReqContext, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetTemplate(c *contextmodel.ReqContext, name string) response.Response {
|
||||
templates, err := srv.templates.GetTemplates(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -167,7 +167,7 @@ func (srv *ProvisioningSrv) RouteGetTemplate(c *models.ReqContext, name string)
|
||||
return response.Empty(http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutTemplate(c *models.ReqContext, body definitions.NotificationTemplateContent, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutTemplate(c *contextmodel.ReqContext, body definitions.NotificationTemplateContent, name string) response.Response {
|
||||
tmpl := definitions.NotificationTemplate{
|
||||
Name: name,
|
||||
Template: body.Template,
|
||||
@@ -183,7 +183,7 @@ func (srv *ProvisioningSrv) RoutePutTemplate(c *models.ReqContext, body definiti
|
||||
return response.JSON(http.StatusAccepted, modified)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteDeleteTemplate(c *models.ReqContext, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteDeleteTemplate(c *contextmodel.ReqContext, name string) response.Response {
|
||||
err := srv.templates.DeleteTemplate(c.Req.Context(), c.OrgID, name)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -191,7 +191,7 @@ func (srv *ProvisioningSrv) RouteDeleteTemplate(c *models.ReqContext, name strin
|
||||
return response.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTiming(c *models.ReqContext, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTiming(c *contextmodel.ReqContext, name string) response.Response {
|
||||
timings, err := srv.muteTimings.GetMuteTimings(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -204,7 +204,7 @@ func (srv *ProvisioningSrv) RouteGetMuteTiming(c *models.ReqContext, name string
|
||||
return response.Empty(http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTimings(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTimings(c *contextmodel.ReqContext) response.Response {
|
||||
timings, err := srv.muteTimings.GetMuteTimings(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -212,7 +212,7 @@ func (srv *ProvisioningSrv) RouteGetMuteTimings(c *models.ReqContext) response.R
|
||||
return response.JSON(http.StatusOK, timings)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePostMuteTiming(c *models.ReqContext, mt definitions.MuteTimeInterval) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePostMuteTiming(c *contextmodel.ReqContext, mt definitions.MuteTimeInterval) response.Response {
|
||||
mt.Provenance = alerting_models.ProvenanceAPI
|
||||
created, err := srv.muteTimings.CreateMuteTiming(c.Req.Context(), mt, c.OrgID)
|
||||
if err != nil {
|
||||
@@ -224,7 +224,7 @@ func (srv *ProvisioningSrv) RoutePostMuteTiming(c *models.ReqContext, mt definit
|
||||
return response.JSON(http.StatusCreated, created)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutMuteTiming(c *models.ReqContext, mt definitions.MuteTimeInterval, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutMuteTiming(c *contextmodel.ReqContext, mt definitions.MuteTimeInterval, name string) response.Response {
|
||||
mt.Name = name
|
||||
mt.Provenance = alerting_models.ProvenanceAPI
|
||||
updated, err := srv.muteTimings.UpdateMuteTiming(c.Req.Context(), mt, c.OrgID)
|
||||
@@ -240,7 +240,7 @@ func (srv *ProvisioningSrv) RoutePutMuteTiming(c *models.ReqContext, mt definiti
|
||||
return response.JSON(http.StatusAccepted, updated)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteDeleteMuteTiming(c *models.ReqContext, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteDeleteMuteTiming(c *contextmodel.ReqContext, name string) response.Response {
|
||||
err := srv.muteTimings.DeleteMuteTiming(c.Req.Context(), name, c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -248,7 +248,7 @@ func (srv *ProvisioningSrv) RouteDeleteMuteTiming(c *models.ReqContext, name str
|
||||
return response.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetAlertRules(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetAlertRules(c *contextmodel.ReqContext) response.Response {
|
||||
rules, err := srv.alertRules.GetAlertRules(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -256,7 +256,7 @@ func (srv *ProvisioningSrv) RouteGetAlertRules(c *models.ReqContext) response.Re
|
||||
return response.JSON(http.StatusOK, definitions.NewAlertRules(rules))
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteRouteGetAlertRule(c *models.ReqContext, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteRouteGetAlertRule(c *contextmodel.ReqContext, UID string) response.Response {
|
||||
rule, provenace, err := srv.alertRules.GetAlertRule(c.Req.Context(), c.OrgID, UID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -264,7 +264,7 @@ func (srv *ProvisioningSrv) RouteRouteGetAlertRule(c *models.ReqContext, UID str
|
||||
return response.JSON(http.StatusOK, definitions.NewAlertRule(rule, provenace))
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePostAlertRule(c *models.ReqContext, ar definitions.ProvisionedAlertRule) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePostAlertRule(c *contextmodel.ReqContext, ar definitions.ProvisionedAlertRule) response.Response {
|
||||
upstreamModel, err := ar.UpstreamModel()
|
||||
upstreamModel.OrgID = c.OrgID
|
||||
if err != nil {
|
||||
@@ -289,7 +289,7 @@ func (srv *ProvisioningSrv) RoutePostAlertRule(c *models.ReqContext, ar definiti
|
||||
return response.JSON(http.StatusCreated, resp)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutAlertRule(c *models.ReqContext, ar definitions.ProvisionedAlertRule, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutAlertRule(c *contextmodel.ReqContext, ar definitions.ProvisionedAlertRule, UID string) response.Response {
|
||||
updated, err := ar.UpstreamModel()
|
||||
if err != nil {
|
||||
ErrResp(http.StatusBadRequest, err, "")
|
||||
@@ -315,7 +315,7 @@ func (srv *ProvisioningSrv) RoutePutAlertRule(c *models.ReqContext, ar definitio
|
||||
return response.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteDeleteAlertRule(c *models.ReqContext, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteDeleteAlertRule(c *contextmodel.ReqContext, UID string) response.Response {
|
||||
err := srv.alertRules.DeleteAlertRule(c.Req.Context(), c.OrgID, UID, alerting_models.ProvenanceAPI)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -323,7 +323,7 @@ func (srv *ProvisioningSrv) RouteDeleteAlertRule(c *models.ReqContext, UID strin
|
||||
return response.JSON(http.StatusNoContent, "")
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetAlertRuleGroup(c *models.ReqContext, folder string, group string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetAlertRuleGroup(c *contextmodel.ReqContext, folder string, group string) response.Response {
|
||||
g, err := srv.alertRules.GetRuleGroup(c.Req.Context(), c.OrgID, folder, group)
|
||||
if err != nil {
|
||||
if errors.Is(err, store.ErrAlertRuleGroupNotFound) {
|
||||
@@ -334,7 +334,7 @@ func (srv *ProvisioningSrv) RouteGetAlertRuleGroup(c *models.ReqContext, folder
|
||||
return response.JSON(http.StatusOK, definitions.NewAlertRuleGroupFromModel(g))
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutAlertRuleGroup(c *models.ReqContext, ag definitions.AlertRuleGroup, folderUID string, group string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutAlertRuleGroup(c *contextmodel.ReqContext, ag definitions.AlertRuleGroup, folderUID string, group string) response.Response {
|
||||
ag.FolderUID = folderUID
|
||||
ag.Title = group
|
||||
groupModel, err := ag.ToModel()
|
||||
@@ -354,7 +354,7 @@ func (srv *ProvisioningSrv) RoutePutAlertRuleGroup(c *models.ReqContext, ag defi
|
||||
return response.JSON(http.StatusOK, ag)
|
||||
}
|
||||
|
||||
func determineProvenance(ctx *models.ReqContext) alerting_models.Provenance {
|
||||
func determineProvenance(ctx *contextmodel.ReqContext) alerting_models.Provenance {
|
||||
if _, disabled := ctx.Req.Header[disableProvenanceHeaderName]; disabled {
|
||||
return alerting_models.ProvenanceNone
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
gfcore "github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/provisioning"
|
||||
@@ -438,8 +438,8 @@ func createProvisioningSrvSutFromEnv(t *testing.T, env *testEnvironment) Provisi
|
||||
}
|
||||
}
|
||||
|
||||
func createTestRequestCtx() gfcore.ReqContext {
|
||||
return gfcore.ReqContext{
|
||||
func createTestRequestCtx() contextmodel.ReqContext {
|
||||
return contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/apierrors"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/schedule"
|
||||
@@ -53,7 +53,7 @@ var (
|
||||
// or, if non-empty, a specific group of rules in the namespace.
|
||||
// Returns http.StatusUnauthorized if user does not have access to any of the rules that match the filter.
|
||||
// Returns http.StatusBadRequest if all rules that match the filter and the user is authorized to delete are provisioned.
|
||||
func (srv RulerSrv) RouteDeleteAlertRules(c *models.ReqContext, namespaceTitle string, group string) response.Response {
|
||||
func (srv RulerSrv) RouteDeleteAlertRules(c *contextmodel.ReqContext, namespaceTitle string, group string) response.Response {
|
||||
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgID, c.SignedInUser, true)
|
||||
if err != nil {
|
||||
return toNamespaceErrorResponse(err)
|
||||
@@ -155,7 +155,7 @@ func (srv RulerSrv) RouteDeleteAlertRules(c *models.ReqContext, namespaceTitle s
|
||||
}
|
||||
|
||||
// RouteGetNamespaceRulesConfig returns all rules in a specific folder that user has access to
|
||||
func (srv RulerSrv) RouteGetNamespaceRulesConfig(c *models.ReqContext, namespaceTitle string) response.Response {
|
||||
func (srv RulerSrv) RouteGetNamespaceRulesConfig(c *contextmodel.ReqContext, namespaceTitle string) response.Response {
|
||||
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgID, c.SignedInUser, false)
|
||||
if err != nil {
|
||||
return toNamespaceErrorResponse(err)
|
||||
@@ -197,7 +197,7 @@ func (srv RulerSrv) RouteGetNamespaceRulesConfig(c *models.ReqContext, namespace
|
||||
|
||||
// RouteGetRulesGroupConfig returns rules that belong to a specific group in a specific namespace (folder).
|
||||
// If user does not have access to at least one of the rule in the group, returns status 401 Unauthorized
|
||||
func (srv RulerSrv) RouteGetRulesGroupConfig(c *models.ReqContext, namespaceTitle string, ruleGroup string) response.Response {
|
||||
func (srv RulerSrv) RouteGetRulesGroupConfig(c *contextmodel.ReqContext, namespaceTitle string, ruleGroup string) response.Response {
|
||||
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgID, c.SignedInUser, false)
|
||||
if err != nil {
|
||||
return toNamespaceErrorResponse(err)
|
||||
@@ -232,7 +232,7 @@ func (srv RulerSrv) RouteGetRulesGroupConfig(c *models.ReqContext, namespaceTitl
|
||||
}
|
||||
|
||||
// RouteGetRulesConfig returns all alert rules that are available to the current user
|
||||
func (srv RulerSrv) RouteGetRulesConfig(c *models.ReqContext) response.Response {
|
||||
func (srv RulerSrv) RouteGetRulesConfig(c *contextmodel.ReqContext) response.Response {
|
||||
namespaceMap, err := srv.store.GetUserVisibleNamespaces(c.Req.Context(), c.OrgID, c.SignedInUser)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "failed to get namespaces visible to the user")
|
||||
@@ -301,7 +301,7 @@ func (srv RulerSrv) RouteGetRulesConfig(c *models.ReqContext) response.Response
|
||||
return response.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (srv RulerSrv) RoutePostNameRulesConfig(c *models.ReqContext, ruleGroupConfig apimodels.PostableRuleGroupConfig, namespaceTitle string) response.Response {
|
||||
func (srv RulerSrv) RoutePostNameRulesConfig(c *contextmodel.ReqContext, ruleGroupConfig apimodels.PostableRuleGroupConfig, namespaceTitle string) response.Response {
|
||||
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgID, c.SignedInUser, true)
|
||||
if err != nil {
|
||||
return toNamespaceErrorResponse(err)
|
||||
@@ -325,7 +325,7 @@ func (srv RulerSrv) RoutePostNameRulesConfig(c *models.ReqContext, ruleGroupConf
|
||||
|
||||
// updateAlertRulesInGroup calculates changes (rules to add,update,delete), verifies that the user is authorized to do the calculated changes and updates database.
|
||||
// All operations are performed in a single transaction
|
||||
func (srv RulerSrv) updateAlertRulesInGroup(c *models.ReqContext, groupKey ngmodels.AlertRuleGroupKey, rules []*ngmodels.AlertRule) response.Response {
|
||||
func (srv RulerSrv) updateAlertRulesInGroup(c *contextmodel.ReqContext, groupKey ngmodels.AlertRuleGroupKey, rules []*ngmodels.AlertRule) response.Response {
|
||||
var finalChanges *store.GroupDelta
|
||||
hasAccess := accesscontrol.HasAccess(srv.ac, c)
|
||||
err := srv.xactManager.InTransaction(c.Req.Context(), func(tranCtx context.Context) error {
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
models2 "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
acMock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -657,7 +657,7 @@ func createService(ac *acMock.Mock, store *fakes.RuleStore, scheduler schedule.S
|
||||
}
|
||||
}
|
||||
|
||||
func createRequestContext(orgID int64, role org.RoleType, params map[string]string) *models2.ReqContext {
|
||||
func createRequestContext(orgID int64, role org.RoleType, params map[string]string) *contextmodel.ReqContext {
|
||||
uri, _ := url.Parse("http://localhost")
|
||||
ctx := web.Context{Req: &http.Request{
|
||||
URL: uri,
|
||||
@@ -666,7 +666,7 @@ func createRequestContext(orgID int64, role org.RoleType, params map[string]stri
|
||||
ctx.Req = web.SetURLParams(ctx.Req, params)
|
||||
}
|
||||
|
||||
return &models2.ReqContext{
|
||||
return &contextmodel.ReqContext{
|
||||
IsSignedIn: true,
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgRole: role,
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -35,7 +35,7 @@ type TestingApiSrv struct {
|
||||
featureManager featuremgmt.FeatureToggles
|
||||
}
|
||||
|
||||
func (srv TestingApiSrv) RouteTestGrafanaRuleConfig(c *models.ReqContext, body apimodels.TestRulePayload) response.Response {
|
||||
func (srv TestingApiSrv) RouteTestGrafanaRuleConfig(c *contextmodel.ReqContext, body apimodels.TestRulePayload) response.Response {
|
||||
if body.Type() != apimodels.GrafanaBackend || body.GrafanaManagedCondition == nil {
|
||||
return errorToResponse(backendTypeDoesNotMatchPayloadTypeError(apimodels.GrafanaBackend, body.Type().String()))
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (srv TestingApiSrv) RouteTestGrafanaRuleConfig(c *models.ReqContext, body a
|
||||
})
|
||||
}
|
||||
|
||||
func (srv TestingApiSrv) RouteTestRuleConfig(c *models.ReqContext, body apimodels.TestRulePayload, datasourceUID string) response.Response {
|
||||
func (srv TestingApiSrv) RouteTestRuleConfig(c *contextmodel.ReqContext, body apimodels.TestRulePayload, datasourceUID string) response.Response {
|
||||
if body.Type() != apimodels.LoTexRulerBackend {
|
||||
return errorToResponse(backendTypeDoesNotMatchPayloadTypeError(apimodels.LoTexRulerBackend, body.Type().String()))
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (srv TestingApiSrv) RouteTestRuleConfig(c *models.ReqContext, body apimodel
|
||||
)
|
||||
}
|
||||
|
||||
func (srv TestingApiSrv) RouteEvalQueries(c *models.ReqContext, cmd apimodels.EvalQueriesPayload) response.Response {
|
||||
func (srv TestingApiSrv) RouteEvalQueries(c *contextmodel.ReqContext, cmd apimodels.EvalQueriesPayload) response.Response {
|
||||
if !authorizeDatasourceAccessForRule(&ngmodels.AlertRule{Data: cmd.Data}, func(evaluator accesscontrol.Evaluator) bool {
|
||||
return accesscontrol.HasAccess(srv.accessControl, c)(accesscontrol.ReqSignedIn, evaluator)
|
||||
}) {
|
||||
@@ -145,7 +145,7 @@ func (srv TestingApiSrv) RouteEvalQueries(c *models.ReqContext, cmd apimodels.Ev
|
||||
return response.JSONStreaming(http.StatusOK, evalResults)
|
||||
}
|
||||
|
||||
func (srv TestingApiSrv) BacktestAlertRule(c *models.ReqContext, cmd apimodels.BacktestConfig) response.Response {
|
||||
func (srv TestingApiSrv) BacktestAlertRule(c *contextmodel.ReqContext, cmd apimodels.BacktestConfig) response.Response {
|
||||
if !srv.featureManager.IsEnabled(featuremgmt.FlagAlertingBacktesting) {
|
||||
return ErrResp(http.StatusNotFound, nil, "Backgtesting API is not enabled")
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
models2 "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
acMock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
fakes "github.com/grafana/grafana/pkg/services/datasources/fakes"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
func TestRouteTestGrafanaRuleConfig(t *testing.T) {
|
||||
t.Run("when fine-grained access is enabled", func(t *testing.T) {
|
||||
rc := &models2.ReqContext{
|
||||
rc := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -95,7 +95,7 @@ func TestRouteTestGrafanaRuleConfig(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("when fine-grained access is disabled", func(t *testing.T) {
|
||||
rc := &models2.ReqContext{
|
||||
rc := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -152,7 +152,7 @@ func TestRouteTestGrafanaRuleConfig(t *testing.T) {
|
||||
|
||||
func TestRouteEvalQueries(t *testing.T) {
|
||||
t.Run("when fine-grained access is enabled", func(t *testing.T) {
|
||||
rc := &models2.ReqContext{
|
||||
rc := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -222,7 +222,7 @@ func TestRouteEvalQueries(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("when fine-grained access is disabled", func(t *testing.T) {
|
||||
rc := &models2.ReqContext{
|
||||
rc := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
|
||||
@@ -17,22 +17,22 @@ func NewConfiguration(grafana *ConfigSrv) *ConfigurationApiHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRouteGetAlertmanagers(c *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRouteGetAlertmanagers(c *contextmodel.ReqContext) response.Response {
|
||||
return f.grafana.RouteGetAlertmanagers(c)
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRouteGetNGalertConfig(c *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRouteGetNGalertConfig(c *contextmodel.ReqContext) response.Response {
|
||||
return f.grafana.RouteGetNGalertConfig(c)
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRoutePostNGalertConfig(c *models.ReqContext, body apimodels.PostableNGalertConfig) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRoutePostNGalertConfig(c *contextmodel.ReqContext, body apimodels.PostableNGalertConfig) response.Response {
|
||||
return f.grafana.RoutePostNGalertConfig(c, body)
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRouteDeleteNGalertConfig(c *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRouteDeleteNGalertConfig(c *contextmodel.ReqContext) response.Response {
|
||||
return f.grafana.RouteDeleteNGalertConfig(c)
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRouteGetStatus(c *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRouteGetStatus(c *contextmodel.ReqContext) response.Response {
|
||||
return f.grafana.RouteGetAlertingStatus(c)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
@@ -22,7 +22,7 @@ func NewForkingAM(datasourceCache datasources.CacheService, proxy *LotexAM, graf
|
||||
}
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) getService(ctx *models.ReqContext) (*LotexAM, error) {
|
||||
func (f *AlertmanagerApiHandler) getService(ctx *contextmodel.ReqContext) (*LotexAM, error) {
|
||||
_, err := getDatasourceByUID(ctx, f.DatasourceCache, apimodels.AlertmanagerBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -30,7 +30,7 @@ func (f *AlertmanagerApiHandler) getService(ctx *models.ReqContext) (*LotexAM, e
|
||||
return f.AMSvc, nil
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMStatus(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMStatus(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -39,7 +39,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAMStatus(ctx *models.ReqContext,
|
||||
return s.RouteGetAMStatus(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteCreateSilence(ctx *models.ReqContext, body apimodels.PostableSilence, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteCreateSilence(ctx *contextmodel.ReqContext, body apimodels.PostableSilence, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -48,7 +48,7 @@ func (f *AlertmanagerApiHandler) handleRouteCreateSilence(ctx *models.ReqContext
|
||||
return s.RouteCreateSilence(ctx, body)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteAlertingConfig(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteAlertingConfig(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -57,7 +57,7 @@ func (f *AlertmanagerApiHandler) handleRouteDeleteAlertingConfig(ctx *models.Req
|
||||
return s.RouteDeleteAlertingConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteSilence(ctx *models.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteSilence(ctx *contextmodel.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -66,7 +66,7 @@ func (f *AlertmanagerApiHandler) handleRouteDeleteSilence(ctx *models.ReqContext
|
||||
return s.RouteDeleteSilence(ctx, silenceID)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAlertingConfig(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAlertingConfig(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -75,7 +75,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAlertingConfig(ctx *models.ReqCon
|
||||
return s.RouteGetAlertingConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlertGroups(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlertGroups(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -84,7 +84,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAMAlertGroups(ctx *models.ReqCont
|
||||
return s.RouteGetAMAlertGroups(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlerts(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlerts(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -93,7 +93,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAMAlerts(ctx *models.ReqContext,
|
||||
return s.RouteGetAMAlerts(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilence(ctx *models.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilence(ctx *contextmodel.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -102,7 +102,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetSilence(ctx *models.ReqContext, s
|
||||
return s.RouteGetSilence(ctx, silenceID)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilences(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilences(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -111,7 +111,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetSilences(ctx *models.ReqContext,
|
||||
return s.RouteGetSilences(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAlertingConfig(ctx *models.ReqContext, body apimodels.PostableUserConfig, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAlertingConfig(ctx *contextmodel.ReqContext, body apimodels.PostableUserConfig, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -122,7 +122,7 @@ func (f *AlertmanagerApiHandler) handleRoutePostAlertingConfig(ctx *models.ReqCo
|
||||
return s.RoutePostAlertingConfig(ctx, body)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAMAlerts(ctx *models.ReqContext, body apimodels.PostableAlerts, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAMAlerts(ctx *contextmodel.ReqContext, body apimodels.PostableAlerts, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -131,53 +131,53 @@ func (f *AlertmanagerApiHandler) handleRoutePostAMAlerts(ctx *models.ReqContext,
|
||||
return s.RoutePostAMAlerts(ctx, body)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteGrafanaSilence(ctx *models.ReqContext, id string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteGrafanaSilence(ctx *contextmodel.ReqContext, id string) response.Response {
|
||||
return f.GrafanaSvc.RouteDeleteSilence(ctx, id)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteDeleteAlertingConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteCreateGrafanaSilence(ctx *models.ReqContext, body apimodels.PostableSilence) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteCreateGrafanaSilence(ctx *contextmodel.ReqContext, body apimodels.PostableSilence) response.Response {
|
||||
return f.GrafanaSvc.RouteCreateSilence(ctx, body)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMStatus(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAMStatus(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAMAlerts(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMAlertGroups(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMAlertGroups(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAMAlertGroups(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAlertingConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaSilence(ctx *models.ReqContext, id string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaSilence(ctx *contextmodel.ReqContext, id string) response.Response {
|
||||
return f.GrafanaSvc.RouteGetSilence(ctx, id)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaSilences(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaSilences(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetSilences(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostGrafanaAlertingConfig(ctx *models.ReqContext, conf apimodels.PostableUserConfig) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostGrafanaAlertingConfig(ctx *contextmodel.ReqContext, conf apimodels.PostableUserConfig) response.Response {
|
||||
if !conf.AlertmanagerConfig.ReceiverType().Can(apimodels.GrafanaReceiverType) {
|
||||
return errorToResponse(backendTypeDoesNotMatchPayloadTypeError(apimodels.GrafanaBackend, conf.AlertmanagerConfig.ReceiverType().String()))
|
||||
}
|
||||
return f.GrafanaSvc.RoutePostAlertingConfig(ctx, conf)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaReceivers(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaReceivers(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetReceivers(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostTestGrafanaReceivers(ctx *models.ReqContext, conf apimodels.TestReceiversConfigBodyParams) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostTestGrafanaReceivers(ctx *contextmodel.ReqContext, conf apimodels.TestReceiversConfigBodyParams) response.Response {
|
||||
return f.GrafanaSvc.RoutePostTestReceivers(ctx, conf)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
@@ -22,7 +22,7 @@ func NewForkingProm(datasourceCache datasources.CacheService, proxy *LotexProm,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) handleRouteGetAlertStatuses(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *PrometheusApiHandler) handleRouteGetAlertStatuses(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -30,7 +30,7 @@ func (f *PrometheusApiHandler) handleRouteGetAlertStatuses(ctx *models.ReqContex
|
||||
return t.RouteGetAlertStatuses(ctx)
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) handleRouteGetRuleStatuses(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *PrometheusApiHandler) handleRouteGetRuleStatuses(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -38,15 +38,15 @@ func (f *PrometheusApiHandler) handleRouteGetRuleStatuses(ctx *models.ReqContext
|
||||
return t.RouteGetRuleStatuses(ctx)
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) handleRouteGetGrafanaAlertStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) handleRouteGetGrafanaAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAlertStatuses(ctx)
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) handleRouteGetGrafanaRuleStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) handleRouteGetGrafanaRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetRuleStatuses(ctx)
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) getService(ctx *models.ReqContext) (*LotexProm, error) {
|
||||
func (f *PrometheusApiHandler) getService(ctx *contextmodel.ReqContext) (*LotexProm, error) {
|
||||
_, err := getDatasourceByUID(ctx, f.DatasourceCache, apimodels.LoTexRulerBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
@@ -22,7 +22,7 @@ func NewForkingRuler(datasourceCache datasources.CacheService, lotex *LotexRuler
|
||||
}
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteDeleteNamespaceRulesConfig(ctx *models.ReqContext, dsUID, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteDeleteNamespaceRulesConfig(ctx *contextmodel.ReqContext, dsUID, namespace string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -30,7 +30,7 @@ func (f *RulerApiHandler) handleRouteDeleteNamespaceRulesConfig(ctx *models.ReqC
|
||||
return t.RouteDeleteNamespaceRulesConfig(ctx, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteDeleteRuleGroupConfig(ctx *models.ReqContext, dsUID, namespace, group string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteDeleteRuleGroupConfig(ctx *contextmodel.ReqContext, dsUID, namespace, group string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -38,7 +38,7 @@ func (f *RulerApiHandler) handleRouteDeleteRuleGroupConfig(ctx *models.ReqContex
|
||||
return t.RouteDeleteRuleGroupConfig(ctx, namespace, group)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetNamespaceRulesConfig(ctx *models.ReqContext, dsUID, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetNamespaceRulesConfig(ctx *contextmodel.ReqContext, dsUID, namespace string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -46,7 +46,7 @@ func (f *RulerApiHandler) handleRouteGetNamespaceRulesConfig(ctx *models.ReqCont
|
||||
return t.RouteGetNamespaceRulesConfig(ctx, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetRulegGroupConfig(ctx *models.ReqContext, dsUID, namespace, group string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetRulegGroupConfig(ctx *contextmodel.ReqContext, dsUID, namespace, group string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -54,7 +54,7 @@ func (f *RulerApiHandler) handleRouteGetRulegGroupConfig(ctx *models.ReqContext,
|
||||
return t.RouteGetRulegGroupConfig(ctx, namespace, group)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetRulesConfig(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetRulesConfig(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -62,7 +62,7 @@ func (f *RulerApiHandler) handleRouteGetRulesConfig(ctx *models.ReqContext, dsUI
|
||||
return t.RouteGetRulesConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRoutePostNameRulesConfig(ctx *models.ReqContext, conf apimodels.PostableRuleGroupConfig, dsUID, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRoutePostNameRulesConfig(ctx *contextmodel.ReqContext, conf apimodels.PostableRuleGroupConfig, dsUID, namespace string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -73,27 +73,27 @@ func (f *RulerApiHandler) handleRoutePostNameRulesConfig(ctx *models.ReqContext,
|
||||
return t.RoutePostNameRulesConfig(ctx, conf, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteDeleteNamespaceGrafanaRulesConfig(ctx *models.ReqContext, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteDeleteNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext, namespace string) response.Response {
|
||||
return f.GrafanaRuler.RouteDeleteAlertRules(ctx, namespace, "")
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteDeleteGrafanaRuleGroupConfig(ctx *models.ReqContext, namespace, groupName string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteDeleteGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext, namespace, groupName string) response.Response {
|
||||
return f.GrafanaRuler.RouteDeleteAlertRules(ctx, namespace, groupName)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetNamespaceGrafanaRulesConfig(ctx *models.ReqContext, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext, namespace string) response.Response {
|
||||
return f.GrafanaRuler.RouteGetNamespaceRulesConfig(ctx, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetGrafanaRuleGroupConfig(ctx *models.ReqContext, namespace, group string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext, namespace, group string) response.Response {
|
||||
return f.GrafanaRuler.RouteGetRulesGroupConfig(ctx, namespace, group)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaRuler.RouteGetRulesConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRoutePostNameGrafanaRulesConfig(ctx *models.ReqContext, conf apimodels.PostableRuleGroupConfig, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRoutePostNameGrafanaRulesConfig(ctx *contextmodel.ReqContext, conf apimodels.PostableRuleGroupConfig, namespace string) response.Response {
|
||||
payloadType := conf.Type()
|
||||
if payloadType != apimodels.GrafanaBackend {
|
||||
return errorToResponse(backendTypeDoesNotMatchPayloadTypeError(apimodels.GrafanaBackend, conf.Type().String()))
|
||||
@@ -101,7 +101,7 @@ func (f *RulerApiHandler) handleRoutePostNameGrafanaRulesConfig(ctx *models.ReqC
|
||||
return f.GrafanaRuler.RoutePostNameRulesConfig(ctx, conf, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) getService(ctx *models.ReqContext) (*LotexRuler, error) {
|
||||
func (f *RulerApiHandler) getService(ctx *contextmodel.ReqContext) (*LotexRuler, error) {
|
||||
_, err := getDatasourceByUID(ctx, f.DatasourceCache, apimodels.LoTexRulerBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -12,39 +12,39 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type AlertmanagerApi interface {
|
||||
RouteCreateGrafanaSilence(*models.ReqContext) response.Response
|
||||
RouteCreateSilence(*models.ReqContext) response.Response
|
||||
RouteDeleteAlertingConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteGrafanaAlertingConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteGrafanaSilence(*models.ReqContext) response.Response
|
||||
RouteDeleteSilence(*models.ReqContext) response.Response
|
||||
RouteGetAMAlertGroups(*models.ReqContext) response.Response
|
||||
RouteGetAMAlerts(*models.ReqContext) response.Response
|
||||
RouteGetAMStatus(*models.ReqContext) response.Response
|
||||
RouteGetAlertingConfig(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAMAlertGroups(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAMAlerts(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAMStatus(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAlertingConfig(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaReceivers(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaSilence(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaSilences(*models.ReqContext) response.Response
|
||||
RouteGetSilence(*models.ReqContext) response.Response
|
||||
RouteGetSilences(*models.ReqContext) response.Response
|
||||
RoutePostAMAlerts(*models.ReqContext) response.Response
|
||||
RoutePostAlertingConfig(*models.ReqContext) response.Response
|
||||
RoutePostGrafanaAlertingConfig(*models.ReqContext) response.Response
|
||||
RoutePostTestGrafanaReceivers(*models.ReqContext) response.Response
|
||||
RouteCreateGrafanaSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteCreateSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteGrafanaAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteGrafanaSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAMAlertGroups(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAMAlerts(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAMStatus(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAMAlertGroups(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAMAlerts(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAMStatus(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaReceivers(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaSilences(*contextmodel.ReqContext) response.Response
|
||||
RouteGetSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteGetSilences(*contextmodel.ReqContext) response.Response
|
||||
RoutePostAMAlerts(*contextmodel.ReqContext) response.Response
|
||||
RoutePostAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostGrafanaAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostTestGrafanaReceivers(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) RouteCreateGrafanaSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteCreateGrafanaSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.PostableSilence{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -52,7 +52,7 @@ func (f *AlertmanagerApiHandler) RouteCreateGrafanaSilence(ctx *models.ReqContex
|
||||
}
|
||||
return f.handleRouteCreateGrafanaSilence(ctx, conf)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteCreateSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteCreateSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
// Parse Request Body
|
||||
@@ -62,80 +62,80 @@ func (f *AlertmanagerApiHandler) RouteCreateSilence(ctx *models.ReqContext) resp
|
||||
}
|
||||
return f.handleRouteCreateSilence(ctx, conf, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteDeleteAlertingConfig(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteDeleteGrafanaAlertingConfig(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteGrafanaSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteGrafanaSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
silenceIdParam := web.Params(ctx.Req)[":SilenceId"]
|
||||
return f.handleRouteDeleteGrafanaSilence(ctx, silenceIdParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
silenceIdParam := web.Params(ctx.Req)[":SilenceId"]
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteDeleteSilence(ctx, silenceIdParam, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMAlertGroups(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMAlertGroups(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAMAlertGroups(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAMAlerts(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMStatus(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAMStatus(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAlertingConfig(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMAlertGroups(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMAlertGroups(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAMAlertGroups(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAMAlerts(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMStatus(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAMStatus(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAlertingConfig(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaReceivers(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaReceivers(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaReceivers(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
silenceIdParam := web.Params(ctx.Req)[":SilenceId"]
|
||||
return f.handleRouteGetGrafanaSilence(ctx, silenceIdParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaSilences(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaSilences(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaSilences(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
silenceIdParam := web.Params(ctx.Req)[":SilenceId"]
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetSilence(ctx, silenceIdParam, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetSilences(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetSilences(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetSilences(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RoutePostAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RoutePostAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
// Parse Request Body
|
||||
@@ -145,7 +145,7 @@ func (f *AlertmanagerApiHandler) RoutePostAMAlerts(ctx *models.ReqContext) respo
|
||||
}
|
||||
return f.handleRoutePostAMAlerts(ctx, conf, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RoutePostAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RoutePostAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
// Parse Request Body
|
||||
@@ -155,7 +155,7 @@ func (f *AlertmanagerApiHandler) RoutePostAlertingConfig(ctx *models.ReqContext)
|
||||
}
|
||||
return f.handleRoutePostAlertingConfig(ctx, conf, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RoutePostGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RoutePostGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.PostableUserConfig{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -163,7 +163,7 @@ func (f *AlertmanagerApiHandler) RoutePostGrafanaAlertingConfig(ctx *models.ReqC
|
||||
}
|
||||
return f.handleRoutePostGrafanaAlertingConfig(ctx, conf)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RoutePostTestGrafanaReceivers(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RoutePostTestGrafanaReceivers(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.TestReceiversConfigBodyParams{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
|
||||
@@ -12,33 +12,33 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type ConfigurationApi interface {
|
||||
RouteDeleteNGalertConfig(*models.ReqContext) response.Response
|
||||
RouteGetAlertmanagers(*models.ReqContext) response.Response
|
||||
RouteGetNGalertConfig(*models.ReqContext) response.Response
|
||||
RouteGetStatus(*models.ReqContext) response.Response
|
||||
RoutePostNGalertConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteNGalertConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertmanagers(*contextmodel.ReqContext) response.Response
|
||||
RouteGetNGalertConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetStatus(*contextmodel.ReqContext) response.Response
|
||||
RoutePostNGalertConfig(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) RouteDeleteNGalertConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RouteDeleteNGalertConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteDeleteNGalertConfig(ctx)
|
||||
}
|
||||
func (f *ConfigurationApiHandler) RouteGetAlertmanagers(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RouteGetAlertmanagers(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetAlertmanagers(ctx)
|
||||
}
|
||||
func (f *ConfigurationApiHandler) RouteGetNGalertConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RouteGetNGalertConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetNGalertConfig(ctx)
|
||||
}
|
||||
func (f *ConfigurationApiHandler) RouteGetStatus(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RouteGetStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetStatus(ctx)
|
||||
}
|
||||
func (f *ConfigurationApiHandler) RoutePostNGalertConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RoutePostNGalertConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.PostableNGalertConfig{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
|
||||
@@ -12,30 +12,30 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type PrometheusApi interface {
|
||||
RouteGetAlertStatuses(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAlertStatuses(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaRuleStatuses(*models.ReqContext) response.Response
|
||||
RouteGetRuleStatuses(*models.ReqContext) response.Response
|
||||
RouteGetAlertStatuses(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAlertStatuses(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaRuleStatuses(*contextmodel.ReqContext) response.Response
|
||||
RouteGetRuleStatuses(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) RouteGetAlertStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) RouteGetAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAlertStatuses(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *PrometheusApiHandler) RouteGetGrafanaAlertStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) RouteGetGrafanaAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAlertStatuses(ctx)
|
||||
}
|
||||
func (f *PrometheusApiHandler) RouteGetGrafanaRuleStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) RouteGetGrafanaRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaRuleStatuses(ctx)
|
||||
}
|
||||
func (f *PrometheusApiHandler) RouteGetRuleStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) RouteGetRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetRuleStatuses(ctx, datasourceUIDParam)
|
||||
|
||||
@@ -12,95 +12,95 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type ProvisioningApi interface {
|
||||
RouteDeleteAlertRule(*models.ReqContext) response.Response
|
||||
RouteDeleteContactpoints(*models.ReqContext) response.Response
|
||||
RouteDeleteMuteTiming(*models.ReqContext) response.Response
|
||||
RouteDeleteTemplate(*models.ReqContext) response.Response
|
||||
RouteGetAlertRule(*models.ReqContext) response.Response
|
||||
RouteGetAlertRuleGroup(*models.ReqContext) response.Response
|
||||
RouteGetAlertRules(*models.ReqContext) response.Response
|
||||
RouteGetContactpoints(*models.ReqContext) response.Response
|
||||
RouteGetMuteTiming(*models.ReqContext) response.Response
|
||||
RouteGetMuteTimings(*models.ReqContext) response.Response
|
||||
RouteGetPolicyTree(*models.ReqContext) response.Response
|
||||
RouteGetTemplate(*models.ReqContext) response.Response
|
||||
RouteGetTemplates(*models.ReqContext) response.Response
|
||||
RoutePostAlertRule(*models.ReqContext) response.Response
|
||||
RoutePostContactpoints(*models.ReqContext) response.Response
|
||||
RoutePostMuteTiming(*models.ReqContext) response.Response
|
||||
RoutePutAlertRule(*models.ReqContext) response.Response
|
||||
RoutePutAlertRuleGroup(*models.ReqContext) response.Response
|
||||
RoutePutContactpoint(*models.ReqContext) response.Response
|
||||
RoutePutMuteTiming(*models.ReqContext) response.Response
|
||||
RoutePutPolicyTree(*models.ReqContext) response.Response
|
||||
RoutePutTemplate(*models.ReqContext) response.Response
|
||||
RouteResetPolicyTree(*models.ReqContext) response.Response
|
||||
RouteDeleteAlertRule(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteContactpoints(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteMuteTiming(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteTemplate(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertRule(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertRuleGroup(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertRules(*contextmodel.ReqContext) response.Response
|
||||
RouteGetContactpoints(*contextmodel.ReqContext) response.Response
|
||||
RouteGetMuteTiming(*contextmodel.ReqContext) response.Response
|
||||
RouteGetMuteTimings(*contextmodel.ReqContext) response.Response
|
||||
RouteGetPolicyTree(*contextmodel.ReqContext) response.Response
|
||||
RouteGetTemplate(*contextmodel.ReqContext) response.Response
|
||||
RouteGetTemplates(*contextmodel.ReqContext) response.Response
|
||||
RoutePostAlertRule(*contextmodel.ReqContext) response.Response
|
||||
RoutePostContactpoints(*contextmodel.ReqContext) response.Response
|
||||
RoutePostMuteTiming(*contextmodel.ReqContext) response.Response
|
||||
RoutePutAlertRule(*contextmodel.ReqContext) response.Response
|
||||
RoutePutAlertRuleGroup(*contextmodel.ReqContext) response.Response
|
||||
RoutePutContactpoint(*contextmodel.ReqContext) response.Response
|
||||
RoutePutMuteTiming(*contextmodel.ReqContext) response.Response
|
||||
RoutePutPolicyTree(*contextmodel.ReqContext) response.Response
|
||||
RoutePutTemplate(*contextmodel.ReqContext) response.Response
|
||||
RouteResetPolicyTree(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) RouteDeleteAlertRule(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteDeleteAlertRule(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
return f.handleRouteDeleteAlertRule(ctx, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteDeleteContactpoints(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteDeleteContactpoints(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
return f.handleRouteDeleteContactpoints(ctx, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteDeleteMuteTiming(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteDeleteMuteTiming(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
return f.handleRouteDeleteMuteTiming(ctx, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteDeleteTemplate(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteDeleteTemplate(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
return f.handleRouteDeleteTemplate(ctx, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRule(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRule(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
return f.handleRouteGetAlertRule(ctx, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRuleGroup(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRuleGroup(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
folderUIDParam := web.Params(ctx.Req)[":FolderUID"]
|
||||
groupParam := web.Params(ctx.Req)[":Group"]
|
||||
return f.handleRouteGetAlertRuleGroup(ctx, folderUIDParam, groupParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRules(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRules(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetAlertRules(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetContactpoints(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetContactpoints(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetContactpoints(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetMuteTiming(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetMuteTiming(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
return f.handleRouteGetMuteTiming(ctx, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetMuteTimings(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetMuteTimings(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetMuteTimings(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetPolicyTree(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetTemplate(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetTemplate(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
return f.handleRouteGetTemplate(ctx, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetTemplates(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetTemplates(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetTemplates(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePostAlertRule(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePostAlertRule(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.ProvisionedAlertRule{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -108,7 +108,7 @@ func (f *ProvisioningApiHandler) RoutePostAlertRule(ctx *models.ReqContext) resp
|
||||
}
|
||||
return f.handleRoutePostAlertRule(ctx, conf)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePostContactpoints(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePostContactpoints(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.EmbeddedContactPoint{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -116,7 +116,7 @@ func (f *ProvisioningApiHandler) RoutePostContactpoints(ctx *models.ReqContext)
|
||||
}
|
||||
return f.handleRoutePostContactpoints(ctx, conf)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePostMuteTiming(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePostMuteTiming(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.MuteTimeInterval{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -124,7 +124,7 @@ func (f *ProvisioningApiHandler) RoutePostMuteTiming(ctx *models.ReqContext) res
|
||||
}
|
||||
return f.handleRoutePostMuteTiming(ctx, conf)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutAlertRule(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutAlertRule(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
// Parse Request Body
|
||||
@@ -134,7 +134,7 @@ func (f *ProvisioningApiHandler) RoutePutAlertRule(ctx *models.ReqContext) respo
|
||||
}
|
||||
return f.handleRoutePutAlertRule(ctx, conf, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutAlertRuleGroup(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutAlertRuleGroup(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
folderUIDParam := web.Params(ctx.Req)[":FolderUID"]
|
||||
groupParam := web.Params(ctx.Req)[":Group"]
|
||||
@@ -145,7 +145,7 @@ func (f *ProvisioningApiHandler) RoutePutAlertRuleGroup(ctx *models.ReqContext)
|
||||
}
|
||||
return f.handleRoutePutAlertRuleGroup(ctx, conf, folderUIDParam, groupParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutContactpoint(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutContactpoint(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
// Parse Request Body
|
||||
@@ -155,7 +155,7 @@ func (f *ProvisioningApiHandler) RoutePutContactpoint(ctx *models.ReqContext) re
|
||||
}
|
||||
return f.handleRoutePutContactpoint(ctx, conf, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutMuteTiming(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutMuteTiming(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
// Parse Request Body
|
||||
@@ -165,7 +165,7 @@ func (f *ProvisioningApiHandler) RoutePutMuteTiming(ctx *models.ReqContext) resp
|
||||
}
|
||||
return f.handleRoutePutMuteTiming(ctx, conf, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.Route{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -173,7 +173,7 @@ func (f *ProvisioningApiHandler) RoutePutPolicyTree(ctx *models.ReqContext) resp
|
||||
}
|
||||
return f.handleRoutePutPolicyTree(ctx, conf)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutTemplate(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutTemplate(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
// Parse Request Body
|
||||
@@ -183,7 +183,7 @@ func (f *ProvisioningApiHandler) RoutePutTemplate(ctx *models.ReqContext) respon
|
||||
}
|
||||
return f.handleRoutePutTemplate(ctx, conf, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteResetPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteResetPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteResetPolicyTree(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,84 +12,84 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type RulerApi interface {
|
||||
RouteDeleteGrafanaRuleGroupConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteNamespaceGrafanaRulesConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteNamespaceRulesConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteRuleGroupConfig(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaRuleGroupConfig(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaRulesConfig(*models.ReqContext) response.Response
|
||||
RouteGetNamespaceGrafanaRulesConfig(*models.ReqContext) response.Response
|
||||
RouteGetNamespaceRulesConfig(*models.ReqContext) response.Response
|
||||
RouteGetRulegGroupConfig(*models.ReqContext) response.Response
|
||||
RouteGetRulesConfig(*models.ReqContext) response.Response
|
||||
RoutePostNameGrafanaRulesConfig(*models.ReqContext) response.Response
|
||||
RoutePostNameRulesConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteGrafanaRuleGroupConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteNamespaceGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteNamespaceRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteRuleGroupConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaRuleGroupConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetNamespaceGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetNamespaceRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetRulegGroupConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostNameGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostNameRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) RouteDeleteGrafanaRuleGroupConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteDeleteGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
||||
return f.handleRouteDeleteGrafanaRuleGroupConfig(ctx, namespaceParam, groupnameParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteDeleteNamespaceGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteDeleteNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
return f.handleRouteDeleteNamespaceGrafanaRulesConfig(ctx, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteDeleteNamespaceRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteDeleteNamespaceRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
return f.handleRouteDeleteNamespaceRulesConfig(ctx, datasourceUIDParam, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteDeleteRuleGroupConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteDeleteRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
||||
return f.handleRouteDeleteRuleGroupConfig(ctx, datasourceUIDParam, namespaceParam, groupnameParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetGrafanaRuleGroupConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
||||
return f.handleRouteGetGrafanaRuleGroupConfig(ctx, namespaceParam, groupnameParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaRulesConfig(ctx)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetNamespaceGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
return f.handleRouteGetNamespaceGrafanaRulesConfig(ctx, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetNamespaceRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetNamespaceRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
return f.handleRouteGetNamespaceRulesConfig(ctx, datasourceUIDParam, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetRulegGroupConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetRulegGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
||||
return f.handleRouteGetRulegGroupConfig(ctx, datasourceUIDParam, namespaceParam, groupnameParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetRulesConfig(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RoutePostNameGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RoutePostNameGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
// Parse Request Body
|
||||
@@ -99,7 +99,7 @@ func (f *RulerApiHandler) RoutePostNameGrafanaRulesConfig(ctx *models.ReqContext
|
||||
}
|
||||
return f.handleRoutePostNameGrafanaRulesConfig(ctx, conf, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RoutePostNameRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RoutePostNameRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
|
||||
@@ -12,20 +12,20 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type TestingApi interface {
|
||||
BacktestConfig(*models.ReqContext) response.Response
|
||||
RouteEvalQueries(*models.ReqContext) response.Response
|
||||
RouteTestRuleConfig(*models.ReqContext) response.Response
|
||||
RouteTestRuleGrafanaConfig(*models.ReqContext) response.Response
|
||||
BacktestConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteEvalQueries(*contextmodel.ReqContext) response.Response
|
||||
RouteTestRuleConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteTestRuleGrafanaConfig(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) BacktestConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *TestingApiHandler) BacktestConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.BacktestConfig{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -33,7 +33,7 @@ func (f *TestingApiHandler) BacktestConfig(ctx *models.ReqContext) response.Resp
|
||||
}
|
||||
return f.handleBacktestConfig(ctx, conf)
|
||||
}
|
||||
func (f *TestingApiHandler) RouteEvalQueries(ctx *models.ReqContext) response.Response {
|
||||
func (f *TestingApiHandler) RouteEvalQueries(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.EvalQueriesPayload{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -41,7 +41,7 @@ func (f *TestingApiHandler) RouteEvalQueries(ctx *models.ReqContext) response.Re
|
||||
}
|
||||
return f.handleRouteEvalQueries(ctx, conf)
|
||||
}
|
||||
func (f *TestingApiHandler) RouteTestRuleConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *TestingApiHandler) RouteTestRuleConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
// Parse Request Body
|
||||
@@ -51,7 +51,7 @@ func (f *TestingApiHandler) RouteTestRuleConfig(ctx *models.ReqContext) response
|
||||
}
|
||||
return f.handleRouteTestRuleConfig(ctx, conf, datasourceUIDParam)
|
||||
}
|
||||
func (f *TestingApiHandler) RouteTestRuleGrafanaConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *TestingApiHandler) RouteTestRuleGrafanaConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.TestRulePayload{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -61,7 +61,7 @@ func NewLotexAM(proxy *AlertingProxy, log log.Logger) *LotexAM {
|
||||
}
|
||||
|
||||
func (am *LotexAM) withAMReq(
|
||||
ctx *models.ReqContext,
|
||||
ctx *contextmodel.ReqContext,
|
||||
method string,
|
||||
endpoint string,
|
||||
pathParams []string,
|
||||
@@ -110,7 +110,7 @@ func (am *LotexAM) withAMReq(
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetAMStatus(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetAMStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -122,7 +122,7 @@ func (am *LotexAM) RouteGetAMStatus(ctx *models.ReqContext) response.Response {
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteCreateSilence(ctx *models.ReqContext, silenceBody apimodels.PostableSilence) response.Response {
|
||||
func (am *LotexAM) RouteCreateSilence(ctx *contextmodel.ReqContext, silenceBody apimodels.PostableSilence) response.Response {
|
||||
blob, err := json.Marshal(silenceBody)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "Failed marshal silence")
|
||||
@@ -138,7 +138,7 @@ func (am *LotexAM) RouteCreateSilence(ctx *models.ReqContext, silenceBody apimod
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteDeleteAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteDeleteAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodDelete,
|
||||
@@ -150,7 +150,7 @@ func (am *LotexAM) RouteDeleteAlertingConfig(ctx *models.ReqContext) response.Re
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteDeleteSilence(ctx *models.ReqContext, silenceID string) response.Response {
|
||||
func (am *LotexAM) RouteDeleteSilence(ctx *contextmodel.ReqContext, silenceID string) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodDelete,
|
||||
@@ -162,7 +162,7 @@ func (am *LotexAM) RouteDeleteSilence(ctx *models.ReqContext, silenceID string)
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -174,7 +174,7 @@ func (am *LotexAM) RouteGetAlertingConfig(ctx *models.ReqContext) response.Respo
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetAMAlertGroups(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetAMAlertGroups(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -186,7 +186,7 @@ func (am *LotexAM) RouteGetAMAlertGroups(ctx *models.ReqContext) response.Respon
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -198,7 +198,7 @@ func (am *LotexAM) RouteGetAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetSilence(ctx *models.ReqContext, silenceID string) response.Response {
|
||||
func (am *LotexAM) RouteGetSilence(ctx *contextmodel.ReqContext, silenceID string) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -210,7 +210,7 @@ func (am *LotexAM) RouteGetSilence(ctx *models.ReqContext, silenceID string) res
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetSilences(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetSilences(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -222,7 +222,7 @@ func (am *LotexAM) RouteGetSilences(ctx *models.ReqContext) response.Response {
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RoutePostAlertingConfig(ctx *models.ReqContext, config apimodels.PostableUserConfig) response.Response {
|
||||
func (am *LotexAM) RoutePostAlertingConfig(ctx *contextmodel.ReqContext, config apimodels.PostableUserConfig) response.Response {
|
||||
yml, err := yaml.Marshal(&config)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "Failed marshal alert manager configuration ")
|
||||
@@ -239,7 +239,7 @@ func (am *LotexAM) RoutePostAlertingConfig(ctx *models.ReqContext, config apimod
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RoutePostAMAlerts(ctx *models.ReqContext, alerts apimodels.PostableAlerts) response.Response {
|
||||
func (am *LotexAM) RoutePostAMAlerts(ctx *contextmodel.ReqContext, alerts apimodels.PostableAlerts) response.Response {
|
||||
yml, err := yaml.Marshal(alerts)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "Failed marshal postable alerts")
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -38,7 +38,7 @@ func NewLotexProm(proxy *AlertingProxy, log log.Logger) *LotexProm {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *LotexProm) RouteGetAlertStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (p *LotexProm) RouteGetAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
endpoints, err := p.getEndpoints(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -57,7 +57,7 @@ func (p *LotexProm) RouteGetAlertStatuses(ctx *models.ReqContext) response.Respo
|
||||
)
|
||||
}
|
||||
|
||||
func (p *LotexProm) RouteGetRuleStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (p *LotexProm) RouteGetRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
endpoints, err := p.getEndpoints(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -76,7 +76,7 @@ func (p *LotexProm) RouteGetRuleStatuses(ctx *models.ReqContext) response.Respon
|
||||
)
|
||||
}
|
||||
|
||||
func (p *LotexProm) getEndpoints(ctx *models.ReqContext) (*promEndpoints, error) {
|
||||
func (p *LotexProm) getEndpoints(ctx *contextmodel.ReqContext) (*promEndpoints, error) {
|
||||
datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
if datasourceUID == "" {
|
||||
return nil, fmt.Errorf("datasource UID is invalid")
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -55,7 +55,7 @@ func NewLotexRuler(proxy *AlertingProxy, log log.Logger) *LotexRuler {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteDeleteNamespaceRulesConfig(ctx *models.ReqContext, namespace string) response.Response {
|
||||
func (r *LotexRuler) RouteDeleteNamespaceRulesConfig(ctx *contextmodel.ReqContext, namespace string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -73,7 +73,7 @@ func (r *LotexRuler) RouteDeleteNamespaceRulesConfig(ctx *models.ReqContext, nam
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteDeleteRuleGroupConfig(ctx *models.ReqContext, namespace string, group string) response.Response {
|
||||
func (r *LotexRuler) RouteDeleteRuleGroupConfig(ctx *contextmodel.ReqContext, namespace string, group string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -96,7 +96,7 @@ func (r *LotexRuler) RouteDeleteRuleGroupConfig(ctx *models.ReqContext, namespac
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteGetNamespaceRulesConfig(ctx *models.ReqContext, namespace string) response.Response {
|
||||
func (r *LotexRuler) RouteGetNamespaceRulesConfig(ctx *contextmodel.ReqContext, namespace string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -118,7 +118,7 @@ func (r *LotexRuler) RouteGetNamespaceRulesConfig(ctx *models.ReqContext, namesp
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteGetRulegGroupConfig(ctx *models.ReqContext, namespace string, group string) response.Response {
|
||||
func (r *LotexRuler) RouteGetRulegGroupConfig(ctx *contextmodel.ReqContext, namespace string, group string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -141,7 +141,7 @@ func (r *LotexRuler) RouteGetRulegGroupConfig(ctx *models.ReqContext, namespace
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteGetRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (r *LotexRuler) RouteGetRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -160,7 +160,7 @@ func (r *LotexRuler) RouteGetRulesConfig(ctx *models.ReqContext) response.Respon
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RoutePostNameRulesConfig(ctx *models.ReqContext, conf apimodels.PostableRuleGroupConfig, ns string) response.Response {
|
||||
func (r *LotexRuler) RoutePostNameRulesConfig(ctx *contextmodel.ReqContext, conf apimodels.PostableRuleGroupConfig, ns string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -173,7 +173,7 @@ func (r *LotexRuler) RoutePostNameRulesConfig(ctx *models.ReqContext, conf apimo
|
||||
return r.withReq(ctx, http.MethodPost, u, bytes.NewBuffer(yml), jsonExtractor(nil), nil)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) validateAndGetPrefix(ctx *models.ReqContext) (string, error) {
|
||||
func (r *LotexRuler) validateAndGetPrefix(ctx *contextmodel.ReqContext) (string, error) {
|
||||
datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
if datasourceUID == "" {
|
||||
return "", fmt.Errorf("datasource UID is invalid")
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasourceproxy"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -98,7 +98,7 @@ func TestLotexRuler_ValidateAndGetPrefix(t *testing.T) {
|
||||
// Setup request context.
|
||||
httpReq, err := http.NewRequest(http.MethodGet, "http://grafanacloud.com"+tt.urlParams, nil)
|
||||
require.NoError(t, err)
|
||||
ctx := &models.ReqContext{Context: &web.Context{Req: web.SetURLParams(httpReq, tt.namedParams)}}
|
||||
ctx := &contextmodel.ReqContext{Context: &web.Context{Req: web.SetURLParams(httpReq, tt.namedParams)}}
|
||||
|
||||
prefix, err := ruler.validateAndGetPrefix(ctx)
|
||||
require.Equal(t, tt.expected, prefix)
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
|
||||
@@ -16,94 +16,94 @@ func NewProvisioningApi(svc *ProvisioningSrv) *ProvisioningApiHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetPolicyTree(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutPolicyTree(ctx *models.ReqContext, route apimodels.Route) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutPolicyTree(ctx *contextmodel.ReqContext, route apimodels.Route) response.Response {
|
||||
return f.svc.RoutePutPolicyTree(ctx, route)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetContactpoints(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetContactpoints(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetContactPoints(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePostContactpoints(ctx *models.ReqContext, cp apimodels.EmbeddedContactPoint) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePostContactpoints(ctx *contextmodel.ReqContext, cp apimodels.EmbeddedContactPoint) response.Response {
|
||||
return f.svc.RoutePostContactPoint(ctx, cp)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutContactpoint(ctx *models.ReqContext, cp apimodels.EmbeddedContactPoint, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutContactpoint(ctx *contextmodel.ReqContext, cp apimodels.EmbeddedContactPoint, UID string) response.Response {
|
||||
return f.svc.RoutePutContactPoint(ctx, cp, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteContactpoints(ctx *models.ReqContext, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteContactpoints(ctx *contextmodel.ReqContext, UID string) response.Response {
|
||||
return f.svc.RouteDeleteContactPoint(ctx, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetTemplates(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetTemplates(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetTemplates(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetTemplate(ctx *models.ReqContext, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetTemplate(ctx *contextmodel.ReqContext, name string) response.Response {
|
||||
return f.svc.RouteGetTemplate(ctx, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutTemplate(ctx *models.ReqContext, body apimodels.NotificationTemplateContent, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutTemplate(ctx *contextmodel.ReqContext, body apimodels.NotificationTemplateContent, name string) response.Response {
|
||||
return f.svc.RoutePutTemplate(ctx, body, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteTemplate(ctx *models.ReqContext, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteTemplate(ctx *contextmodel.ReqContext, name string) response.Response {
|
||||
return f.svc.RouteDeleteTemplate(ctx, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetMuteTiming(ctx *models.ReqContext, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetMuteTiming(ctx *contextmodel.ReqContext, name string) response.Response {
|
||||
return f.svc.RouteGetMuteTiming(ctx, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetMuteTimings(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetMuteTimings(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetMuteTimings(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePostMuteTiming(ctx *models.ReqContext, mt apimodels.MuteTimeInterval) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePostMuteTiming(ctx *contextmodel.ReqContext, mt apimodels.MuteTimeInterval) response.Response {
|
||||
return f.svc.RoutePostMuteTiming(ctx, mt)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutMuteTiming(ctx *models.ReqContext, mt apimodels.MuteTimeInterval, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutMuteTiming(ctx *contextmodel.ReqContext, mt apimodels.MuteTimeInterval, name string) response.Response {
|
||||
return f.svc.RoutePutMuteTiming(ctx, mt, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteMuteTiming(ctx *models.ReqContext, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteMuteTiming(ctx *contextmodel.ReqContext, name string) response.Response {
|
||||
return f.svc.RouteDeleteMuteTiming(ctx, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRules(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRules(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetAlertRules(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRule(ctx *models.ReqContext, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRule(ctx *contextmodel.ReqContext, UID string) response.Response {
|
||||
return f.svc.RouteRouteGetAlertRule(ctx, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePostAlertRule(ctx *models.ReqContext, ar apimodels.ProvisionedAlertRule) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePostAlertRule(ctx *contextmodel.ReqContext, ar apimodels.ProvisionedAlertRule) response.Response {
|
||||
return f.svc.RoutePostAlertRule(ctx, ar)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutAlertRule(ctx *models.ReqContext, ar apimodels.ProvisionedAlertRule, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutAlertRule(ctx *contextmodel.ReqContext, ar apimodels.ProvisionedAlertRule, UID string) response.Response {
|
||||
return f.svc.RoutePutAlertRule(ctx, ar, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteAlertRule(ctx *models.ReqContext, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteAlertRule(ctx *contextmodel.ReqContext, UID string) response.Response {
|
||||
return f.svc.RouteDeleteAlertRule(ctx, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteResetPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteResetPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteResetPolicyTree(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRuleGroup(ctx *models.ReqContext, folder, group string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRuleGroup(ctx *contextmodel.ReqContext, folder, group string) response.Response {
|
||||
return f.svc.RouteGetAlertRuleGroup(ctx, folder, group)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutAlertRuleGroup(ctx *models.ReqContext, ag apimodels.AlertRuleGroup, folder, group string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutAlertRuleGroup(ctx *contextmodel.ReqContext, ag apimodels.AlertRuleGroup, folder, group string) response.Response {
|
||||
return f.svc.RoutePutAlertRuleGroup(ctx, ag, folder, group)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
|
||||
@@ -17,18 +17,18 @@ func NewTestingApi(svc *TestingApiSrv) *TestingApiHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) handleRouteTestRuleConfig(c *models.ReqContext, body apimodels.TestRulePayload, dsUID string) response.Response {
|
||||
func (f *TestingApiHandler) handleRouteTestRuleConfig(c *contextmodel.ReqContext, body apimodels.TestRulePayload, dsUID string) response.Response {
|
||||
return f.svc.RouteTestRuleConfig(c, body, dsUID)
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) handleRouteTestRuleGrafanaConfig(c *models.ReqContext, body apimodels.TestRulePayload) response.Response {
|
||||
func (f *TestingApiHandler) handleRouteTestRuleGrafanaConfig(c *contextmodel.ReqContext, body apimodels.TestRulePayload) response.Response {
|
||||
return f.svc.RouteTestGrafanaRuleConfig(c, body)
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) handleRouteEvalQueries(c *models.ReqContext, body apimodels.EvalQueriesPayload) response.Response {
|
||||
func (f *TestingApiHandler) handleRouteEvalQueries(c *contextmodel.ReqContext, body apimodels.EvalQueriesPayload) response.Response {
|
||||
return f.svc.RouteEvalQueries(c, body)
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) handleBacktestConfig(ctx *models.ReqContext, conf apimodels.BacktestConfig) response.Response {
|
||||
func (f *TestingApiHandler) handleBacktestConfig(ctx *contextmodel.ReqContext, conf apimodels.BacktestConfig) response.Response {
|
||||
return f.svc.BacktestAlertRule(ctx, conf)
|
||||
}
|
||||
|
||||
@@ -11,14 +11,15 @@ import (
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
type {{classname}} interface { {{#operation}}
|
||||
{{nickname}}(*models.ReqContext) response.Response{{/operation}}
|
||||
{{nickname}}(*contextmodel.ReqContext) response.Response{{/operation}}
|
||||
}
|
||||
|
||||
{{#operations}}{{#operation}}
|
||||
func (f *{{classname}}Handler) {{nickname}}(ctx *models.ReqContext) response.Response { {{#hasPathParams}}
|
||||
func (f *{{classname}}Handler) {{nickname}}(ctx *contextmodel.ReqContext) response.Response { {{#hasPathParams}}
|
||||
// Parse Path Parameters{{/hasPathParams}}{{#pathParams}}
|
||||
{{paramName}}Param := web.Params(ctx.Req)[":{{baseName}}"]{{/pathParams}}
|
||||
{{#bodyParams}}
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasourceproxy"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -34,7 +34,7 @@ func toMacaronPath(path string) string {
|
||||
}))
|
||||
}
|
||||
|
||||
func getDatasourceByUID(ctx *models.ReqContext, cache datasources.CacheService, expectedType apimodels.Backend) (*datasources.DataSource, error) {
|
||||
func getDatasourceByUID(ctx *contextmodel.ReqContext, cache datasources.CacheService, expectedType apimodels.Backend) (*datasources.DataSource, error) {
|
||||
datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
ds, err := cache.GetDatasourceByUID(ctx.Req.Context(), datasourceUID, ctx.SignedInUser, ctx.SkipCache)
|
||||
if err != nil {
|
||||
@@ -69,12 +69,12 @@ func (w *safeMacaronWrapper) CloseNotify() <-chan bool {
|
||||
|
||||
// createProxyContext creates a new request context that is provided down to the data source proxy.
|
||||
// The request context
|
||||
// 1. overwrites the underlying response writer used by a *models.ReqContext because AlertingProxy needs to intercept
|
||||
// 1. overwrites the underlying response writer used by a *contextmodel.ReqContext because AlertingProxy needs to intercept
|
||||
// the response from the data source to analyze it and probably change
|
||||
// 2. elevates the current user permissions to Editor if both conditions are met: RBAC is enabled, user does not have Editor role.
|
||||
// This is needed to bypass the plugin authorization, which still relies on the legacy roles.
|
||||
// This elevation can be considered safe because all upstream calls are protected by the RBAC on web request router level.
|
||||
func (p *AlertingProxy) createProxyContext(ctx *models.ReqContext, request *http.Request, response *response.NormalResponse) *models.ReqContext {
|
||||
func (p *AlertingProxy) createProxyContext(ctx *contextmodel.ReqContext, request *http.Request, response *response.NormalResponse) *contextmodel.ReqContext {
|
||||
cpy := *ctx
|
||||
cpyMCtx := *cpy.Context
|
||||
cpyMCtx.Resp = web.NewResponseWriter(ctx.Req.Method, &safeMacaronWrapper{response})
|
||||
@@ -100,7 +100,7 @@ type AlertingProxy struct {
|
||||
|
||||
// withReq proxies a different request
|
||||
func (p *AlertingProxy) withReq(
|
||||
ctx *models.ReqContext,
|
||||
ctx *contextmodel.ReqContext,
|
||||
method string,
|
||||
u *url.URL,
|
||||
body io.Reader,
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/auth"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
models2 "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -41,7 +41,7 @@ func TestToMacaronPath(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAlertingProxy_createProxyContext(t *testing.T) {
|
||||
ctx := &models.ReqContext{
|
||||
ctx := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user