From 33120bee5292eaa3eb52bfa28fd3932fcf7f1050 Mon Sep 17 00:00:00 2001 From: Adrian <161029+aalmenar@users.noreply.github.com> Date: Sat, 5 Apr 2025 02:58:16 +0200 Subject: [PATCH] feat(alerting): Add optional ttl parameter to pushover notifications (#1050) Add optional ttl parameter to pushover notifications Co-authored-by: Adrian Almenar --- README.md | 1 + alerting/provider/pushover/pushover.go | 10 ++++++++++ alerting/provider/pushover/pushover_test.go | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 7f68545d..b6d79b15 100644 --- a/README.md +++ b/README.md @@ -1236,6 +1236,7 @@ endpoints: | `alerting.pushover.priority` | Priority of all messages, ranging from -2 (very low) to 2 (emergency) | `0` | | `alerting.pushover.resolved-priority` | Override the priority of messages on resolved, ranging from -2 (very low) to 2 (emergency) | `0` | | `alerting.pushover.sound` | Sound of all messages
See [sounds](https://pushover.net/api#sounds) for all valid choices. | `""` | +| `alerting.pushover.ttl` | Set the Time-to-live of the message to be automatically deleted from pushover notifications | `0` | | `alerting.pushover.default-alert` | Default alert configuration.
See [Setting a default alert](#setting-a-default-alert) | N/A | ```yaml diff --git a/alerting/provider/pushover/pushover.go b/alerting/provider/pushover/pushover.go index aba7a4e8..a3935d77 100644 --- a/alerting/provider/pushover/pushover.go +++ b/alerting/provider/pushover/pushover.go @@ -48,6 +48,11 @@ type Config struct { // Sound of the messages (see: https://pushover.net/api#sounds) // default: "" (pushover) Sound string `yaml:"sound,omitempty"` + + // TTL of your message (https://pushover.net/api#ttl) + // If priority is 2 then this parameter is ignored + // default: 0 + TTL int `yaml:"ttl,omitempty"` } func (cfg *Config) Validate() error { @@ -88,6 +93,9 @@ func (cfg *Config) Merge(override *Config) { if len(override.Sound) > 0 { cfg.Sound = override.Sound } + if override.TTL > 0 { + cfg.TTL = override.TTL + } } // AlertProvider is the configuration necessary for sending an alert using Pushover @@ -136,6 +144,7 @@ type Body struct { Priority int `json:"priority"` Html int `json:"html"` Sound string `json:"sound,omitempty"` + TTL int `json:"ttl,omitempty"` } // buildRequestBody builds the request body for the provider @@ -173,6 +182,7 @@ func (provider *AlertProvider) buildRequestBody(cfg *Config, ep *endpoint.Endpoi Priority: priority, Html: 1, Sound: cfg.Sound, + TTL: cfg.TTL, }) return body } diff --git a/alerting/provider/pushover/pushover_test.go b/alerting/provider/pushover/pushover_test.go index aa0436c0..7131d91b 100644 --- a/alerting/provider/pushover/pushover_test.go +++ b/alerting/provider/pushover/pushover_test.go @@ -169,6 +169,13 @@ func TestAlertProvider_buildRequestBody(t *testing.T) { Resolved: true, 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\"}", }, + { + Name: "with-ttl", + Provider: AlertProvider{DefaultConfig: Config{ApplicationToken: "TokenWithLengthOf30Characters2", UserKey: "TokenWithLengthOf30Characters5", Title: "Gatus Notifications", Priority: 2, ResolvedPriority: 2, TTL: 3600}}, + Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3}, + Resolved: true, + 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}", + }, } for _, scenario := range scenarios { t.Run(scenario.Name, func(t *testing.T) {