forked from DGNum/stateless-uptime-kuma
69 lines
1.5 KiB
Nix
69 lines
1.5 KiB
Nix
{ lib }:
|
|
rec {
|
|
mkFqdn = _: cfg: cfg.networking.fqdn;
|
|
|
|
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: {
|
|
monitors = {
|
|
${prefix + node} = {
|
|
type = "ping";
|
|
inherit tags;
|
|
hostname = mkHost node module.config;
|
|
};
|
|
};
|
|
}
|
|
);
|
|
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);
|
|
};
|
|
}
|