CloudMigrations: create snapshot for Notification Templates (#94676)

* CloudMigrations: create snapshot for Notification Templates

* CloudMigrations: add notification templates resource to frontend
This commit is contained in:
Matheus Macabu
2024-10-15 12:55:33 +02:00
committed by GitHub
parent f97f489c2c
commit 016dea1143
9 changed files with 100 additions and 6 deletions
@@ -39,3 +39,30 @@ func (s *Service) getAlertMuteTimings(ctx context.Context, signedInUser *user.Si
return muteTimeIntervals, nil
}
type notificationTemplate struct {
Name string `json:"name"`
Template string `json:"template"`
}
func (s *Service) getNotificationTemplates(ctx context.Context, signedInUser *user.SignedInUser) ([]notificationTemplate, error) {
if !s.features.IsEnabledGlobally(featuremgmt.FlagOnPremToCloudMigrationsAlerts) {
return nil, nil
}
templates, err := s.ngAlert.Api.Templates.GetTemplates(ctx, signedInUser.OrgID)
if err != nil {
return nil, fmt.Errorf("fetching ngalert notification templates: %w", err)
}
notificationTemplates := make([]notificationTemplate, 0, len(templates))
for _, template := range templates {
notificationTemplates = append(notificationTemplates, notificationTemplate{
Name: template.Name,
Template: template.Template,
})
}
return notificationTemplates, nil
}