Skip to content

Commit 828afc4

Browse files
Added more json fields to AlertStatus webhook notification (#4445)
* Added more json fields to webhook notifications for AlertStatus updates: Summary string Details string ServiceID string ServiceName string Meta map[string]string Before these fields were only available in Alert notifications and it was not possible to send them to the user with acknowledge or close events. * Update contribution guidelines for testing command `make test` * Added PublicURL field to json for webhook notification for Alart and AlartStatus Before was that field not available and it was not possible to send them to the user with messages. * AlertBundle Webhook sends now PublicURL as well. * cfg.PublicURL() gets used as cfg.General.PublicURL is deprecated. Co-authored-by: Nathaniel Caza <mastercactapus@gmail.com> * Changed PublicURL to AlertURL AlertURL contains the full link to the alert page, or to the alarm list of the according service if it is an alert bundle. * Replaced function calls for URL generation fmt.Sprintf("%s/alerts/%d", pubURL, m.AlertID) with cfg.CallbackURL(fmt.Sprintf("/alerts/%d", m.AlertID)) * Address review feedback: rename AlertURL to GoAlertURL and clean up - Rename AlertURL to GoAlertURL as suggested, since the URL points to GoAlert itself, not to anything notification-specific - Remove unused pubURL variable (cfg.CallbackURL is used instead) - Remove unused strings import --------- Co-authored-by: Nathaniel Caza <mastercactapus@gmail.com>
1 parent 93100ea commit 828afc4

4 files changed

Lines changed: 53 additions & 17 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Patches are welcome, but we ask that any significant change start as an [issue](
2626

2727
More information is available for [complex features](./docs/complex-features.md).
2828

29-
Be sure to run `make check` and tests before opening a PR to catch common errors.
29+
Be sure to run `make check` and `make test` before opening a PR to catch common errors.
3030

3131
### UI Change Guidelines
3232

engine/sendmessage.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi
104104
if stat == nil {
105105
return nil, fmt.Errorf("could not find original notification for alert %d to %s", msg.AlertID, msg.Dest.String())
106106
}
107+
name, _, err := p.a.ServiceInfo(ctx, a.ServiceID)
108+
if err != nil {
109+
return nil, errors.Wrap(err, "lookup service info")
110+
}
111+
meta, err := p.a.Metadata(ctx, p.b.db, msg.AlertID)
112+
if err != nil {
113+
return nil, errors.Wrap(err, "lookup alert metadata")
114+
}
107115

108116
var status notification.AlertState
109117
switch e.Type() {
@@ -124,6 +132,8 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi
124132
Details: a.Details,
125133
NewAlertState: status,
126134
OriginalStatus: *stat,
135+
ServiceName: name,
136+
Meta: meta,
127137
}
128138
case notification.MessageTypeTest:
129139
notifMsg = notification.Test{

notification/nfymsg/msgalertstatus.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,27 @@ const (
1414
type AlertStatus struct {
1515
Base
1616

17-
AlertID int
18-
LogEntry string
19-
ServiceID string
17+
AlertID int
2018

2119
// Summary of the alert that this status is in regards to.
2220
Summary string
21+
2322
// Details of the alert that this status is in regards to.
2423
Details string
2524

25+
ServiceID string
26+
27+
// ServiceName of the alert that this status is in regards to.
28+
ServiceName string
29+
30+
// Meta contains key/value pairs associated with the alert.
31+
Meta map[string]string
32+
2633
// OriginalStatus is the status of the first Alert notification to this Dest for this AlertID.
2734
OriginalStatus SendResult
2835

2936
// NewAlertState contains the most recent state of the alert.
3037
NewAlertState AlertState
38+
39+
LogEntry string
3140
}

notification/webhook/sender.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type POSTDataAlert struct {
2727
ServiceID string
2828
ServiceName string
2929
Meta map[string]string
30+
GoAlertURL string
3031
}
3132

3233
// POSTDataAlertBundle represents fields in outgoing alert bundle notification.
@@ -36,23 +37,31 @@ type POSTDataAlertBundle struct {
3637
ServiceID string
3738
ServiceName string
3839
Count int
40+
GoAlertURL string
3941
}
4042

4143
// POSTDataAlertStatus represents fields in outgoing alert status notification.
4244
type POSTDataAlertStatus struct {
43-
AppName string
44-
Type string
45-
AlertID int
46-
LogEntry string
45+
AppName string
46+
Type string
47+
AlertID int
48+
Summary string
49+
Details string
50+
ServiceID string
51+
ServiceName string
52+
Meta map[string]string
53+
LogEntry string
54+
GoAlertURL string
4755
}
4856

4957
// POSTDataAlertStatusBundle represents fields in outgoing alert status bundle notification.
5058
type POSTDataAlertStatusBundle struct {
51-
AppName string
52-
Type string
53-
AlertID int
54-
LogEntry string
55-
Count int
59+
AppName string
60+
Type string
61+
AlertID int
62+
LogEntry string
63+
Count int
64+
GoAlertURL string
5665
}
5766

5867
// POSTDataVerification represents fields in outgoing verification notification.
@@ -119,6 +128,7 @@ func (s *Sender) SendMessage(ctx context.Context, msg notification.Message) (*no
119128
ServiceID: m.ServiceID,
120129
ServiceName: m.ServiceName,
121130
Meta: m.Meta,
131+
GoAlertURL: cfg.CallbackURL(fmt.Sprintf("/alerts/%d", m.AlertID)),
122132
}
123133
case notification.AlertBundle:
124134
payload = POSTDataAlertBundle{
@@ -127,13 +137,20 @@ func (s *Sender) SendMessage(ctx context.Context, msg notification.Message) (*no
127137
ServiceID: m.ServiceID,
128138
ServiceName: m.ServiceName,
129139
Count: m.Count,
140+
GoAlertURL: cfg.CallbackURL(fmt.Sprintf("/services/%s/alerts", m.ServiceID)),
130141
}
131142
case notification.AlertStatus:
132143
payload = POSTDataAlertStatus{
133-
AppName: cfg.ApplicationName(),
134-
Type: "AlertStatus",
135-
AlertID: m.AlertID,
136-
LogEntry: m.LogEntry,
144+
AppName: cfg.ApplicationName(),
145+
Type: "AlertStatus",
146+
Details: m.Details,
147+
AlertID: m.AlertID,
148+
Summary: m.Summary,
149+
ServiceID: m.ServiceID,
150+
ServiceName: m.ServiceName,
151+
Meta: m.Meta,
152+
LogEntry: m.LogEntry,
153+
GoAlertURL: cfg.CallbackURL(fmt.Sprintf("/alerts/%d", m.AlertID)),
137154
}
138155
case notification.ScheduleOnCallUsers:
139156
// We use types defined in this package to insulate against unintended API

0 commit comments

Comments
 (0)