1 import ../make-test-python.nix ({ lib, pkgs, ... }:
4 name = "prometheus-alertmanager";
7 prometheus = { config, pkgs, ... }: {
8 environment.systemPackages = [ pkgs.jq ];
10 networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
12 services.prometheus = {
14 globalConfig.scrape_interval = "2s";
22 "alertmanager:${toString config.services.prometheus.alertmanager.port}"
40 summary: "Instance {{ $labels.instance }} down"
46 job_name = "alertmanager";
50 "alertmanager:${toString config.services.prometheus.alertmanager.port}"
60 "node:${toString config.services.prometheus.exporters.node.port}"
69 alertmanager = { config, pkgs, ... }: {
70 services.prometheus.alertmanager = {
76 resolve_timeout = "1m";
85 group_interval = "15s";
86 repeat_interval = "24h";
94 url = "http://logger:6725";
105 logger = { config, pkgs, ... }: {
106 networking.firewall.allowedTCPPorts = [ 6725 ];
108 services.prometheus.alertmanagerWebhookLogger.enable = true;
113 alertmanager.wait_for_unit("alertmanager")
114 alertmanager.wait_for_open_port(9093)
115 alertmanager.wait_until_succeeds("curl -s http://127.0.0.1:9093/-/ready")
116 #alertmanager.wait_until_succeeds("journalctl -o cat -u alertmanager.service | grep 'version=${pkgs.prometheus-alertmanager.version}'")
118 logger.wait_for_unit("alertmanager-webhook-logger")
119 logger.wait_for_open_port(6725)
121 prometheus.wait_for_unit("prometheus")
122 prometheus.wait_for_open_port(9090)
124 prometheus.wait_until_succeeds(
125 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(up\{job=\"alertmanager\"\}==1)' | "
126 + "jq '.data.result[0].value[1]' | grep '\"1\"'"
129 prometheus.wait_until_succeeds(
130 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=sum(alertmanager_build_info)%20by%20(version)' | "
131 + "jq '.data.result[0].metric.version' | grep '\"${pkgs.prometheus-alertmanager.version}\"'"
134 prometheus.wait_until_succeeds(
135 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=count(up\{job=\"node\"\}!=1)' | "
136 + "jq '.data.result[0].value[1]' | grep '\"1\"'"
139 prometheus.wait_until_succeeds(
140 "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=alertmanager_notifications_total\{integration=\"webhook\"\}' | "
141 + "jq '.data.result[0].value[1]' | grep -v '\"0\"'"
144 logger.wait_until_succeeds(
145 "journalctl -o cat -u alertmanager-webhook-logger.service | grep '\"alertname\":\"InstanceDown\"'"
148 logger.log(logger.succeed("systemd-analyze security alertmanager-webhook-logger.service | grep -v '✓'"))
150 alertmanager.log(alertmanager.succeed("systemd-analyze security alertmanager.service | grep -v '✓'"))