2022-12-14 09:59:37 -06:00
|
|
|
package notifier
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-02-03 10:36:49 -06:00
|
|
|
"github.com/grafana/alerting/receivers"
|
2022-12-19 09:53:58 -06:00
|
|
|
|
2022-12-14 09:59:37 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/notifications"
|
|
|
|
)
|
|
|
|
|
|
|
|
type sender struct {
|
|
|
|
ns notifications.Service
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:36:49 -06:00
|
|
|
func (s sender) SendWebhook(ctx context.Context, cmd *receivers.SendWebhookSettings) error {
|
2023-01-17 13:47:31 -06:00
|
|
|
return s.ns.SendWebhookSync(ctx, ¬ifications.SendWebhookSync{
|
2022-12-19 09:53:58 -06:00
|
|
|
Url: cmd.URL,
|
2022-12-14 09:59:37 -06:00
|
|
|
User: cmd.User,
|
|
|
|
Password: cmd.Password,
|
|
|
|
Body: cmd.Body,
|
2022-12-19 09:53:58 -06:00
|
|
|
HttpMethod: cmd.HTTPMethod,
|
|
|
|
HttpHeader: cmd.HTTPHeader,
|
2022-12-14 09:59:37 -06:00
|
|
|
ContentType: cmd.ContentType,
|
|
|
|
Validation: cmd.Validation,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:36:49 -06:00
|
|
|
func (s sender) SendEmail(ctx context.Context, cmd *receivers.SendEmailSettings) error {
|
2023-01-17 13:47:31 -06:00
|
|
|
var attached []*notifications.SendEmailAttachFile
|
2022-12-14 09:59:37 -06:00
|
|
|
if cmd.AttachedFiles != nil {
|
2023-01-17 13:47:31 -06:00
|
|
|
attached = make([]*notifications.SendEmailAttachFile, 0, len(cmd.AttachedFiles))
|
2022-12-14 09:59:37 -06:00
|
|
|
for _, file := range cmd.AttachedFiles {
|
2023-01-17 13:47:31 -06:00
|
|
|
attached = append(attached, ¬ifications.SendEmailAttachFile{
|
2022-12-14 09:59:37 -06:00
|
|
|
Name: file.Name,
|
|
|
|
Content: file.Content,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-01-17 13:47:31 -06:00
|
|
|
return s.ns.SendEmailCommandHandlerSync(ctx, ¬ifications.SendEmailCommandSync{
|
|
|
|
SendEmailCommand: notifications.SendEmailCommand{
|
2022-12-14 09:59:37 -06:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|