Alertmanager to ntfy-sh webhook container for Kubernetes deployments
631eeb0816
I had a couple of panics due to invalid URL, which could have been an error message during startup. Example: Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: 2024/04/01 17:33:49 Received valid hook from 127.0.0.1:43130 Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: 2024/04/01 17:33:49 Processing alert: {firing map[alertname:Target Down instance:devkit.local:80 job:esphome severity:high] map[description:The target is not reachable summary:Target is down] 2024-> Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: 2024/04/01 17:33:49 http: panic serving 127.0.0.1:43130: runtime error: invalid memory address or nil pointer dereference Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: goroutine 1013 [running]: Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: net/http.(*conn).serve.func1() Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: /usr/lib/go/src/net/http/server.go:1868 +0xb9 Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: panic({0x840200?, 0xd01360?}) Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: /usr/lib/go/src/runtime/panic.go:920 +0x270 Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: main.WebhookHandler({0xa1d5f0, 0xc00038e000}, 0xc0001b0000) Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: /home/j/src/alertmanager-ntfy/main.go:45 +0xbf2 Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: net/http.HandlerFunc.ServeHTTP(0x10?, {0xa1d5f0?, 0xc00038e000?}, 0xc0004020ac?) Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: /usr/lib/go/src/net/http/server.go:2136 +0x29 Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: net/http.(*ServeMux).ServeHTTP(0x411f45?, {0xa1d5f0, 0xc00038e000}, 0xc0001b0000) Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: /usr/lib/go/src/net/http/server.go:2514 +0x142 Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: net/http.serverHandler.ServeHTTP({0xa1c0c0?}, {0xa1d5f0?, 0xc00038e000?}, 0x6?) Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: /usr/lib/go/src/net/http/server.go:2938 +0x8e Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: net/http.(*conn).serve(0xc0000d21b0, {0xa1e1f0, 0xc00027a600}) Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: /usr/lib/go/src/net/http/server.go:2009 +0x5f4 Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: created by net/http.(*Server).Serve in goroutine 1 Apr 01 17:33:49 nyx.jabid.in alertmanager-ntfy[878013]: /usr/lib/go/src/net/http/server.go:3086 +0x5cb |
||
---|---|---|
.gitignore | ||
default.nix | ||
flake.lock | ||
flake.nix | ||
go.mod | ||
go.sum | ||
LICENCE | ||
main.go | ||
mock.json | ||
module.nix | ||
README.md |
alertmanager-ntfy
Listen for webhooks from Alertmanager and send them to ntfy push notifications
Configuration is done with environment variables.
Variable | Description | Example |
---|---|---|
HTTP_ADDRESS | Adress to listen on | localhost |
HTTP_PORT | Port to listen on | 8080 |
NTFY_TOPIC | ntfy topic to send to | https://ntfy.sh/test |
NTFY_USER | ntfy user for basic auth | myuser |
NTFY_PASS | ntfy password for basic auth | supersecret |
NTFY_PRIORITY | Priority of ntfy messages | high |
Nix
For Nix/Nixos users a flake.nix
is provided to simplify the build. It also
privides app to test the hooks with mocked data from mock.json
Build
nix build
Run directly
nix run
Test alerts
nix run '.#mock-hook'
Module
The flake also includes a NixOS module for ease of use. A minimal configuration will look like this:
# Add to flake inputs
inputs.alertmanager-ntfy.url = "github:pinpox/alertmanager-ntfy";
# Import the module in your configuration.nix
imports = [
self.inputs.alertmanager-ntfy.nixosModules.default
];
# Enable and set options
services.alertmanager-ntfy = {
enable = true;
httpAddress = "localhost";
httpPort = "9999";
ntfyTopic = "https://ntfy.sh/test";
ntfyPriority = "high";
envFile = "/var/src/secrets/alertmanager-ntfy/envfile";
};