modules/nixos/monitoring: matrix-alertmanager-receiver -> matrix-hook

This commit is contained in:
zowoq 2023-08-16 08:01:08 +10:00
parent 076e33ddcc
commit e9a020cfd5
5 changed files with 57 additions and 52 deletions

View file

@ -89,8 +89,8 @@ lib.mapAttrsToList
description = "{{$labels.host}} failed to (re)start service {{$labels.name}}";
};
matrix_alertmanager_receiver_not_running = {
condition = ''systemd_units_active_code{name="matrix-alertmanager-receiver.service", sub!="running"}'';
matrix_hook_not_running = {
condition = ''systemd_units_active_code{name="matrix-hook.service", sub!="running"}'';
description = "{{$labels.host}} should have a running {{$labels.name}}";
};

View file

@ -1,6 +1,6 @@
{
imports = [
./matrix-alertmanager.nix
./matrix-hook.nix
./prometheus.nix
./telegraf.nix
];

View file

@ -1,46 +0,0 @@
{ config, pkgs, ... }:
let
matrix-alertmanager-receiver = pkgs.buildGoModule rec {
pname = "matrix-alertmanager-receiver";
version = "0.1.2";
src = pkgs.fetchFromSourcehut {
owner = "~fnux";
repo = "matrix-alertmanager-receiver";
rev = version;
hash = "sha256-F6Cn0lmASAjWGEBCmyLdfz4r06fDTEfZQcynfA/RRtI=";
};
vendorHash = "sha256-7tRCX9FzOsLXCTWWjLp3hr1kegt1dxsbCKfC7tICreo=";
};
in
{
sops.secrets.nix-community-matrix-bot-token = { };
sops.templates."config.toml".content = ''
Homeserver = "https://matrix-client.matrix.org"
TargetRoomID = "!cBybDCkeRlSWfuaFvn:numtide.com"
MXID = "@nix-community-matrix-bot:matrix.org"
MXToken = "${config.sops.placeholder.nix-community-matrix-bot-token}"
HTTPPort = 9088
HTTPAddress = "localhost"
'';
sops.templates."config.toml".owner = "matrix-alertmanager-receiver";
users.users.matrix-alertmanager-receiver = {
isSystemUser = true;
group = "matrix-alertmanager-receiver";
};
users.groups.matrix-alertmanager-receiver = { };
systemd.services.matrix-alertmanager-receiver = {
description = "Matrix Alertmanager Receiver";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${matrix-alertmanager-receiver}/bin/matrix-alertmanager-receiver -config ${config.sops.templates."config.toml".path}";
Restart = "always";
RestartSec = "10";
User = "matrix-alertmanager-receiver";
Group = "matrix-alertmanager-receiver";
};
};
}

View file

@ -0,0 +1,51 @@
{ config, pkgs, ... }:
let
matrixHook = pkgs.buildGoModule rec {
pname = "matrix-hook";
version = "2e2770e685ca57e111b9dd2dc178cc6984404a25";
src = pkgs.fetchFromGitHub {
owner = "pinpox";
repo = "matrix-hook";
rev = version;
hash = "sha256-G5pq9sIz94V2uTYBcuHJsqD2/pMtxhWkAO8B0FncLbE=";
};
vendorHash = "sha256-185Wz9IpJRBmunl+KGj/iy37YeszbT3UYzyk9V994oQ=";
postInstall = ''
install message.html.tmpl -Dt $out
'';
};
in
{
sops.secrets.nix-community-matrix-bot-token = { };
users.users.matrix-hook = {
isSystemUser = true;
group = "matrix-hook";
};
users.groups.matrix-hook = { };
systemd.services.matrix-hook = {
description = "Matrix Hook";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
HTTP_ADDRESS = "localhost";
HTTP_PORT = "9088";
MX_HOMESERVER = "https://matrix-client.matrix.org";
MX_ID = "@nix-community-matrix-bot:matrix.org";
MX_ROOMID = "!cBybDCkeRlSWfuaFvn:numtide.com";
MX_MSG_TEMPLATE = "${matrixHook}/message.html.tmpl";
};
serviceConfig = {
Type = "simple";
ExecStart = "${matrixHook}/bin/matrix-hook";
EnvironmentFile = [
config.sops.secrets.nix-community-matrix-bot-token.path
];
Restart = "always";
RestartSec = "10";
User = "matrix-hook";
Group = "matrix-hook";
};
};
}