mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-21 23:43:27 +01:00
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:
parent
c6ff6ec583
commit
177feba75b
19
README.md
19
README.md
@ -1107,15 +1107,16 @@ endpoints:
|
|||||||
|
|
||||||
|
|
||||||
#### Configuring Pushover alerts
|
#### Configuring Pushover alerts
|
||||||
| Parameter | Description | Default |
|
| Parameter | Description | Default |
|
||||||
|:---------------------------------------|:------------------------------------------------------------------------------------------------|:-----------------------------|
|
|:--------------------------------------|:------------------------------------------------------------------------------------------------|:-----------------------------|
|
||||||
| `alerting.pushover` | Configuration for alerts of type `pushover` | `{}` |
|
| `alerting.pushover` | Configuration for alerts of type `pushover` | `{}` |
|
||||||
| `alerting.pushover.application-token` | Pushover application token | `""` |
|
| `alerting.pushover.application-token` | Pushover application token | `""` |
|
||||||
| `alerting.pushover.user-key` | User or group key | `""` |
|
| `alerting.pushover.user-key` | User or group key | `""` |
|
||||||
| `alerting.pushover.title` | Fixed title for all messages sent via Pushover | Name of your App in Pushover |
|
| `alerting.pushover.title` | Fixed title for all messages sent via Pushover | Name of your App in Pushover |
|
||||||
| `alerting.pushover.priority` | Priority of all messages, ranging from -2 (very low) to 2 (emergency) | `0` |
|
| `alerting.pushover.priority` | Priority of all messages, ranging from -2 (very low) to 2 (emergency) | `0` |
|
||||||
| `alerting.pushover.sound` | Sound of all messages<br />See [sounds](https://pushover.net/api#sounds) for all valid choices. | `""` |
|
| `alerting.pushover.resolved-priority` | Override the priority of messages on resolved, ranging from -2 (very low) to 2 (emergency) | `0` |
|
||||||
| `alerting.pushover.default-alert` | Default alert configuration. <br />See [Setting a default alert](#setting-a-default-alert) | N/A |
|
| `alerting.pushover.sound` | Sound of all messages<br />See [sounds](https://pushover.net/api#sounds) for all valid choices. | `""` |
|
||||||
|
| `alerting.pushover.default-alert` | Default alert configuration. <br />See [Setting a default alert](#setting-a-default-alert) | N/A |
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
alerting:
|
alerting:
|
||||||
|
@ -34,6 +34,10 @@ type AlertProvider struct {
|
|||||||
// default: 0
|
// default: 0
|
||||||
Priority int `yaml:"priority,omitempty"`
|
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)
|
// Sound of the messages (see: https://pushover.net/api#sounds)
|
||||||
// default: "" (pushover)
|
// default: "" (pushover)
|
||||||
Sound string `yaml:"sound,omitempty"`
|
Sound string `yaml:"sound,omitempty"`
|
||||||
@ -47,7 +51,10 @@ func (provider *AlertProvider) IsValid() bool {
|
|||||||
if provider.Priority == 0 {
|
if provider.Priority == 0 {
|
||||||
provider.Priority = defaultPriority
|
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
|
// Send an alert using the provider
|
||||||
@ -93,16 +100,22 @@ func (provider *AlertProvider) buildRequestBody(ep *endpoint.Endpoint, alert *al
|
|||||||
User: provider.UserKey,
|
User: provider.UserKey,
|
||||||
Title: provider.Title,
|
Title: provider.Title,
|
||||||
Message: message,
|
Message: message,
|
||||||
Priority: provider.priority(),
|
Priority: provider.priority(resolved),
|
||||||
Sound: provider.Sound,
|
Sound: provider.Sound,
|
||||||
})
|
})
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *AlertProvider) priority() int {
|
func (provider *AlertProvider) priority(resolved bool) int {
|
||||||
if provider.Priority == 0 {
|
if resolved && provider.ResolvedPriority == 0 {
|
||||||
return defaultPriority
|
return defaultPriority
|
||||||
}
|
}
|
||||||
|
if !resolved && provider.Priority == 0 {
|
||||||
|
return defaultPriority
|
||||||
|
}
|
||||||
|
if resolved {
|
||||||
|
return provider.ResolvedPriority
|
||||||
|
}
|
||||||
return provider.Priority
|
return provider.Priority
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ func TestPushoverAlertProvider_IsValid(t *testing.T) {
|
|||||||
UserKey: "aTokenWithLengthOf30characters",
|
UserKey: "aTokenWithLengthOf30characters",
|
||||||
Title: "Gatus Notification",
|
Title: "Gatus Notification",
|
||||||
Priority: 1,
|
Priority: 1,
|
||||||
|
ResolvedPriority: 1,
|
||||||
}
|
}
|
||||||
if !validProvider.IsValid() {
|
if !validProvider.IsValid() {
|
||||||
t.Error("provider should've been valid")
|
t.Error("provider should've been valid")
|
||||||
@ -119,11 +120,12 @@ func TestAlertProvider_buildRequestBody(t *testing.T) {
|
|||||||
firstDescription := "description-1"
|
firstDescription := "description-1"
|
||||||
secondDescription := "description-2"
|
secondDescription := "description-2"
|
||||||
scenarios := []struct {
|
scenarios := []struct {
|
||||||
Name string
|
Name string
|
||||||
Provider AlertProvider
|
Provider AlertProvider
|
||||||
Alert alert.Alert
|
Alert alert.Alert
|
||||||
Resolved bool
|
Resolved bool
|
||||||
ExpectedBody string
|
ResolvedPriority bool
|
||||||
|
ExpectedBody string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Name: "triggered",
|
Name: "triggered",
|
||||||
@ -134,14 +136,21 @@ func TestAlertProvider_buildRequestBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "resolved",
|
Name: "resolved",
|
||||||
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2},
|
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, ResolvedPriority: 2},
|
||||||
Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3},
|
Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3},
|
||||||
Resolved: true,
|
Resolved: true,
|
||||||
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"RESOLVED: endpoint-name - description-2\",\"priority\":2}",
|
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"RESOLVED: endpoint-name - description-2\",\"priority\":2}",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "resolved-priority",
|
||||||
|
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, ResolvedPriority: 0},
|
||||||
|
Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3},
|
||||||
|
Resolved: true,
|
||||||
|
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"RESOLVED: endpoint-name - description-2\",\"priority\":0}",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "with-sound",
|
Name: "with-sound",
|
||||||
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, Sound: "falling"},
|
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, ResolvedPriority: 2, Sound: "falling"},
|
||||||
Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3},
|
Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3},
|
||||||
Resolved: true,
|
Resolved: true,
|
||||||
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"RESOLVED: endpoint-name - description-2\",\"priority\":2,\"sound\":\"falling\"}",
|
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"RESOLVED: endpoint-name - description-2\",\"priority\":2,\"sound\":\"falling\"}",
|
||||||
|
Loading…
Reference in New Issue
Block a user