From 5ebe26caf857f0f0a05e9bb5fed453c48fd14044 Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 20 Apr 2024 14:34:42 +0200 Subject: [PATCH] lib/clerie-monitoring-ids.nix: Add functions to analyse assigned monitoring ids --- flake.nix | 2 ++ lib/clerie-monitoring-ids.nix | 13 +++++++++++++ lib/default.nix | 1 + 3 files changed, 16 insertions(+) create mode 100644 lib/clerie-monitoring-ids.nix diff --git a/flake.nix b/flake.nix index d7699a0..810a4ab 100644 --- a/flake.nix +++ b/flake.nix @@ -134,6 +134,8 @@ uptimestatus; }); + inherit lib self; + hydraJobs = { inherit (self) packages; diff --git a/lib/clerie-monitoring-ids.nix b/lib/clerie-monitoring-ids.nix new file mode 100644 index 0000000..fe3f64a --- /dev/null +++ b/lib/clerie-monitoring-ids.nix @@ -0,0 +1,13 @@ +inputs: + +with inputs.nixpkgs.lib; + +rec { + monitoringIdForHost = host: let + evalResult = builtins.tryEval (attrByPath [ "clerie" "monitoring" "id" ] null host.config); + in + if evalResult.success then evalResult.value else null; + monitoringIdsByHost = hosts: filterAttrs (name: id: id != null) (mapAttrs (name: host: monitoringIdForHost host) hosts); + hostsByMonitoringIds = hosts: mapAttrs' (name: id: nameValuePair id name) (monitoringIdsByHost hosts); + monitoringIds = hosts: attrNames (hostsByMonitoringIds hosts); +} diff --git a/lib/default.nix b/lib/default.nix index ba58fa5..d43387f 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -14,6 +14,7 @@ let generateColmenaHost mapToColmenaHosts buildHosts; + clerie-monitoring-ids = callLibs ./clerie-monitoring-ids.nix; }; in