grafana/pkg/services/ngalert/notifier/sender.go
Yuri Tseretyan a8b4a4bb45
Alerting: Update alerting module to 20230418161049-5f374e58cb32 + refactoring (#66622)
* update to alerting 20230418161049-5f374e58cb32
* rename renamed structs in https://github.com/grafana/alerting/pull/73
* update ValidateContactPoint to use BuildReceiverConfiguration
* update logger factory according to changes
* rewrite integration builder
Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>
2023-04-25 13:39:46 -04:00

53 lines
1.4 KiB
Go

package notifier
import (
"context"
"github.com/grafana/alerting/receivers"
"github.com/grafana/grafana/pkg/services/notifications"
)
type sender struct {
ns notifications.Service
}
func (s sender) SendWebhook(ctx context.Context, cmd *receivers.SendWebhookSettings) error {
return s.ns.SendWebhookSync(ctx, &notifications.SendWebhookSync{
Url: cmd.URL,
User: cmd.User,
Password: cmd.Password,
Body: cmd.Body,
HttpMethod: cmd.HTTPMethod,
HttpHeader: cmd.HTTPHeader,
ContentType: cmd.ContentType,
Validation: cmd.Validation,
})
}
func (s sender) SendEmail(ctx context.Context, cmd *receivers.SendEmailSettings) error {
var attached []*notifications.SendEmailAttachFile
if cmd.AttachedFiles != nil {
attached = make([]*notifications.SendEmailAttachFile, 0, len(cmd.AttachedFiles))
for _, file := range cmd.AttachedFiles {
attached = append(attached, &notifications.SendEmailAttachFile{
Name: file.Name,
Content: file.Content,
})
}
}
return s.ns.SendEmailCommandHandlerSync(ctx, &notifications.SendEmailCommandSync{
SendEmailCommand: notifications.SendEmailCommand{
To: cmd.To,
SingleEmail: cmd.SingleEmail,
Template: cmd.Template,
Subject: cmd.Subject,
Data: cmd.Data,
Info: cmd.Info,
ReplyTo: cmd.ReplyTo,
EmbeddedFiles: cmd.EmbeddedFiles,
AttachedFiles: attached,
},
})
}