stateless-uptime-kuma/lib/default.nix

83 lines
1.8 KiB
Nix
Raw Normal View History

2024-04-18 20:27:17 +02:00
{ lib }:
rec {
mkFqdn = _: cfg: cfg.networking.fqdn;
probesWithTag =
{
name,
value ? null,
}:
probesConfig:
lib.filterAttrs (
k: v: lib.any (tag: tag.name == name && (value == null || tag.value == value)) v.tags
) probesConfig.monitors;
probesWithType = type: probesConfig: lib.filterAttrs (_: v: v.type == type) probesConfig.monitors;
2024-04-18 20:27:17 +02:00
fromHive =
{
builder,
nodes,
excludes ? [ ],
}:
lib.mkMerge (
builtins.map (node: builder node nodes.${node}) (
lib.subtractLists excludes (builtins.attrNames nodes)
)
);
pingProbesFromHive =
{
mkHost,
nodes,
prefix ? "Ping ",
excludes ? [ ],
tags ? [ ],
}:
fromHive {
builder = (
node: module: {
2024-04-21 18:13:30 +02:00
monitors = let
hostname = mkHost node module.config;
in {
${prefix + hostname} = {
2024-04-18 20:27:17 +02:00
type = "ping";
2024-04-21 18:13:30 +02:00
inherit tags hostname;
2024-04-18 20:27:17 +02:00
};
};
}
);
inherit nodes excludes;
};
httpProbesFromConfig =
{
config,
excludes ? [ ],
prefix ? "",
type ? "keyword",
tags ? [ ],
}:
let
filter = k: v: !builtins.elem k excludes && v.globalRedirect == null;
in
{
monitors = lib.mapAttrs' (
vhostName: vhost:
let
hasSSL = vhost.onlySSL || vhost.enableSSL || vhost.addSSL || vhost.forceSSL;
serverName = if vhost.serverName != null then vhost.serverName else vhostName;
in
{
name = prefix + serverName;
value = {
inherit type;
inherit tags;
url = "http${lib.optionalString hasSSL "s"}://${serverName}";
method = "get";
};
}
) (lib.filterAttrs filter config.services.nginx.virtualHosts);
};
}