Set up alertmanager-hookshot-adapter
This commit is contained in:
parent
9ad279a505
commit
f8cad42b5c
|
@ -9,6 +9,7 @@ let
|
||||||
hydra-ssh-key-priv = [ machines.bagel-box ];
|
hydra-ssh-key-priv = [ machines.bagel-box ];
|
||||||
netbox-environment = [ machines.meta01 ];
|
netbox-environment = [ machines.meta01 ];
|
||||||
mimir-environment = [ machines.meta01 ];
|
mimir-environment = [ machines.meta01 ];
|
||||||
|
mimir-webhook-url = [ machines.meta01 ];
|
||||||
grafana-oauth-secret = [ machines.meta01 ];
|
grafana-oauth-secret = [ machines.meta01 ];
|
||||||
loki-environment = [ machines.meta01 ];
|
loki-environment = [ machines.meta01 ];
|
||||||
gerrit-prometheus-bearer-token = [ machines.gerrit01 machines.meta01 ];
|
gerrit-prometheus-bearer-token = [ machines.gerrit01 machines.meta01 ];
|
||||||
|
|
BIN
secrets/mimir-webhook-url.age
Normal file
BIN
secrets/mimir-webhook-url.age
Normal file
Binary file not shown.
|
@ -3,5 +3,6 @@
|
||||||
./exporters
|
./exporters
|
||||||
./lgtm
|
./lgtm
|
||||||
./agent.nix
|
./agent.nix
|
||||||
|
./hookshot-adapter
|
||||||
];
|
];
|
||||||
}
|
}
|
30
services/monitoring/hookshot-adapter/default.nix
Normal file
30
services/monitoring/hookshot-adapter/default.nix
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.bagel.services.alertmanager-hookshot-adapter;
|
||||||
|
inherit (lib) mkEnableOption mkIf;
|
||||||
|
package = pkgs.callPackage ./package.nix {};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.bagel.services.alertmanager-hookshot-adapter.enable = mkEnableOption "alertmanager to matrix-hookshot adapter";
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
systemd.services.alertmanager-hookshot-adapter = {
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
wants = ["network-online.target"];
|
||||||
|
after = ["network-online.target"];
|
||||||
|
environment = {
|
||||||
|
PORT = "9100";
|
||||||
|
UPSTREAM = "https://alerts.forkos.org/webhook";
|
||||||
|
};
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = lib.getExe package;
|
||||||
|
DynamicUser = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
23
services/monitoring/hookshot-adapter/package.json
Normal file
23
services/monitoring/hookshot-adapter/package.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"name": "alertmanager-hookshot-adapter",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Adapter between alertmanager webhooks and the Matrix Hookshot Apapter",
|
||||||
|
"main": "index.ts",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/hm-edu/alertmanager-hookshot-adapter"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@types/express": "^4.17.21",
|
||||||
|
"@types/node": "^20.11.20",
|
||||||
|
"dotenv": "^16.4.5",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"node-fetch": "^3.3.2",
|
||||||
|
"typescript": "^5.3.3",
|
||||||
|
"winston": "^3.13.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "npx tsc"
|
||||||
|
}
|
||||||
|
}
|
40
services/monitoring/hookshot-adapter/package.nix
Normal file
40
services/monitoring/hookshot-adapter/package.nix
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
mkYarnPackage,
|
||||||
|
fetchFromGitHub,
|
||||||
|
fetchYarnDeps,
|
||||||
|
makeWrapper,
|
||||||
|
nodejs,
|
||||||
|
}:
|
||||||
|
|
||||||
|
mkYarnPackage rec {
|
||||||
|
pname = "alertmanager-hookshot-adapter";
|
||||||
|
version = "1.9.1";
|
||||||
|
|
||||||
|
src = fetchFromGitHub {
|
||||||
|
owner = "hm-edu";
|
||||||
|
repo = "alertmanager-hookshot-adapter";
|
||||||
|
rev = "v${version}";
|
||||||
|
hash = "sha256-KTk70zFA1tymmR8AYrAl2XIyA+SPs5Uksd6Z3kvUb+o=";
|
||||||
|
};
|
||||||
|
|
||||||
|
packageJSON = ./package.json;
|
||||||
|
|
||||||
|
offlineCache = fetchYarnDeps {
|
||||||
|
yarnLock = "${src}/yarn.lock";
|
||||||
|
hash = "sha256-LU25cXB+0DdcHRzKQ1hjQIVntarqPOUXZTgcw6lvLRM=";
|
||||||
|
};
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
yarn build
|
||||||
|
'';
|
||||||
|
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
makeWrapper ${lib.getExe nodejs} $out/bin/alertmanager-hookshot-adapter \
|
||||||
|
--add-flags $out/libexec/alertmanager-hookshot-adapter/deps/alertmanager-hookshot-adapter/dist/index.js
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta.mainProgram = "alertmanager-hookshot-adapter";
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ in
|
||||||
owner = "nginx";
|
owner = "nginx";
|
||||||
};
|
};
|
||||||
mimir-environment.file = ../../../secrets/mimir-environment.age;
|
mimir-environment.file = ../../../secrets/mimir-environment.age;
|
||||||
|
mimir-webhook-url.file = ../../../secrets/mimir-webhook-url.age;
|
||||||
};
|
};
|
||||||
|
|
||||||
services.mimir = {
|
services.mimir = {
|
||||||
|
@ -75,6 +76,11 @@ in
|
||||||
receivers = [
|
receivers = [
|
||||||
{
|
{
|
||||||
name = "matrix";
|
name = "matrix";
|
||||||
|
webhook_configs = [{
|
||||||
|
# Mimir can't expand environment variables in external config files,
|
||||||
|
# so work around it.
|
||||||
|
url_file = "/run/credentials/mimir.service/webhook-url";
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
@ -91,7 +97,10 @@ in
|
||||||
# Avoid that by ensuring it starts after the network is set up.
|
# Avoid that by ensuring it starts after the network is set up.
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
after = ["network-online.target"];
|
after = ["network-online.target"];
|
||||||
serviceConfig.EnvironmentFile = [ config.age.secrets.mimir-environment.path ];
|
serviceConfig = {
|
||||||
|
EnvironmentFile = [ config.age.secrets.mimir-environment.path ];
|
||||||
|
LoadCredential = [ "webhook-url:${config.age.secrets.mimir-webhook-url.path}" ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.nginx = {
|
services.nginx = {
|
||||||
|
@ -111,5 +120,6 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
bagel.monitoring.grafana-agent.exporters.mimir.port = 9009;
|
bagel.monitoring.grafana-agent.exporters.mimir.port = 9009;
|
||||||
|
bagel.services.alertmanager-hookshot-adapter.enable = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue