fuuko/go-neb: Add alertmanager matrix receiver

This commit is contained in:
Simon Bruder 2021-04-02 17:46:07 +02:00
parent 2897451a65
commit 94b2746018
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
5 changed files with 67 additions and 5 deletions

View file

@ -14,7 +14,9 @@
specific service the machine provides.
+ `secrets`: Nix expressions that include information that is not meant to
be visible to everyone (e.g. accounts, password hashes, private
information etc.)
information etc.) or secrets for services that dont provide any other
(easy) way of specifying them and whose secrets leaking does not pose a
huge threat
* `modules`: Custom modules. Many are activated by default, since I want them
on all systems.
* `pkgs`: My nixpkgs overlay

Binary file not shown.

View file

@ -2,5 +2,6 @@
imports = [
./synapse.nix
./mautrix-whatsapp.nix
./go-neb.nix
];
}

View file

@ -0,0 +1,56 @@
{ config, ... }:
let
synapseCfg = config.services.matrix-synapse;
in
{
services.go-neb = rec {
enable = true;
bindAddress = "127.0.0.1:8010";
baseUrl = "http://${bindAddress}";
config = {
clients = [
({
UserID = "@alertmanager:${synapseCfg.server_name}";
HomeserverURL = synapseCfg.public_baseurl;
Sync = false;
AutoJoinRooms = false;
DisplayName = "Prometheus Alertmanager";
} // (import ../../secrets/go-neb-alertmanager.nix)) # AccessToken and DeviceID
];
services = [
{
ID = "alertmanager_service";
Type = "alertmanager";
UserID = "@alertmanager:${synapseCfg.server_name}";
Config = {
webhook_url = "${baseUrl}/services/hooks/YWxlcnRtYW5hZ2VyX3NlcnZpY2U";
rooms = {
"!ceigaGYfREXXSeLFiH:sbruder.de" = {
text_template = "{{ range .Alerts }}[{{ .Status }}] {{ index .Labels \"alertname\" }}: {{ index .Annotations \"description\" }}\n{{ end }}";
html_template = ''
{{ range .Alerts }}
{{ $severity := index .Labels "severity" }}
<font{{ if eq .Status "firing" -}}
{{- if eq $severity "critical" }} color="red"
{{- else if eq $severity "warning" }} color="orange"
{{- end -}}
{{- else }} color="green"
{{- end }}>
<strong>{{ if eq .Status "firing" -}}
[firing{{ if ne $severity "" }} - {{ $severity }}{{ end }}]
{{- else -}}
[resolved]
{{- end }}</strong>
</font>
{{ index .Labels "alertname" }}: {{ index .Annotations "description" }} <a href="{{ .GeneratorURL }}">source</a><br/>
{{ end }}
'';
msg_type = "m.text";
};
};
};
}
];
};
};
}

View file

@ -51,10 +51,13 @@ in
receivers = [
{
name = "matrix";
webhook_configs = [
# FIXME: Add correct URL
{ url = "http://matrix-alertmanager:3000/alerts"; }
];
webhook_configs = lib.singleton {
url = (lib.elemAt
(lib.filter
({ ID, ... }: ID == "alertmanager_service")
config.services.go-neb.config.services)
0).Config.webhook_url;
};
}
];
};