notify: Adds support for gotify open-source notification service.#5380
notify: Adds support for gotify open-source notification service.#5380TheSp1der wants to merge 8 commits into
Conversation
Signed-off-by: nhyatt <nhyatt@smoothnet.org>
Signed-off-by: nhyatt <nhyatt@smoothnet.org>
Signed-off-by: nhyatt <nhyatt@smoothnet.org>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds Gotify as an Alertmanager notification receiver, including configuration validation, receiver integration wiring, HTTP delivery, default templates, and tests for payloads, content metadata, and file-based secrets. ChangesGotify Receiver Support
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Alertmanager
participant BuildReceiverIntegrations
participant GotifyNotifier
participant GotifyServer
Alertmanager->>BuildReceiverIntegrations: load GotifyConfigs
BuildReceiverIntegrations->>GotifyNotifier: create notifier
Alertmanager->>GotifyNotifier: Notify(alerts)
GotifyNotifier->>GotifyServer: POST rendered JSON with X-Gotify-Key
GotifyServer-->>GotifyNotifier: HTTP response
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@notify/gotify/gotify.go`:
- Line 143: The Gotify auth header is incorrectly passing the token through the
template engine, which can mutate an opaque credential and bypass template
errors already checked earlier. Update the Gotify notifier logic in the function
that builds the request header to use the raw token directly in the X-Gotify-Key
header, matching the other notifier implementations that send credentials
without templating.
- Around line 106-108: Check tmplErr before parsing priority in gotify.Notify so
template failures are not masked by strconv.Atoi. In the priority handling
block, make sure the result of tmplText(n.conf.Priority) is accompanied by an
immediate tmplErr check before calling strconv.Atoi, and return that template
error directly if present. Keep the existing priority parsing path in Notify and
the later tmplErr handling consistent, but ensure the early priority parse
cannot turn a template failure into an "invalid syntax" error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: b8b87b8f-4049-4f3c-843b-2bd1be89a778
📒 Files selected for processing (7)
config/config.goconfig/receiver/receiver.gonotify/gotify/config.gonotify/gotify/config_test.gonotify/gotify/gotify.gonotify/gotify/gotify_test.gotemplate/default.tmpl
Prevent token from being processed by template engine. Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Nicolaas Hyatt <39059405+TheSp1der@users.noreply.github.com>
Updates return message to more accurately represent error instead of possible confusing "invalid syntax". Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Nicolaas Hyatt <39059405+TheSp1der@users.noreply.github.com>
Signed-off-by: nhyatt <nhyatt@smoothnet.org>
|
This looks like a simple stateles JSON post to me. So two questions:
|
|
That's a good question:
|
So the auth should be not an issue. The native webhhok supports many authentications ans cusomtizations. Especially setting a header is easy https://prometheus.io/docs/alerting/latest/configuration/#http_header
You can use a custom roundtripper to acheive that, see eg here https://github.com/prometheus/alertmanager/blob/main/notify/rocketchat/rocketchat.go#L77-L115 |
|
|
…nts a custom RoundTripper to inject the X-Gotify-Key header. Replaces manual HTTP request construction with notify.PostJSON helper. Signed-off-by: nhyatt <nhyatt@smoothnet.org>
|
So I quickly modelled this with the webhook: The whole point of adding templating to the webhook notifier was to avoid the ever growing list of notifier integrations. It even gives users the more customization options for the actual layout of the content. (e.g. I am using webhooks instead of msteamsv2 because I can make much nicer messages that way) There are and have been many discussions about how to deal with notification integrations and to my knowledge there is no final decision. I will still review the code (and even approve it) but that doesn't mean it will get in (not my call). At the moment the PR is lacking documentation updates, also whe have a PR template which points that out https://github.com/prometheus/alertmanager/blob/main/.github/pull_request_template.md as well as the webhook topic. |
|
@TheMeier I have added the snippet you required to the PR. I'll update the documentation and benchmark data as soon as I have a moment. |
|
@TheSp1der IMHO benchmarking is not required here |
Signed-off-by: nhyatt <nhyatt@smoothnet.org>
|
@TheMeier, |
Summary
This PR adds a new Gotify receiver integration.
/messageAPI withX-Gotify-Keyauthentication.gotify_configsto the Alertmanager configuration and wires it into receiver integration building.gotify.default.titleandgotify.default.message.extras.client::display.contentTypefor markdown delivery.Pull Request Checklist
Which user-facing changes does this PR introduce?