@ -9,22 +9,22 @@ import (
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
)
type Forked AlertmanagerApi struct {
type AlertmanagerApiHandler struct {
AMSvc * LotexAM
GrafanaSvc * AlertmanagerSrv
DatasourceCache datasources . CacheService
}
// NewForked AM implements a set of routes that proxy to various Alertmanager-compatible backends.
func NewForked AM ( datasourceCache datasources . CacheService , proxy * LotexAM , grafana * AlertmanagerSrv ) * Forked AlertmanagerApi {
return & Forked AlertmanagerApi{
// NewForking AM implements a set of routes that proxy to various Alertmanager-compatible backends.
func NewForking AM ( datasourceCache datasources . CacheService , proxy * LotexAM , grafana * AlertmanagerSrv ) * AlertmanagerApiHandler {
return & AlertmanagerApiHandler {
AMSvc : proxy ,
GrafanaSvc : grafana ,
DatasourceCache : datasourceCache ,
}
}
func ( f * Forked AlertmanagerApi) getService ( ctx * models . ReqContext ) ( * LotexAM , error ) {
func ( f * AlertmanagerApiHandler ) getService ( ctx * models . ReqContext ) ( * LotexAM , error ) {
t , err := backendTypeByUID ( ctx , f . DatasourceCache )
if err != nil {
return nil , err
@ -38,7 +38,7 @@ func (f *ForkedAlertmanagerApi) getService(ctx *models.ReqContext) (*LotexAM, er
}
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetAMStatus( ctx * models . ReqContext , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetAMStatus( ctx * models . ReqContext , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return response . Error ( 400 , err . Error ( ) , nil )
@ -47,7 +47,7 @@ func (f *ForkedAlertmanagerApi) forkRouteGetAMStatus(ctx *models.ReqContext, dsU
return s . RouteGetAMStatus ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteCreateSilence( ctx * models . ReqContext , body apimodels . PostableSilence , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteCreateSilence( ctx * models . ReqContext , body apimodels . PostableSilence , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -56,7 +56,7 @@ func (f *ForkedAlertmanagerApi) forkRouteCreateSilence(ctx *models.ReqContext, b
return s . RouteCreateSilence ( ctx , body )
}
func ( f * ForkedAlertmanagerApi ) fork RouteDeleteAlertingConfig( ctx * models . ReqContext , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteDeleteAlertingConfig( ctx * models . ReqContext , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -65,7 +65,7 @@ func (f *ForkedAlertmanagerApi) forkRouteDeleteAlertingConfig(ctx *models.ReqCon
return s . RouteDeleteAlertingConfig ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteDeleteSilence( ctx * models . ReqContext , silenceID string , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteDeleteSilence( ctx * models . ReqContext , silenceID string , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -74,7 +74,7 @@ func (f *ForkedAlertmanagerApi) forkRouteDeleteSilence(ctx *models.ReqContext, s
return s . RouteDeleteSilence ( ctx , silenceID )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetAlertingConfig( ctx * models . ReqContext , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetAlertingConfig( ctx * models . ReqContext , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -83,7 +83,7 @@ func (f *ForkedAlertmanagerApi) forkRouteGetAlertingConfig(ctx *models.ReqContex
return s . RouteGetAlertingConfig ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetAMAlertGroups( ctx * models . ReqContext , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetAMAlertGroups( ctx * models . ReqContext , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -92,7 +92,7 @@ func (f *ForkedAlertmanagerApi) forkRouteGetAMAlertGroups(ctx *models.ReqContext
return s . RouteGetAMAlertGroups ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetAMAlerts( ctx * models . ReqContext , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetAMAlerts( ctx * models . ReqContext , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -101,7 +101,7 @@ func (f *ForkedAlertmanagerApi) forkRouteGetAMAlerts(ctx *models.ReqContext, dsU
return s . RouteGetAMAlerts ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetSilence( ctx * models . ReqContext , silenceID string , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetSilence( ctx * models . ReqContext , silenceID string , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -110,7 +110,7 @@ func (f *ForkedAlertmanagerApi) forkRouteGetSilence(ctx *models.ReqContext, sile
return s . RouteGetSilence ( ctx , silenceID )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetSilences( ctx * models . ReqContext , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetSilences( ctx * models . ReqContext , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -119,7 +119,7 @@ func (f *ForkedAlertmanagerApi) forkRouteGetSilences(ctx *models.ReqContext, dsU
return s . RouteGetSilences ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RoutePostAlertingConfig( ctx * models . ReqContext , body apimodels . PostableUserConfig , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RoutePostAlertingConfig( ctx * models . ReqContext , body apimodels . PostableUserConfig , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -137,7 +137,7 @@ func (f *ForkedAlertmanagerApi) forkRoutePostAlertingConfig(ctx *models.ReqConte
return s . RoutePostAlertingConfig ( ctx , body )
}
func ( f * ForkedAlertmanagerApi ) fork RoutePostAMAlerts( ctx * models . ReqContext , body apimodels . PostableAlerts , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RoutePostAMAlerts( ctx * models . ReqContext , body apimodels . PostableAlerts , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -146,7 +146,7 @@ func (f *ForkedAlertmanagerApi) forkRoutePostAMAlerts(ctx *models.ReqContext, bo
return s . RoutePostAMAlerts ( ctx , body )
}
func ( f * ForkedAlertmanagerApi ) fork RoutePostTestReceivers( ctx * models . ReqContext , body apimodels . TestReceiversConfigBodyParams , dsUID string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RoutePostTestReceivers( ctx * models . ReqContext , body apimodels . TestReceiversConfigBodyParams , dsUID string ) response . Response {
s , err := f . getService ( ctx )
if err != nil {
return ErrResp ( 400 , err , "" )
@ -155,50 +155,50 @@ func (f *ForkedAlertmanagerApi) forkRoutePostTestReceivers(ctx *models.ReqContex
return s . RoutePostTestReceivers ( ctx , body )
}
func ( f * ForkedAlertmanagerApi ) fork RouteDeleteGrafanaSilence( ctx * models . ReqContext , id string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteDeleteGrafanaSilence( ctx * models . ReqContext , id string ) response . Response {
return f . GrafanaSvc . RouteDeleteSilence ( ctx , id )
}
func ( f * ForkedAlertmanagerApi ) fork RouteDeleteGrafanaAlertingConfig( ctx * models . ReqContext ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteDeleteGrafanaAlertingConfig( ctx * models . ReqContext ) response . Response {
return f . GrafanaSvc . RouteDeleteAlertingConfig ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteCreateGrafanaSilence( ctx * models . ReqContext , body apimodels . PostableSilence ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteCreateGrafanaSilence( ctx * models . ReqContext , body apimodels . PostableSilence ) response . Response {
return f . GrafanaSvc . RouteCreateSilence ( ctx , body )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetGrafanaAMStatus( ctx * models . ReqContext ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetGrafanaAMStatus( ctx * models . ReqContext ) response . Response {
return f . GrafanaSvc . RouteGetAMStatus ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetGrafanaAMAlerts( ctx * models . ReqContext ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetGrafanaAMAlerts( ctx * models . ReqContext ) response . Response {
return f . GrafanaSvc . RouteGetAMAlerts ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetGrafanaAMAlertGroups( ctx * models . ReqContext ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetGrafanaAMAlertGroups( ctx * models . ReqContext ) response . Response {
return f . GrafanaSvc . RouteGetAMAlertGroups ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetGrafanaAlertingConfig( ctx * models . ReqContext ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetGrafanaAlertingConfig( ctx * models . ReqContext ) response . Response {
return f . GrafanaSvc . RouteGetAlertingConfig ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetGrafanaSilence( ctx * models . ReqContext , id string ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetGrafanaSilence( ctx * models . ReqContext , id string ) response . Response {
return f . GrafanaSvc . RouteGetSilence ( ctx , id )
}
func ( f * ForkedAlertmanagerApi ) fork RouteGetGrafanaSilences( ctx * models . ReqContext ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RouteGetGrafanaSilences( ctx * models . ReqContext ) response . Response {
return f . GrafanaSvc . RouteGetSilences ( ctx )
}
func ( f * ForkedAlertmanagerApi ) fork RoutePostGrafanaAMAlerts( ctx * models . ReqContext , conf apimodels . PostableAlerts ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RoutePostGrafanaAMAlerts( ctx * models . ReqContext , conf apimodels . PostableAlerts ) response . Response {
return f . GrafanaSvc . RoutePostAMAlerts ( ctx , conf )
}
func ( f * ForkedAlertmanagerApi ) fork RoutePostGrafanaAlertingConfig( ctx * models . ReqContext , conf apimodels . PostableUserConfig ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RoutePostGrafanaAlertingConfig( ctx * models . ReqContext , conf apimodels . PostableUserConfig ) response . Response {
return f . GrafanaSvc . RoutePostAlertingConfig ( ctx , conf )
}
func ( f * ForkedAlertmanagerApi ) fork RoutePostTestGrafanaReceivers( ctx * models . ReqContext , conf apimodels . TestReceiversConfigBodyParams ) response . Response {
func ( f * AlertmanagerApiHandler ) handle RoutePostTestGrafanaReceivers( ctx * models . ReqContext , conf apimodels . TestReceiversConfigBodyParams ) response . Response {
return f . GrafanaSvc . RoutePostTestReceivers ( ctx , conf )
}