diff --git a/pkg/internal/webhook/types.go b/pkg/internal/webhook/types.go index 30193c92..d61e1e49 100644 --- a/pkg/internal/webhook/types.go +++ b/pkg/internal/webhook/types.go @@ -3,6 +3,7 @@ package webhook import ( "fmt" "strconv" + "strings" "github.com/kubesphere/notification-manager/pkg/apis/v2beta2" "github.com/kubesphere/notification-manager/pkg/constants" @@ -58,7 +59,7 @@ func NewReceiver(tenantID string, obj *v2beta2.Receiver) internal.Receiver { } if service.Path != nil { - r.URL = fmt.Sprintf("%s%s", r.URL, *service.Path) + r.URL = fmt.Sprintf("%s%s", r.URL, strings.TrimPrefix(*service.Path, "/")) } } diff --git a/pkg/notify/notifier/webhook/webhook.go b/pkg/notify/notifier/webhook/webhook.go index 67d146ef..85be03ba 100644 --- a/pkg/notify/notifier/webhook/webhook.go +++ b/pkg/notify/notifier/webhook/webhook.go @@ -174,7 +174,6 @@ func (n *Notifier) Notify(ctx context.Context, data *template.Data) error { } func generateNotificationHistory(buf *bytes.Buffer, data *template.Data) error { - var res []interface{} for _, alert := range data.Alerts { m := make(map[string]interface{}) m[Status] = alert.Status @@ -201,10 +200,12 @@ func generateNotificationHistory(buf *bytes.Buffer, data *template.Data) error { } m[Message] = message - res = append(res, m) + if err := utils.JsonEncode(buf, m); err != nil { + return err + } } - return utils.JsonEncode(buf, res) + return nil } func (n *Notifier) getTransport(r *webhook.Receiver) (http.RoundTripper, error) {