Alerting: API to create extra Alertmanager configurations (#106904)
What is this feature?
Implements the POST endpoint for deleting imported Mimir Alertmanager configurations:
POST /api/convert/api/v1/alerts
The API endpoint creates the extra Alertmanager configuration with the provided identifier and matchers.
This commit is contained in:
@@ -128,6 +128,7 @@ type ConvertPrometheusSrv struct {
|
||||
|
||||
type Alertmanager interface {
|
||||
DeleteExtraConfiguration(ctx context.Context, org int64, identifier string) error
|
||||
SaveAndApplyExtraConfiguration(ctx context.Context, org int64, extraConfig apimodels.ExtraConfiguration) error
|
||||
GetAlertmanagerConfiguration(ctx context.Context, org int64, withAutogen bool) (apimodels.GettableUserConfig, error)
|
||||
}
|
||||
|
||||
@@ -532,7 +533,44 @@ func (srv *ConvertPrometheusSrv) convertToGrafanaRuleGroup(
|
||||
}
|
||||
|
||||
func (srv *ConvertPrometheusSrv) RouteConvertPrometheusPostAlertmanagerConfig(c *contextmodel.ReqContext, amCfg apimodels.AlertmanagerUserConfig) response.Response {
|
||||
return response.Error(http.StatusNotImplemented, "Not Implemented", nil)
|
||||
if !srv.featureToggles.IsEnabledGlobally(featuremgmt.FlagAlertingImportAlertmanagerAPI) {
|
||||
return response.Error(http.StatusNotImplemented, "Not Implemented", nil)
|
||||
}
|
||||
|
||||
logger := srv.logger.FromContext(c.Req.Context())
|
||||
|
||||
identifier, err := parseConfigIdentifierHeader(c)
|
||||
if err != nil {
|
||||
logger.Error("Failed to parse config identifier header", "error", err, "identifier", identifier)
|
||||
return errorToResponse(err)
|
||||
}
|
||||
|
||||
mergeMatchers, err := parseMergeMatchersHeader(c)
|
||||
if err != nil {
|
||||
logger.Error("Failed to parse merge matchers header", "error", err, "identifier", identifier)
|
||||
return errorToResponse(err)
|
||||
}
|
||||
|
||||
ec := apimodels.ExtraConfiguration{
|
||||
Identifier: identifier,
|
||||
MergeMatchers: mergeMatchers,
|
||||
TemplateFiles: amCfg.TemplateFiles,
|
||||
AlertmanagerConfig: amCfg.AlertmanagerConfig,
|
||||
}
|
||||
err = ec.Validate()
|
||||
if err != nil {
|
||||
logger.Error("Invalid alertmanager configuration", "error", err, "identifier", identifier)
|
||||
return errorToResponse(err)
|
||||
}
|
||||
|
||||
err = srv.am.SaveAndApplyExtraConfiguration(c.Req.Context(), c.GetOrgID(), ec)
|
||||
if err != nil {
|
||||
logger.Error("Failed to save alertmanager configuration", "error", err, "identifier", identifier)
|
||||
return errorToResponse(fmt.Errorf("failed to save alertmanager configuration: %w", err))
|
||||
}
|
||||
|
||||
logger.Info("Successfully updated alertmanager configuration with imported Prometheus config", "identifier", identifier)
|
||||
return successfulResponse()
|
||||
}
|
||||
|
||||
func (srv *ConvertPrometheusSrv) RouteConvertPrometheusGetAlertmanagerConfig(c *contextmodel.ReqContext) response.Response {
|
||||
|
||||
Reference in New Issue
Block a user