Skip to content

Commit

Permalink
Revert "Only call cancel_by_tag if priority contains '2'"
Browse files Browse the repository at this point in the history
This reverts commit 68aa21a.
  • Loading branch information
kadaan committed Jan 6, 2025
1 parent 7da0146 commit 41c5f50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
46 changes: 24 additions & 22 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 2 additions & 8 deletions notify/pushover/pushover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down

0 comments on commit 41c5f50

Please sign in to comment.