{ 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; 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); }; }