feat(channels): include event verb in ntfy title + smtp subject (#10)
Co-authored-by: Steve Cliff <steve@devcloud.guru> Co-committed-by: Steve Cliff <steve@devcloud.guru>
This commit was merged in pull request #10.
This commit is contained in:
@@ -58,14 +58,34 @@ func (c *NtfyChannel) Send(ctx context.Context, p Payload) (int, time.Duration,
|
||||
server := strings.TrimRight(c.cfg.ServerURL, "/")
|
||||
url := server + "/" + c.cfg.Topic
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBufferString(p.Message))
|
||||
// Body carries the event verb so the body alone is unambiguous when
|
||||
// it shows up on a phone lockscreen without the title.
|
||||
body := p.Message
|
||||
switch p.Event {
|
||||
case EventResolved:
|
||||
body = "Resolved · " + p.Message
|
||||
case EventAcknowledged:
|
||||
body = "Acknowledged · " + p.Message
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBufferString(body))
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("ntfy: build request: %w", err)
|
||||
}
|
||||
|
||||
// Title prefix tracks the event so raise vs ack vs resolve are
|
||||
// visually distinct in the ntfy notification list.
|
||||
verb := "raised"
|
||||
switch p.Event {
|
||||
case EventAcknowledged:
|
||||
verb = "ack"
|
||||
case EventResolved:
|
||||
verb = "resolved"
|
||||
case EventTest:
|
||||
verb = "test"
|
||||
}
|
||||
req.Header.Set("Content-Type", "text/plain")
|
||||
req.Header.Set("Title", fmt.Sprintf("[%s] %s %s", p.Severity, p.HostName, p.Kind))
|
||||
req.Header.Set("Tags", p.Severity+","+p.Kind)
|
||||
req.Header.Set("Title", fmt.Sprintf("[%s · %s] %s %s", verb, p.Severity, p.HostName, p.Kind))
|
||||
req.Header.Set("Tags", verb+","+p.Severity+","+p.Kind)
|
||||
req.Header.Set("Priority", priorityForSeverity(p.Severity, c.defaultPriority))
|
||||
if p.Link != "" {
|
||||
req.Header.Set("Click", p.Link)
|
||||
|
||||
Reference in New Issue
Block a user