Files
grafana/pkg/services/ngalert/notifier/testreceivers.go
53c39ccda3 Alerting: Update alerting module to 3befd25883e0d17673e5590cc5c5702bbc031b16 (#114062)
* [create-pull-request] automated change

* fix module path for alerting notify test receivers

---------

Co-authored-by: moustafab <27738648+moustafab@users.noreply.github.com>
Co-authored-by: Moustafa Baiou <moustafa.baiou@grafana.com>
2025-11-19 21:24:08 +00:00

58 lines
1.9 KiB
Go

package notifier
import (
"context"
"encoding/json"
"github.com/grafana/alerting/models"
alertingNotify "github.com/grafana/alerting/notify"
v2 "github.com/prometheus/alertmanager/api/v2"
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
)
func (am *alertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*alertingNotify.TestReceiversResult, int, error) {
receivers := make([]*alertingNotify.APIReceiver, 0, len(c.Receivers))
for _, r := range c.Receivers {
integrations := make([]*models.IntegrationConfig, 0, len(r.GrafanaManagedReceivers))
for _, gr := range r.GrafanaManagedReceivers {
integrations = append(integrations, &models.IntegrationConfig{
UID: gr.UID,
Name: gr.Name,
Type: gr.Type,
DisableResolveMessage: gr.DisableResolveMessage,
Settings: json.RawMessage(gr.Settings),
SecureSettings: gr.SecureSettings,
})
}
recv := &alertingNotify.APIReceiver{
ConfigReceiver: r.Receiver,
ReceiverConfig: models.ReceiverConfig{
Integrations: integrations,
},
}
err := patchNewSecureFields(ctx, recv, alertingNotify.DecodeSecretsFromBase64, am.decryptFn)
if err != nil {
return nil, 0, err
}
receivers = append(receivers, recv)
}
a := &alertingNotify.PostableAlert{}
if c.Alert != nil {
a.Annotations = v2.ModelLabelSetToAPILabelSet(c.Alert.Annotations)
a.Labels = v2.ModelLabelSetToAPILabelSet(c.Alert.Labels)
}
AddDefaultLabelsAndAnnotations(a)
return am.Base.TestReceivers(ctx, alertingNotify.TestReceiversConfigBodyParams{
Alert: &models.TestReceiversConfigAlertParams{
Annotations: v2.APILabelSetToModelLabelSet(a.Annotations),
Labels: v2.APILabelSetToModelLabelSet(a.Labels),
},
Receivers: receivers,
})
}
func (am *alertmanager) GetReceivers(_ context.Context) ([]apimodels.Receiver, error) {
return am.Base.GetReceiversStatus(), nil
}