feat(pushover): priority on resolved (#879)

* feat(pushover): priority on resolved

Signed-off-by: Devin Buhl <devin@buhl.casa>

* Update README.md

* Update README.md

* Rename ResolvedPriority

* Update README.md

* Update alerting/provider/pushover/pushover.go

* Update README.md

* Update pushover.go

* Update pushover_test.go

* fix: update tests

Signed-off-by: Devin Buhl <devin@buhl.casa>

* fix: update tests

Signed-off-by: Devin Buhl <devin@buhl.casa>

---------

Signed-off-by: Devin Buhl <devin@buhl.casa>
Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
Devin Buhl
2024-11-05 19:57:33 -05:00
committed by GitHub
parent c6ff6ec583
commit 177feba75b
3 changed files with 44 additions and 21 deletions

View File

@ -34,6 +34,10 @@ type AlertProvider struct {
// default: 0
Priority int `yaml:"priority,omitempty"`
// Priority of resolved messages, ranging from -2 (very low) to 2 (Emergency)
// default: 0
ResolvedPriority int `yaml:"resolved-priority,omitempty"`
// Sound of the messages (see: https://pushover.net/api#sounds)
// default: "" (pushover)
Sound string `yaml:"sound,omitempty"`
@ -47,7 +51,10 @@ func (provider *AlertProvider) IsValid() bool {
if provider.Priority == 0 {
provider.Priority = defaultPriority
}
return len(provider.ApplicationToken) == 30 && len(provider.UserKey) == 30 && provider.Priority >= -2 && provider.Priority <= 2
if provider.ResolvedPriority == 0 {
provider.ResolvedPriority = defaultPriority
}
return len(provider.ApplicationToken) == 30 && len(provider.UserKey) == 30 && provider.Priority >= -2 && provider.Priority <= 2 && provider.ResolvedPriority >= -2 && provider.ResolvedPriority <= 2
}
// Send an alert using the provider
@ -93,16 +100,22 @@ func (provider *AlertProvider) buildRequestBody(ep *endpoint.Endpoint, alert *al
User: provider.UserKey,
Title: provider.Title,
Message: message,
Priority: provider.priority(),
Priority: provider.priority(resolved),
Sound: provider.Sound,
})
return body
}
func (provider *AlertProvider) priority() int {
if provider.Priority == 0 {
func (provider *AlertProvider) priority(resolved bool) int {
if resolved && provider.ResolvedPriority == 0 {
return defaultPriority
}
if !resolved && provider.Priority == 0 {
return defaultPriority
}
if resolved {
return provider.ResolvedPriority
}
return provider.Priority
}