From 41c5f50f30b9835524b8b4b8f2b3a3466c483ed5 Mon Sep 17 00:00:00 2001 From: Joel Baranick Date: Mon, 6 Jan 2025 09:08:29 -0800 Subject: [PATCH] Revert "Only call cancel_by_tag if priority contains '2'" This reverts commit 68aa21a2f588bc0daefdc27e995c496a22e008c8. --- config/notifiers.go | 46 +++++++++++++++++++------------------ notify/pushover/pushover.go | 10 ++------ 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/config/notifiers.go b/config/notifiers.go index 74c74a92a0..3774d331d9 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -151,13 +151,14 @@ var ( NotifierConfig: NotifierConfig{ VSendResolved: true, }, - Title: `{{ template "pushover.default.title" . }}`, - Message: `{{ template "pushover.default.message" . }}`, - URL: `{{ template "pushover.default.url" . }}`, - Priority: `{{ if eq .Status "firing" }}2{{ else }}0{{ end }}`, // emergency (firing) or normal - Retry: duration(1 * time.Minute), - Expire: duration(1 * time.Hour), - HTML: false, + Title: `{{ template "pushover.default.title" . }}`, + Message: `{{ template "pushover.default.message" . }}`, + URL: `{{ template "pushover.default.url" . }}`, + Priority: `{{ if eq .Status "firing" }}2{{ else }}0{{ end }}`, // emergency (firing) or normal + Retry: duration(1 * time.Minute), + Expire: duration(1 * time.Hour), + HTML: false, + CancelOnResolve: false, } // DefaultSNSConfig defines default values for SNS configurations. @@ -727,21 +728,22 @@ type PushoverConfig struct { HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"` - UserKey Secret `yaml:"user_key,omitempty" json:"user_key,omitempty"` - UserKeyFile string `yaml:"user_key_file,omitempty" json:"user_key_file,omitempty"` - Token Secret `yaml:"token,omitempty" json:"token,omitempty"` - TokenFile string `yaml:"token_file,omitempty" json:"token_file,omitempty"` - Title string `yaml:"title,omitempty" json:"title,omitempty"` - Message string `yaml:"message,omitempty" json:"message,omitempty"` - URL string `yaml:"url,omitempty" json:"url,omitempty"` - URLTitle string `yaml:"url_title,omitempty" json:"url_title,omitempty"` - Device string `yaml:"device,omitempty" json:"device,omitempty"` - Sound string `yaml:"sound,omitempty" json:"sound,omitempty"` - Priority string `yaml:"priority,omitempty" json:"priority,omitempty"` - Retry duration `yaml:"retry,omitempty" json:"retry,omitempty"` - Expire duration `yaml:"expire,omitempty" json:"expire,omitempty"` - TTL duration `yaml:"ttl,omitempty" json:"ttl,omitempty"` - HTML bool `yaml:"html" json:"html,omitempty"` + UserKey Secret `yaml:"user_key,omitempty" json:"user_key,omitempty"` + UserKeyFile string `yaml:"user_key_file,omitempty" json:"user_key_file,omitempty"` + Token Secret `yaml:"token,omitempty" json:"token,omitempty"` + TokenFile string `yaml:"token_file,omitempty" json:"token_file,omitempty"` + Title string `yaml:"title,omitempty" json:"title,omitempty"` + Message string `yaml:"message,omitempty" json:"message,omitempty"` + URL string `yaml:"url,omitempty" json:"url,omitempty"` + URLTitle string `yaml:"url_title,omitempty" json:"url_title,omitempty"` + Device string `yaml:"device,omitempty" json:"device,omitempty"` + Sound string `yaml:"sound,omitempty" json:"sound,omitempty"` + Priority string `yaml:"priority,omitempty" json:"priority,omitempty"` + Retry duration `yaml:"retry,omitempty" json:"retry,omitempty"` + Expire duration `yaml:"expire,omitempty" json:"expire,omitempty"` + TTL duration `yaml:"ttl,omitempty" json:"ttl,omitempty"` + HTML bool `yaml:"html" json:"html,omitempty"` + CancelOnResolve bool `yaml:"cancel_on_resolve" json:"cancel_on_resolve,omitempty"` } // UnmarshalYAML implements the yaml.Unmarshaler interface. diff --git a/notify/pushover/pushover.go b/notify/pushover/pushover.go index b261554234..f509248d32 100644 --- a/notify/pushover/pushover.go +++ b/notify/pushover/pushover.go @@ -39,8 +39,6 @@ const ( maxMessageLenRunes = 1024 // https://pushover.net/api#limits - 512 characters or runes. maxURLLenRunes = 512 - // https://pushover.net/api#priority - 2 is emergency priority. - emergencyPriority = "2" ) // Notifier implements a Notifier for Pushover notifications. @@ -156,7 +154,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) parameters.Add("expire", fmt.Sprintf("%d", int64(time.Duration(n.conf.Expire).Seconds()))) parameters.Add("device", tmpl(n.conf.Device)) parameters.Add("sound", tmpl(n.conf.Sound)) - if priority == emergencyPriority { + if n.conf.CancelOnResolve && priority == "2" { parameters.Add("tags", groupKeyTag) } newttl := int64(time.Duration(n.conf.TTL).Seconds()) @@ -173,11 +171,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) return false, err } shouldRetry, err := n.sendMessage(ctx, key, u, parameters) - - // Notifications sent for firing alerts could be sent with emergency priority, but the resolution notifications - // might be sent with a different priority. Because of this, and the desire to reduce unnecessary cancel_by_tag - // call again Pushover, we only call cancel_by_tag if the priority config value contains. - if err == nil && strings.Contains(n.conf.Priority, emergencyPriority) && alerts.Status() == model.AlertResolved { + if err == nil && n.conf.CancelOnResolve && alerts.Status() == model.AlertResolved { u, err = url.Parse(fmt.Sprintf("%s/%s.json", n.apiReceiptsURL, groupKeyTag)) if err != nil { return false, err