Skip to content

Commit

Permalink
change the format of notification history
Browse files Browse the repository at this point in the history
Signed-off-by: wanjunlei <[email protected]>
  • Loading branch information
wanjunlei committed Nov 29, 2023
1 parent e35efd8 commit 25c1070
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg/internal/webhook/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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, "/"))
}
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/notify/notifier/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 25c1070

Please sign in to comment.