Skip to content

Commit

Permalink
Merge pull request #3199 from target/feat/webhook-service-name
Browse files Browse the repository at this point in the history
feat: add service name/id field to webhook alerts
  • Loading branch information
allending313 authored Jul 26, 2023
2 parents 2ffae48 + 80ab163 commit 7e540ea
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
16 changes: 11 additions & 5 deletions engine/sendmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi
Count: count,
}
case notification.MessageTypeAlert:
name, _, err := p.a.ServiceInfo(ctx, msg.ServiceID)
if err != nil {
return nil, errors.Wrap(err, "lookup service info")
}
a, err := p.a.FindOne(ctx, msg.AlertID)
if err != nil {
return nil, errors.Wrap(err, "lookup alert")
Expand All @@ -68,11 +72,13 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi
stat = nil
}
notifMsg = notification.Alert{
Dest: msg.Dest,
AlertID: msg.AlertID,
Summary: a.Summary,
Details: a.Details,
CallbackID: msg.ID,
Dest: msg.Dest,
AlertID: msg.AlertID,
Summary: a.Summary,
Details: a.Details,
CallbackID: msg.ID,
ServiceID: a.ServiceID,
ServiceName: name,

OriginalStatus: stat,
}
Expand Down
12 changes: 7 additions & 5 deletions notification/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package notification

// Alert represents outgoing notifications for alerts.
type Alert struct {
Dest Dest
CallbackID string // CallbackID is the identifier used to communicate a response to the notification
AlertID int // The global alert number
Summary string
Details string
Dest Dest
CallbackID string // CallbackID is the identifier used to communicate a response to the notification
AlertID int // The global alert number
Summary string
Details string
ServiceID string
ServiceName string

// OriginalStatus is the status of the first Alert notification to this Dest for this AlertID.
OriginalStatus *SendResult
Expand Down
24 changes: 14 additions & 10 deletions notification/webhook/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ type Sender struct{}

// POSTDataAlert represents fields in outgoing alert notification.
type POSTDataAlert struct {
AppName string
Type string
AlertID int
Summary string
Details string
AppName string
Type string
AlertID int
Summary string
Details string
ServiceID string
ServiceName string
}

// POSTDataAlertBundle represents fields in outgoing alert bundle notification.
Expand Down Expand Up @@ -102,11 +104,13 @@ func (s *Sender) Send(ctx context.Context, msg notification.Message) (*notificat
}
case notification.Alert:
payload = POSTDataAlert{
AppName: cfg.ApplicationName(),
Type: "Alert",
Details: m.Details,
AlertID: m.AlertID,
Summary: m.Summary,
AppName: cfg.ApplicationName(),
Type: "Alert",
Details: m.Details,
AlertID: m.AlertID,
Summary: m.Summary,
ServiceID: m.ServiceID,
ServiceName: m.ServiceName,
}
case notification.AlertBundle:
payload = POSTDataAlertBundle{
Expand Down
12 changes: 8 additions & 4 deletions test/smoke/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
)

type WebhookTestingAlert struct {
AlertID int
Type string
Summary string
Details string
AlertID int
Type string
Summary string
Details string
ServiceID string
ServiceName string
}

func TestWebhookAlert(t *testing.T) {
Expand Down Expand Up @@ -79,4 +81,6 @@ func TestWebhookAlert(t *testing.T) {
assert.Equal(t, alert.Type, "Alert")
assert.Equal(t, alert.Summary, "testing summary")
assert.Equal(t, alert.Details, "testing details")
assert.Equal(t, alert.ServiceID, h.UUID("sid"))
assert.Equal(t, alert.ServiceName, "service")
}

0 comments on commit 7e540ea

Please sign in to comment.