mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 18:41:34 +01:00
gatus: split ambiguous "endpoints" option into "customEndpoints" and internal "finalEndpoints"
This commit is contained in:
parent
dd5268ded4
commit
47b35b5ed6
2 changed files with 33 additions and 22 deletions
|
|
@ -19,11 +19,14 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
domain = "status.${config.custom.services.tailscale.domain}";
|
domain = "status.${config.custom.services.tailscale.domain}";
|
||||||
endpointDomains = config.meta.domains.globalList;
|
endpointDomains = config.meta.domains.globalList;
|
||||||
endpoints = {
|
customEndpoints = {
|
||||||
"status".group = "Monitoring";
|
"status" = {
|
||||||
|
group = "Monitoring";
|
||||||
|
url = "https://${config.custom.services.gatus.domain}";
|
||||||
|
};
|
||||||
"alerts" = {
|
"alerts" = {
|
||||||
group = "Monitoring";
|
group = "Monitoring";
|
||||||
appendPath = "/v1/health";
|
url = "https://alerts.${config.custom.services.tailscale.domain}/v1/health";
|
||||||
extraConditions = [ "[BODY].healthy == true" ];
|
extraConditions = [ "[BODY].healthy == true" ];
|
||||||
};
|
};
|
||||||
"git ssh".url = "ssh://git.sstork.dev";
|
"git ssh".url = "ssh://git.sstork.dev";
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,20 @@
|
||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.custom.services.gatus;
|
cfg = config.custom.services.gatus;
|
||||||
|
|
||||||
|
defaultEndpoints =
|
||||||
|
let
|
||||||
|
getSubdomain = domain: domain |> lib.splitString "." |> lib.head;
|
||||||
|
in
|
||||||
|
cfg.endpointDomains
|
||||||
|
|> lib.map (
|
||||||
|
domain:
|
||||||
|
lib.nameValuePair (getSubdomain domain) {
|
||||||
|
name = getSubdomain domain;
|
||||||
|
url = "https://${domain}";
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|> lib.listToAttrs;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.custom.services.gatus = {
|
options.custom.services.gatus = {
|
||||||
|
|
@ -17,7 +31,7 @@ in
|
||||||
type = lib.types.listOf lib.types.nonEmptyStr;
|
type = lib.types.listOf lib.types.nonEmptyStr;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
};
|
};
|
||||||
endpoints = lib.mkOption {
|
customEndpoints = lib.mkOption {
|
||||||
type = lib.types.attrsOf (
|
type = lib.types.attrsOf (
|
||||||
lib.types.submodule (
|
lib.types.submodule (
|
||||||
{ name, ... }:
|
{ name, ... }:
|
||||||
|
|
@ -35,10 +49,6 @@ in
|
||||||
type = lib.types.nonEmptyStr;
|
type = lib.types.nonEmptyStr;
|
||||||
default = "";
|
default = "";
|
||||||
};
|
};
|
||||||
appendPath = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "";
|
|
||||||
};
|
|
||||||
extraConditions = lib.mkOption {
|
extraConditions = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.nonEmptyStr;
|
type = lib.types.listOf lib.types.nonEmptyStr;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
|
|
@ -49,6 +59,11 @@ in
|
||||||
);
|
);
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
finalEndpoints = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf lib.types.anything;
|
||||||
|
default = defaultEndpoints // cfg.customEndpoints;
|
||||||
|
readOnly = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
|
@ -61,14 +76,6 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
custom.services.gatus.endpoints =
|
|
||||||
let
|
|
||||||
getSubdomain = domain: domain |> lib.splitString "." |> lib.head;
|
|
||||||
in
|
|
||||||
cfg.endpointDomains
|
|
||||||
|> lib.map (domain: lib.nameValuePair (getSubdomain domain) { url = "https://${domain}"; })
|
|
||||||
|> lib.listToAttrs;
|
|
||||||
|
|
||||||
services.gatus = {
|
services.gatus = {
|
||||||
enable = true;
|
enable = true;
|
||||||
environmentFile = config.sops.templates."gatus.env".path;
|
environmentFile = config.sops.templates."gatus.env".path;
|
||||||
|
|
@ -108,10 +115,9 @@ in
|
||||||
mkEndpoint = (
|
mkEndpoint = (
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
group,
|
group ? null,
|
||||||
url,
|
url,
|
||||||
appendPath,
|
extraConditions ? [ ],
|
||||||
extraConditions,
|
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
isPrivate = lib.hasInfix config.custom.services.tailscale.domain url;
|
isPrivate = lib.hasInfix config.custom.services.tailscale.domain url;
|
||||||
|
|
@ -120,7 +126,7 @@ in
|
||||||
{
|
{
|
||||||
inherit name;
|
inherit name;
|
||||||
group = if group != null then group else deducedGroup;
|
group = if group != null then group else deducedGroup;
|
||||||
url = url + appendPath;
|
url = url;
|
||||||
alerts = [ { type = "ntfy"; } ];
|
alerts = [ { type = "ntfy"; } ];
|
||||||
ssh = lib.mkIf (lib.hasPrefix "ssh" url) {
|
ssh = lib.mkIf (lib.hasPrefix "ssh" url) {
|
||||||
username = "";
|
username = "";
|
||||||
|
|
@ -144,7 +150,9 @@ in
|
||||||
conditions = [ "[STATUS] == 200" ];
|
conditions = [ "[STATUS] == 200" ];
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
++ (cfg.endpoints |> lib.mapAttrsToList (_: value: value) |> lib.map (entry: mkEndpoint entry));
|
++ (
|
||||||
|
cfg.finalEndpoints |> lib.mapAttrsToList (_: value: value) |> lib.map (entry: mkEndpoint entry)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue