From a864b6f27531a2d68ff17e6992a666397afbbded Mon Sep 17 00:00:00 2001 From: henrygd Date: Tue, 25 Feb 2025 17:47:16 -0500 Subject: [PATCH] move supportstitle to global var --- beszel/internal/alerts/alerts.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/beszel/internal/alerts/alerts.go b/beszel/internal/alerts/alerts.go index f5975bdf..09cfd474 100644 --- a/beszel/internal/alerts/alerts.go +++ b/beszel/internal/alerts/alerts.go @@ -60,6 +60,24 @@ type SystemAlertData struct { descriptor string // override descriptor in notification body (for temp sensor, disk partition, etc) } +// notification services that support title param +var supportsTitle = map[string]struct{}{ + "bark": {}, + "discord": {}, + "gotify": {}, + "ifttt": {}, + "join": {}, + "matrix": {}, + "ntfy": {}, + "opsgenie": {}, + "pushbullet": {}, + "pushover": {}, + "slack": {}, + "teams": {}, + "telegram": {}, + "zulip": {}, +} + func NewAlertManager(app core.App) *AlertManager { return &AlertManager{ app: app, @@ -446,9 +464,6 @@ func (am *AlertManager) sendAlert(data AlertMessageData) { // SendShoutrrrAlert sends an alert via a Shoutrrr URL func (am *AlertManager) SendShoutrrrAlert(notificationUrl, title, message, link, linkText string) error { - // services that support title param - supportsTitle := []string{"bark", "discord", "gotify", "ifttt", "join", "matrix", "ntfy", "opsgenie", "pushbullet", "pushover", "slack", "teams", "telegram", "zulip"} - // Parse the URL parsedURL, err := url.Parse(notificationUrl) if err != nil { @@ -458,7 +473,7 @@ func (am *AlertManager) SendShoutrrrAlert(notificationUrl, title, message, link, queryParams := parsedURL.Query() // Add title - if sliceContains(supportsTitle, scheme) { + if _, ok := supportsTitle[scheme]; ok { queryParams.Add("title", title) } else if scheme == "mattermost" { // use markdown title for mattermost