Skip to content

Commit 33120be

Browse files
aalmenarAdrian Almenar
and
Adrian Almenar
authored
feat(alerting): Add optional ttl parameter to pushover notifications (#1050)
Add optional ttl parameter to pushover notifications Co-authored-by: Adrian Almenar <[email protected]>
1 parent 53b785b commit 33120be

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ endpoints:
12361236
| `alerting.pushover.priority` | Priority of all messages, ranging from -2 (very low) to 2 (emergency) | `0` |
12371237
| `alerting.pushover.resolved-priority` | Override the priority of messages on resolved, ranging from -2 (very low) to 2 (emergency) | `0` |
12381238
| `alerting.pushover.sound` | Sound of all messages<br />See [sounds](https://pushover.net/api#sounds) for all valid choices. | `""` |
1239+
| `alerting.pushover.ttl` | Set the Time-to-live of the message to be automatically deleted from pushover notifications | `0` |
12391240
| `alerting.pushover.default-alert` | Default alert configuration. <br />See [Setting a default alert](#setting-a-default-alert) | N/A |
12401241

12411242
```yaml

Diff for: alerting/provider/pushover/pushover.go

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ type Config struct {
4848
// Sound of the messages (see: https://pushover.net/api#sounds)
4949
// default: "" (pushover)
5050
Sound string `yaml:"sound,omitempty"`
51+
52+
// TTL of your message (https://pushover.net/api#ttl)
53+
// If priority is 2 then this parameter is ignored
54+
// default: 0
55+
TTL int `yaml:"ttl,omitempty"`
5156
}
5257

5358
func (cfg *Config) Validate() error {
@@ -88,6 +93,9 @@ func (cfg *Config) Merge(override *Config) {
8893
if len(override.Sound) > 0 {
8994
cfg.Sound = override.Sound
9095
}
96+
if override.TTL > 0 {
97+
cfg.TTL = override.TTL
98+
}
9199
}
92100

93101
// AlertProvider is the configuration necessary for sending an alert using Pushover
@@ -136,6 +144,7 @@ type Body struct {
136144
Priority int `json:"priority"`
137145
Html int `json:"html"`
138146
Sound string `json:"sound,omitempty"`
147+
TTL int `json:"ttl,omitempty"`
139148
}
140149

141150
// buildRequestBody builds the request body for the provider
@@ -173,6 +182,7 @@ func (provider *AlertProvider) buildRequestBody(cfg *Config, ep *endpoint.Endpoi
173182
Priority: priority,
174183
Html: 1,
175184
Sound: cfg.Sound,
185+
TTL: cfg.TTL,
176186
})
177187
return body
178188
}

Diff for: alerting/provider/pushover/pushover_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ func TestAlertProvider_buildRequestBody(t *testing.T) {
169169
Resolved: true,
170170
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"An alert for \\u003cb\\u003eendpoint-name\\u003c/b\\u003e has been resolved after passing successfully 5 time(s) in a row with the following description: description-2\\n✅ - [CONNECTED] == true\\n✅ - [STATUS] == 200\",\"priority\":2,\"html\":1,\"sound\":\"falling\"}",
171171
},
172+
{
173+
Name: "with-ttl",
174+
Provider: AlertProvider{DefaultConfig: Config{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, ResolvedPriority: 2, TTL: 3600}},
175+
Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3},
176+
Resolved: true,
177+
ExpectedBody: "{\"token\":\"TokenWithLengthOf30Characters2\",\"user\":\"TokenWithLengthOf30Characters5\",\"title\":\"Gatus Notifications\",\"message\":\"An alert for \\u003cb\\u003eendpoint-name\\u003c/b\\u003e has been resolved after passing successfully 5 time(s) in a row with the following description: description-2\\n✅ - [CONNECTED] == true\\n✅ - [STATUS] == 200\",\"priority\":2,\"html\":1,\"ttl\":3600}",
178+
},
172179
}
173180
for _, scenario := range scenarios {
174181
t.Run(scenario.Name, func(t *testing.T) {

0 commit comments

Comments
 (0)