Skip to content

Commit 177feba

Browse files
onedr0pTwiN
andauthored
feat(pushover): priority on resolved (#879)
* feat(pushover): priority on resolved Signed-off-by: Devin Buhl <[email protected]> * 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 <[email protected]> * fix: update tests Signed-off-by: Devin Buhl <[email protected]> --------- Signed-off-by: Devin Buhl <[email protected]> Co-authored-by: TwiN <[email protected]>
1 parent c6ff6ec commit 177feba

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,15 +1107,16 @@ endpoints:
11071107

11081108

11091109
#### Configuring Pushover alerts
1110-
| Parameter | Description | Default |
1111-
|:---------------------------------------|:------------------------------------------------------------------------------------------------|:-----------------------------|
1112-
| `alerting.pushover` | Configuration for alerts of type `pushover` | `{}` |
1113-
| `alerting.pushover.application-token` | Pushover application token | `""` |
1114-
| `alerting.pushover.user-key` | User or group key | `""` |
1115-
| `alerting.pushover.title` | Fixed title for all messages sent via Pushover | Name of your App in Pushover |
1116-
| `alerting.pushover.priority` | Priority of all messages, ranging from -2 (very low) to 2 (emergency) | `0` |
1117-
| `alerting.pushover.sound` | Sound of all messages<br />See [sounds](https://pushover.net/api#sounds) for all valid choices. | `""` |
1118-
| `alerting.pushover.default-alert` | Default alert configuration. <br />See [Setting a default alert](#setting-a-default-alert) | N/A |
1110+
| Parameter | Description | Default |
1111+
|:--------------------------------------|:------------------------------------------------------------------------------------------------|:-----------------------------|
1112+
| `alerting.pushover` | Configuration for alerts of type `pushover` | `{}` |
1113+
| `alerting.pushover.application-token` | Pushover application token | `""` |
1114+
| `alerting.pushover.user-key` | User or group key | `""` |
1115+
| `alerting.pushover.title` | Fixed title for all messages sent via Pushover | Name of your App in Pushover |
1116+
| `alerting.pushover.priority` | Priority of all messages, ranging from -2 (very low) to 2 (emergency) | `0` |
1117+
| `alerting.pushover.resolved-priority` | Override the priority of messages on resolved, ranging from -2 (very low) to 2 (emergency) | `0` |
1118+
| `alerting.pushover.sound` | Sound of all messages<br />See [sounds](https://pushover.net/api#sounds) for all valid choices. | `""` |
1119+
| `alerting.pushover.default-alert` | Default alert configuration. <br />See [Setting a default alert](#setting-a-default-alert) | N/A |
11191120

11201121
```yaml
11211122
alerting:
@@ -2274,7 +2275,7 @@ The path to generate a badge is the following:
22742275
/api/v1/endpoints/{key}/uptimes/{duration}/badge.svg
22752276
```
22762277
Where:
2277-
- `{duration}` is `30d` (alpha), `7d`, `24h` or `1h`
2278+
- `{duration}` is `30d` (alpha), `7d`, `24h` or `1h`
22782279
- `{key}` has the pattern `<GROUP_NAME>_<ENDPOINT_NAME>` in which both variables have ` `, `/`, `_`, `,` and `.` replaced by `-`.
22792280

22802281
For instance, if you want the uptime during the last 24 hours from the endpoint `frontend` in the group `core`,

alerting/provider/pushover/pushover.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type AlertProvider struct {
3434
// default: 0
3535
Priority int `yaml:"priority,omitempty"`
3636

37+
// Priority of resolved messages, ranging from -2 (very low) to 2 (Emergency)
38+
// default: 0
39+
ResolvedPriority int `yaml:"resolved-priority,omitempty"`
40+
3741
// Sound of the messages (see: https://pushover.net/api#sounds)
3842
// default: "" (pushover)
3943
Sound string `yaml:"sound,omitempty"`
@@ -47,7 +51,10 @@ func (provider *AlertProvider) IsValid() bool {
4751
if provider.Priority == 0 {
4852
provider.Priority = defaultPriority
4953
}
50-
return len(provider.ApplicationToken) == 30 && len(provider.UserKey) == 30 && provider.Priority >= -2 && provider.Priority <= 2
54+
if provider.ResolvedPriority == 0 {
55+
provider.ResolvedPriority = defaultPriority
56+
}
57+
return len(provider.ApplicationToken) == 30 && len(provider.UserKey) == 30 && provider.Priority >= -2 && provider.Priority <= 2 && provider.ResolvedPriority >= -2 && provider.ResolvedPriority <= 2
5158
}
5259

5360
// Send an alert using the provider
@@ -93,16 +100,22 @@ func (provider *AlertProvider) buildRequestBody(ep *endpoint.Endpoint, alert *al
93100
User: provider.UserKey,
94101
Title: provider.Title,
95102
Message: message,
96-
Priority: provider.priority(),
103+
Priority: provider.priority(resolved),
97104
Sound: provider.Sound,
98105
})
99106
return body
100107
}
101108

102-
func (provider *AlertProvider) priority() int {
103-
if provider.Priority == 0 {
109+
func (provider *AlertProvider) priority(resolved bool) int {
110+
if resolved && provider.ResolvedPriority == 0 {
104111
return defaultPriority
105112
}
113+
if !resolved && provider.Priority == 0 {
114+
return defaultPriority
115+
}
116+
if resolved {
117+
return provider.ResolvedPriority
118+
}
106119
return provider.Priority
107120
}
108121

alerting/provider/pushover/pushover_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func TestPushoverAlertProvider_IsValid(t *testing.T) {
2121
UserKey: "aTokenWithLengthOf30characters",
2222
Title: "Gatus Notification",
2323
Priority: 1,
24+
ResolvedPriority: 1,
2425
}
2526
if !validProvider.IsValid() {
2627
t.Error("provider should've been valid")
@@ -119,11 +120,12 @@ func TestAlertProvider_buildRequestBody(t *testing.T) {
119120
firstDescription := "description-1"
120121
secondDescription := "description-2"
121122
scenarios := []struct {
122-
Name string
123-
Provider AlertProvider
124-
Alert alert.Alert
125-
Resolved bool
126-
ExpectedBody string
123+
Name string
124+
Provider AlertProvider
125+
Alert alert.Alert
126+
Resolved bool
127+
ResolvedPriority bool
128+
ExpectedBody string
127129
}{
128130
{
129131
Name: "triggered",
@@ -134,14 +136,21 @@ func TestAlertProvider_buildRequestBody(t *testing.T) {
134136
},
135137
{
136138
Name: "resolved",
137-
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2},
139+
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, ResolvedPriority: 2},
138140
Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3},
139141
Resolved: true,
140142
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"RESOLVED: endpoint-name - description-2\",\"priority\":2}",
141143
},
144+
{
145+
Name: "resolved-priority",
146+
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, ResolvedPriority: 0},
147+
Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3},
148+
Resolved: true,
149+
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"RESOLVED: endpoint-name - description-2\",\"priority\":0}",
150+
},
142151
{
143152
Name: "with-sound",
144-
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, Sound: "falling"},
153+
Provider: AlertProvider{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, ResolvedPriority: 2, Sound: "falling"},
145154
Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3},
146155
Resolved: true,
147156
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"RESOLVED: endpoint-name - description-2\",\"priority\":2,\"sound\":\"falling\"}",

0 commit comments

Comments
 (0)