Add priority
This commit is contained in:
parent
1beeb0a7b6
commit
911bf2fa92
3 changed files with 25 additions and 8 deletions
16
README.md
16
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";
|
||||
};
|
||||
```
|
||||
|
|
9
main.go
9
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"))
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue