mirror of
https://github.com/grafana/grafana.git
synced 2026-08-19 01:34:54 -05:00
Alerting: unwrap AMConfigV1 in PostableAPIConfigToNotificationsConfiguration (#125864)
Pass PostableApiAlertingConfig and []TemplateGroup directly instead of the *AMConfigV1 wrapper, so callers control template selection.
This commit is contained in:
@@ -154,7 +154,7 @@ func (moa *MultiOrgAlertmanager) PrepareConfig(
|
||||
|
||||
prepared.AlertmanagerConfig = preparedConfig
|
||||
|
||||
return PostableAPIConfigToNotificationsConfiguration(prepared, moa.limits)
|
||||
return PostableAPIConfigToNotificationsConfiguration(prepared.AlertmanagerConfig, prepared.SortedTemplates(true), moa.limits)
|
||||
}
|
||||
|
||||
func (moa *MultiOrgAlertmanager) SaveAndApplyDefaultConfig(ctx context.Context, orgId int64) error {
|
||||
|
||||
@@ -57,16 +57,20 @@ func IntegrationToIntegrationConfig(i models.Integration) (alertingModels.Integr
|
||||
}, nil
|
||||
}
|
||||
|
||||
func PostableAPIConfigToNotificationsConfiguration(c *v1.AMConfigV1, limits alertingNotify.DynamicLimits) (alertingNotify.NotificationsConfiguration, error) {
|
||||
receivers, err := ModelToAPIReceivers(c.AlertmanagerConfig.Receivers)
|
||||
func PostableAPIConfigToNotificationsConfiguration(
|
||||
cfg v1.PostableApiAlertingConfig,
|
||||
tmpls []v1.TemplateGroup,
|
||||
limits alertingNotify.DynamicLimits,
|
||||
) (alertingNotify.NotificationsConfiguration, error) {
|
||||
receivers, err := ModelToAPIReceivers(cfg.Receivers)
|
||||
if err != nil {
|
||||
return alertingNotify.NotificationsConfiguration{}, err
|
||||
}
|
||||
return alertingNotify.NotificationsConfiguration{
|
||||
RoutingTree: RouteToAPI(c.AlertmanagerConfig.Route),
|
||||
InhibitRules: c.AlertmanagerConfig.InhibitRules,
|
||||
TimeIntervals: ModelToTimeIntervals(c.AlertmanagerConfig.TimeIntervals, c.AlertmanagerConfig.MuteTimeIntervals),
|
||||
Templates: ModelToTemplateDefinitions(c.SortedTemplates(true)),
|
||||
RoutingTree: RouteToAPI(cfg.Route),
|
||||
InhibitRules: cfg.InhibitRules,
|
||||
TimeIntervals: ModelToTimeIntervals(cfg.TimeIntervals, cfg.MuteTimeIntervals),
|
||||
Templates: ModelToTemplateDefinitions(tmpls),
|
||||
Receivers: receivers,
|
||||
Limits: limits,
|
||||
}, nil
|
||||
|
||||
@@ -247,7 +247,7 @@ func NewAlertmanager(
|
||||
return fmt.Errorf("unable to add autogenerated routes: %w", err)
|
||||
}
|
||||
|
||||
nc, err := notifier.PostableAPIConfigToNotificationsConfiguration(parsed, alertingNotify.DynamicLimits{})
|
||||
nc, err := notifier.PostableAPIConfigToNotificationsConfiguration(parsed.AlertmanagerConfig, parsed.SortedTemplates(true), alertingNotify.DynamicLimits{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to convert default configuration: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user