Alerting: Empty endpoints to manage alertmanager configurations (#106546)
This commit is contained in:
@@ -3,6 +3,7 @@ package definitions
|
||||
import (
|
||||
"github.com/prometheus/alertmanager/config"
|
||||
"github.com/prometheus/common/model"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Route for mimirtool
|
||||
@@ -204,7 +205,10 @@ import (
|
||||
// Route for `mimirtool alertmanager load`
|
||||
// swagger:route POST /convert/api/v1/alerts convert_prometheus RouteConvertPrometheusPostAlertmanagerConfig
|
||||
//
|
||||
// Load Alertmanager configuration to Grafana and merge it with the existing configuration.
|
||||
// Load extra Alertmanager configuration to Grafana and merge it with the existing configuration.
|
||||
// This endpoint allows importing Alertmanager configurations to Grafana. Each configuration is identified by
|
||||
// a unique identifier and can include merge matchers to select which alerts should be handled by
|
||||
// this specific configuration.
|
||||
//
|
||||
// Produces:
|
||||
// - application/json
|
||||
@@ -216,6 +220,32 @@ import (
|
||||
// Extensions:
|
||||
// x-raw-request: true
|
||||
|
||||
// Route for `mimirtool alertmanager get`
|
||||
// swagger:route GET /convert/api/v1/alerts convert_prometheus RouteConvertPrometheusGetAlertmanagerConfig
|
||||
//
|
||||
// Get extra Alertmanager configuration from Grafana.
|
||||
// Returns a specific imported Alertmanager configuration by its identifier.
|
||||
//
|
||||
// Produces:
|
||||
// - application/yaml
|
||||
//
|
||||
// Responses:
|
||||
// 200: GettableAlertmanagerUserConfig
|
||||
// 403: ForbiddenError
|
||||
|
||||
// Route for `mimirtool alertmanager delete`
|
||||
// swagger:route DELETE /convert/api/v1/alerts convert_prometheus RouteConvertPrometheusDeleteAlertmanagerConfig
|
||||
//
|
||||
// Delete extra Alertmanager configuration from Grafana by its identifier.
|
||||
// The main Grafana Alertmanager configuration remains unaffected.
|
||||
//
|
||||
// Produces:
|
||||
// - application/json
|
||||
//
|
||||
// Responses:
|
||||
// 202: ConvertPrometheusResponse
|
||||
// 403: ForbiddenError
|
||||
|
||||
// swagger:parameters RouteConvertPrometheusPostRuleGroup RouteConvertPrometheusCortexPostRuleGroup
|
||||
type RouteConvertPrometheusPostRuleGroupParams struct {
|
||||
// in: path
|
||||
@@ -286,11 +316,64 @@ type ConvertPrometheusResponse struct {
|
||||
|
||||
// swagger:parameters RouteConvertPrometheusPostAlertmanagerConfig
|
||||
type RouteConvertPrometheusPostAlertmanagerConfigParams struct {
|
||||
// Unique identifier for this Alertmanager configuration.
|
||||
// This identifier is used to distinguish between different imported configurations.
|
||||
// in: header
|
||||
Identifier string `json:"x-grafana-alerting-config-identifier"`
|
||||
// Comma-separated list of label matchers in 'key=value' format.
|
||||
// These matchers determine which alerts this configuration should handle.
|
||||
// For example: 'environment=production,team=backend' will only apply this
|
||||
// configuration to alerts matching both environment=production AND team=backend.
|
||||
// in: header
|
||||
MergeMatchers string `json:"x-grafana-alerting-merge-matchers"`
|
||||
// Alertmanager configuration including routing rules, receivers, and template files
|
||||
// in:body
|
||||
Body AlertmanagerUserConfig
|
||||
}
|
||||
|
||||
// swagger:parameters RouteConvertPrometheusGetAlertmanagerConfig
|
||||
type RouteConvertPrometheusGetAlertmanagerConfigParams struct {
|
||||
// Unique identifier for the Alertmanager configuration to retrieve.
|
||||
// in: header
|
||||
Identifier string `json:"x-grafana-alerting-config-identifier"`
|
||||
}
|
||||
|
||||
// swagger:parameters RouteConvertPrometheusDeleteAlertmanagerConfig
|
||||
type RouteConvertPrometheusDeleteAlertmanagerConfigParams struct {
|
||||
// Unique identifier for the Alertmanager configuration to delete.
|
||||
// in: header
|
||||
Identifier string `json:"x-grafana-alerting-config-identifier"`
|
||||
}
|
||||
|
||||
// swagger:model
|
||||
type AlertmanagerUserConfig struct {
|
||||
AlertmanagerConfig config.Config `yaml:"alertmanager_config" json:"alertmanager_config"`
|
||||
AlertmanagerConfig config.Config `yaml:"alertmanager_config" json:"alertmanager_config"`
|
||||
TemplateFiles map[string]string `yaml:"template_files" json:"template_files"`
|
||||
}
|
||||
|
||||
func (c *AlertmanagerUserConfig) UnmarshalYAML(value *yaml.Node) error {
|
||||
// mimirtool sends alertmanager_config as a string
|
||||
type cortexAlertmanagerUserConfig struct {
|
||||
TemplateFiles map[string]string `yaml:"template_files" json:"template_files"`
|
||||
AlertmanagerConfig string `yaml:"alertmanager_config" json:"alertmanager_config"`
|
||||
}
|
||||
|
||||
var tmp cortexAlertmanagerUserConfig
|
||||
|
||||
if err := value.Decode(&tmp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := yaml.Unmarshal([]byte(tmp.AlertmanagerConfig), &c.AlertmanagerConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
c.TemplateFiles = tmp.TemplateFiles
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// swagger:model
|
||||
type GettableAlertmanagerUserConfig struct {
|
||||
AlertmanagerConfig string `yaml:"alertmanager_config" json:"alertmanager_config"`
|
||||
TemplateFiles map[string]string `yaml:"template_files" json:"template_files"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user