Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,10 @@ The JSON payload sent to the n8n webhook will include:
[ntfy](https://github.com/binwiederhier/ntfy) is an amazing project that allows you to subscribe to desktop
and mobile notifications, making it an awesome addition to Gatus.

The following placeholders are supported in `click`:
- `[ENDPOINT_URL]` - Resolved from `endpoints[].url`
- `[ENDPOINT_KEY]` - Resolved from internal endpoint key

Example:
```yaml
alerting:
Expand Down
13 changes: 12 additions & 1 deletion alerting/provider/ntfy/ntfy.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ type Body struct {
Click string `json:"click,omitempty"`
}

func resolveEndpointPlaceholders(data string, ep *endpoint.Endpoint) string {
placeholders := map[string]string{
"[ENDPOINT_URL]": ep.URL,
"[ENDPOINT_KEY]": ep.Key(),
}
for placeholder, value := range placeholders {
data = strings.ReplaceAll(data, placeholder, value)
}
return data
}
Comment on lines +174 to +183
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there is a need or interest for more supported placeholders for this and other alert providers. In case there is it would probably make sense to move this out to a file that is shared by all providers and implement it in a more generic way.

This is especially the case if, like in the case of the click url. The part of the input data that is not replaced is static. It does not really make sense to search and replace the same placeholders each time an alert is sent.


// buildRequestBody builds the request body for the provider
func (provider *AlertProvider) buildRequestBody(cfg *Config, ep *endpoint.Endpoint, alert *alert.Alert, result *endpoint.Result, resolved bool) []byte {
var message, formattedConditionResults, tag string
Expand Down Expand Up @@ -201,7 +212,7 @@ func (provider *AlertProvider) buildRequestBody(cfg *Config, ep *endpoint.Endpoi
Tags: []string{tag},
Priority: cfg.Priority,
Email: cfg.Email,
Click: cfg.Click,
Click: resolveEndpointPlaceholders(cfg.Click, ep),
})
return body
}
Expand Down