-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Configure Alertmanager to send webhooks to the `webhook` service. * Connect Loki and Prometheus to Alertmanager. * Add the Alertmanager as a datasource to Grafana Limitations: * The webhook only processes the first alert
- Loading branch information
Showing
8 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ config, ... }: | ||
|
||
{ | ||
imports = [ ./consul-catalog.nix ]; | ||
|
||
services.prometheus.alertmanager = { | ||
enable = true; | ||
configuration = { | ||
route.receiver = "webhook"; | ||
receivers = [ | ||
{ | ||
name = "webhook"; | ||
webhook_configs = [ | ||
{ | ||
url = "http://localhost:${toString config.services.webhook.port}/hooks/alertmanager"; | ||
} | ||
]; | ||
} | ||
]; | ||
}; | ||
}; | ||
|
||
services.consul.catalog = [ | ||
{ | ||
name = "alertmanager"; | ||
port = config.services.prometheus.alertmanager.port; | ||
tags = (import ./lib/traefik.nix).tagsForHost "alertmanager"; | ||
check = { | ||
name = "Health endpoint"; | ||
http = "http://localhost:${toString config.services.prometheus.alertmanager.port}/-/healthy"; | ||
interval = "10s"; | ||
}; | ||
} | ||
]; | ||
|
||
networking.firewall.allowedTCPPorts = [ config.services.prometheus.alertmanager.port ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ config, pkgs, ... }: | ||
|
||
let | ||
|
||
command = pkgs.writeShellScriptBin "ntfy" '' | ||
externalUrl=$1 | ||
status=$2 | ||
summary=$3 | ||
description=$4 | ||
if [ "$status" = "firing" ]; then | ||
icon=rotating_light | ||
else | ||
icon=tada | ||
fi | ||
${pkgs.curl}/bin/curl \ | ||
-H "X-Tags: $icon" \ | ||
-H "Title: $summary" \ | ||
-H "Click: $externalUrl" \ | ||
-d "$description" \ | ||
"http://nuc:8080/home-thewagner-ec1" | ||
''; | ||
|
||
in | ||
|
||
{ | ||
imports = [ ./consul-catalog.nix ]; | ||
|
||
services.webhook = { | ||
enable = true; | ||
hooks = { | ||
alertmanager = { | ||
execute-command = "${command}/bin/ntfy"; | ||
incoming-payload-content-type = "application/json"; | ||
pass-arguments-to-command = [ | ||
{ | ||
source = "payload"; | ||
name = "externalURL"; | ||
} | ||
{ | ||
source = "payload"; | ||
name = "alerts.0.status"; | ||
} | ||
{ | ||
source = "payload"; | ||
name = "alerts.0.annotations.summary"; | ||
} | ||
{ | ||
source = "payload"; | ||
name = "alerts.0.annotations.description"; | ||
} | ||
]; | ||
}; | ||
}; | ||
}; | ||
|
||
services.consul.catalog = [ | ||
{ | ||
name = "webhook"; | ||
port = config.services.webhook.port; | ||
tags = (import ./lib/traefik.nix).tagsForHost "webhook"; | ||
} | ||
]; | ||
|
||
networking.firewall.allowedTCPPorts = [ config.services.webhook.port ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters