diff --git a/docs/configuration.md b/docs/configuration.md index e846d181ab..57d5521876 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2008,6 +2008,12 @@ There is a list of [integrations](https://prometheus.io/docs/operating/integrations/#alertmanager-webhook-receiver) with this feature. +For an example of using `payload` to send notifications to a service that +doesn't have a dedicated receiver, such as [Gotify](https://gotify.net), see +[`examples/webhook/gotify.yml`](https://github.com/prometheus/alertmanager/blob/main/examples/webhook/gotify.yml). +More webhook payload examples, including one for Microsoft Teams, can be +found in [`examples/webhook`](https://github.com/prometheus/alertmanager/tree/main/examples/webhook). + ### `` incident.io notifications are sent via the [incident.io Alert Sources API](https://api-docs.incident.io/tag/Alert-Sources-V2#operation/Alert%20Sources%20V2_Create). diff --git a/docs/notification_examples.md b/docs/notification_examples.md index 094239c981..5801c6a440 100644 --- a/docs/notification_examples.md +++ b/docs/notification_examples.md @@ -156,3 +156,25 @@ templates: ``` See the [`` reference](configuration.md#email_config) for SMTP authentication and TLS options. + +## Sending notifications to Gotify with a custom webhook payload + +[Gotify](https://gotify.net) doesn't have a dedicated Alertmanager receiver, but its push message API is a simple JSON POST, so it can be driven directly with the generic [`webhook_config`](configuration.md#webhook_config) and its `payload` field. Authentication is done via the `X-Gotify-Key` header, which should be set to a Gotify application token using `secrets` so it's redacted from the displayed configuration: + +```yaml +receivers: +- name: gotify + webhook_configs: + - url: 'https://gotify.example.com/message' + http_config: + authorization: + credentials_file: /etc/alertmanager/secrets/gotify-secret/token + payload: + title: '{{ .Status | toUpper }} {{ .CommonLabels.alertname }}' + priority: '{{ if eq .Status "firing" }}5{{ else }}0{{ end }}' + message: | + {{ range .Alerts }}{{ .Annotations.summary }} + {{ end }} +``` + +A more complete version of this example, with Markdown formatting and separate sections for firing and resolved alerts, is available in [`examples/webhook/gotify.yml`](https://github.com/prometheus/alertmanager/blob/main/examples/webhook/gotify.yml). diff --git a/examples/webhook/gotify.yml b/examples/webhook/gotify.yml new file mode 100644 index 0000000000..11975633a9 --- /dev/null +++ b/examples/webhook/gotify.yml @@ -0,0 +1,58 @@ +# Copyright The Prometheus Authors +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is an example of how to send notifications to a Gotify +# (https://gotify.net) server using the generic webhook receiver with a +# custom payload, instead of a dedicated Gotify integration. +# +# Gotify's push message API expects a JSON body with "title", "message" and +# "priority" fields, plus an optional "extras" object. See +# https://gotify.net/docs/pushmsg for the full list of supported fields. +# +# Authentication is done via bearer token as described in +# https://gotify.net/api-docs +receivers: + - name: gotify + webhook_configs: + - url: 'https://gotify.example.com/message' + send_resolved: true + http_config: + authorization: + credentials_file: /etc/alertmanager/secrets/gotify-secret/token + payload: + title: '{{ .Status | toUpper }} {{ .CommonLabels.alertname }}{{ with .CommonLabels.instance }} {{ . }}{{ end }}' + priority: '{{ if eq .Status "firing" }}5{{ else }}0{{ end }}' + extras: + "client::display": + contentType: "text/markdown" + message: | + {{ if gt (len .Alerts.Firing) 0 }} + {{ range .Alerts.Firing }} + **{{ .Annotations.summary }}** + + **Instance:** `{{ .Labels.instance }}` + **Since:** {{ .StartsAt }} + **Source:** [Prometheus]({{ .GeneratorURL }}) + {{ end }} + {{ end }} + {{ if gt (len .Alerts.Resolved) 0 }} + {{ range .Alerts.Resolved }} + **{{ .Annotations.summary }}** + + **Instance:** `{{ .Labels.instance }}` + **Resolved:** {{ .EndsAt }} + **Source:** [Prometheus]({{ .GeneratorURL }}) + {{ end }} + {{ end }} + + [View in Alertmanager]({{ .ExternalURL }})