diff --git a/README.md b/README.md index 1e35ea3..b9fcbda 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,14 @@ send them to [ntfy](https://ntfy.sh/) 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` | +| 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 @@ -60,6 +61,7 @@ services.alertmanager-ntfy = { httpAddress = "localhost"; httpPort = "9999"; ntfyTopic = "https://ntfy.sh/test"; + ntfyPriority = "high"; envFile = "/var/src/secrets/alertmanager-ntfy/envfile"; }; ``` diff --git a/main.go b/main.go index 46017f6..c16ca88 100644 --- a/main.go +++ b/main.go @@ -39,8 +39,15 @@ func WebhookHandler(w http.ResponseWriter, r *http.Request) { return } + // Title req.Header.Set("Title", fmt.Sprintf("[%s] %s", alert.Labels["instance"], alert.Labels["alertname"])) - // req.Header.Set("Priority", "urgent") //TODO broken on ios + + // Priority (if set) + if priority := os.Getenv("NTFY_PRIORITY"); len(strings.TrimSpace(os.Getenv(priority))) != 0 { + req.Header.Set("Priority", priority) + } + + // Tags req.Header.Set("Tags", strings.Join(maps.Values(alert.Labels), ",")) req.SetBasicAuth(os.Getenv("NTFY_USER"), os.Getenv("NTFY_PASS")) diff --git a/module.nix b/module.nix index 45a95a9..634daf4 100644 --- a/module.nix +++ b/module.nix @@ -29,6 +29,13 @@ in { example = "https://ntfy.sh/test"; }; + ntfyPriority = mkOption { + type = types.str; + default = ""; + description = "ntfy.sh message priority"; + example = "urgent"; + }; + envFile = mkOption { type = types.str; default = null; @@ -64,6 +71,7 @@ in { "HTTP_ADDRESS='${cfg.httpAddress}'" "HTTP_PORT='${cfg.httpPort}'" "NTFY_TOPIC='${cfg.ntfyTopic}'" + "NTFY_PRIORITY='${cfg.ntfyPriority}'" ]; User = "alertmanager-ntfy";