mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
chore(monitoring): nf-fmt-nix
This commit is contained in:
parent
23b746191f
commit
f1d249d4c0
10 changed files with 208 additions and 135 deletions
|
|
@ -1,6 +1,9 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) types mkIf mkOption mkEnableOption mkPackageOption mkOptionDefault;
|
||||
|
||||
cfg = config.services.gatus;
|
||||
|
|
@ -189,7 +192,8 @@ in {
|
|||
};
|
||||
failure-threshold = mkOption {type = types.ints.positive;};
|
||||
success-threshold = mkOption {type = types.ints.positive;};
|
||||
send-on-resolved = mkEnableOption
|
||||
send-on-resolved =
|
||||
mkEnableOption
|
||||
"sending a notification once a triggered alert is marked as solved";
|
||||
description = mkOption {type = types.str;};
|
||||
};
|
||||
|
|
@ -235,7 +239,8 @@ in {
|
|||
'';
|
||||
};
|
||||
security = mkOption {
|
||||
type = types.nullOr
|
||||
type =
|
||||
types.nullOr
|
||||
(types.submodule {freeformType = (pkgs.formats.yaml {}).type;});
|
||||
default = null;
|
||||
description = ''
|
||||
|
|
@ -269,8 +274,7 @@ in {
|
|||
certificate-file = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
default = null;
|
||||
description =
|
||||
"Optional public certificate file for TLS in PEM format";
|
||||
description = "Optional public certificate file for TLS in PEM format";
|
||||
};
|
||||
private-key-file = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
|
|
|
|||
|
|
@ -169,13 +169,16 @@
|
|||
getAddressFor ? "getAddressFor",
|
||||
}: let
|
||||
scheme' =
|
||||
if scheme == null then "${port.protocol}://"
|
||||
else if scheme == "" then ""
|
||||
if scheme == null
|
||||
then "${port.protocol}://"
|
||||
else if scheme == ""
|
||||
then ""
|
||||
else "${scheme}://";
|
||||
port' =
|
||||
if !port.enable
|
||||
then throw "${system.name}.exports.services.${service.name}.ports.${portName} isn't enabled"
|
||||
else if port.port == defaultPort then ""
|
||||
else if port.port == defaultPort
|
||||
then ""
|
||||
else ":${toString port.port}";
|
||||
url = "${scheme'}${mkAddress6 host}${port'}";
|
||||
in
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
inherit (gensokyo-zone.lib) mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkOptionDefault;
|
||||
in {
|
||||
config.exports.services.dnsmasq = {system, config, ...}: {
|
||||
config.exports.services.dnsmasq = {
|
||||
system,
|
||||
config,
|
||||
...
|
||||
}: {
|
||||
displayName = mkAlmostOptionDefault "Dnsmasq";
|
||||
id = mkAlmostOptionDefault "dns";
|
||||
nixos = {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
let
|
||||
portModule = {system, config, gensokyo-zone, lib, ...}: let
|
||||
portModule = {
|
||||
system,
|
||||
config,
|
||||
gensokyo-zone,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) unmerged;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.modules) mkIf mkMerge mkOptionDefault;
|
||||
|
|
@ -11,12 +17,16 @@ let
|
|||
status = {
|
||||
enable = mkEnableOption "status checks";
|
||||
alert = {
|
||||
enable = mkEnableOption "health check alerts" // {
|
||||
enable =
|
||||
mkEnableOption "health check alerts"
|
||||
// {
|
||||
default = system.exports.status.alert.enable;
|
||||
};
|
||||
};
|
||||
gatus = {
|
||||
enable = mkEnableOption "gatus" // {
|
||||
enable =
|
||||
mkEnableOption "gatus"
|
||||
// {
|
||||
default = true;
|
||||
};
|
||||
client = {
|
||||
|
|
@ -47,15 +57,20 @@ let
|
|||
status.gatus = let
|
||||
cfg = config.status.gatus;
|
||||
defaultProtocol =
|
||||
if config.protocol != null then mkOptionDefault config.protocol
|
||||
else if config.starttls then mkOptionDefault "starttls"
|
||||
else if config.ssl then mkOptionDefault "tls"
|
||||
else if config.transport != "unix" then mkOptionDefault config.transport
|
||||
if config.protocol != null
|
||||
then mkOptionDefault config.protocol
|
||||
else if config.starttls
|
||||
then mkOptionDefault "starttls"
|
||||
else if config.ssl
|
||||
then mkOptionDefault "tls"
|
||||
else if config.transport != "unix"
|
||||
then mkOptionDefault config.transport
|
||||
else mkIf false (throw "unreachable");
|
||||
in {
|
||||
protocol = defaultProtocol;
|
||||
http.statusCondition = mkOptionDefault (
|
||||
if cfg.protocol == "http" || cfg.protocol == "https" then "[STATUS] == 200"
|
||||
if cfg.protocol == "http" || cfg.protocol == "https"
|
||||
then "[STATUS] == 200"
|
||||
else null
|
||||
);
|
||||
settings = mkMerge [
|
||||
|
|
@ -174,12 +189,18 @@ in
|
|||
name = "node";
|
||||
port = 9091;
|
||||
}
|
||||
{
|
||||
name = "unifi";
|
||||
port = 9130;
|
||||
}
|
||||
];
|
||||
in {
|
||||
options.exports = with lib.types; {
|
||||
prometheus = {
|
||||
exporter = {
|
||||
enable = mkEnableOption "prometheus ingress" // {
|
||||
enable =
|
||||
mkEnableOption "prometheus ingress"
|
||||
// {
|
||||
default = config.access.online.enable;
|
||||
};
|
||||
services = mkOption {
|
||||
|
|
@ -188,11 +209,15 @@ in
|
|||
};
|
||||
};
|
||||
status = {
|
||||
enable = mkEnableOption "status checks" // {
|
||||
enable =
|
||||
mkEnableOption "status checks"
|
||||
// {
|
||||
default = config.access.online.enable;
|
||||
};
|
||||
alert = {
|
||||
enable = mkEnableOption "health check alerts" // {
|
||||
enable =
|
||||
mkEnableOption "health check alerts"
|
||||
// {
|
||||
default = config.access.online.enable && config.type == "NixOS";
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@
|
|||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
in {
|
||||
config.exports.services.nginx = {config, system, ...}: let
|
||||
config.exports.services.nginx = {
|
||||
config,
|
||||
system,
|
||||
...
|
||||
}: let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.nginx;
|
||||
in
|
||||
|
|
|
|||
|
|
@ -31,8 +31,10 @@
|
|||
displayName = mkOption {
|
||||
type = nullOr str;
|
||||
default =
|
||||
if config.name == "default" then null
|
||||
else if config.ssl && (config.name == "ssl" || config.name == "https") then "SSL"
|
||||
if config.name == "default"
|
||||
then null
|
||||
else if config.ssl && (config.name == "ssl" || config.name == "https")
|
||||
then "SSL"
|
||||
else config.name;
|
||||
};
|
||||
listen = mkOption {
|
||||
|
|
|
|||
|
|
@ -17,14 +17,22 @@
|
|||
statusServices = map (serviceName: system.config.exports.services.${serviceName}) system.config.exports.status.services;
|
||||
serviceEndpoints = concatMap (mkServiceEndpoint system) statusServices;
|
||||
systemEndpoint = mkSystemEndpoint system;
|
||||
in serviceEndpoints ++ [ systemEndpoint ];
|
||||
mkPortEndpoint = { system, service, port, unique }: let
|
||||
in
|
||||
serviceEndpoints ++ [systemEndpoint];
|
||||
mkPortEndpoint = {
|
||||
system,
|
||||
service,
|
||||
port,
|
||||
unique,
|
||||
}: let
|
||||
inherit (port.status) gatus;
|
||||
hasId = service.id != service.name;
|
||||
displayName = service.displayName + optionalString (!unique && port.displayName != null) "/${port.displayName}";
|
||||
name = concatStringsSep "-" ([
|
||||
service.name
|
||||
] ++ optional hasId service.id ++ [
|
||||
]
|
||||
++ optional hasId service.id
|
||||
++ [
|
||||
port.name
|
||||
system.config.name
|
||||
]);
|
||||
|
|
@ -37,16 +45,24 @@
|
|||
};
|
||||
starttls.host = system.config.access.fqdn;
|
||||
};
|
||||
urlConf = {
|
||||
urlConf =
|
||||
{
|
||||
inherit service port network;
|
||||
system = system.config;
|
||||
scheme = gatus.protocol;
|
||||
${if gatus.client.network != "ip" then "getAddressFor" else null} = {
|
||||
${
|
||||
if gatus.client.network != "ip"
|
||||
then "getAddressFor"
|
||||
else null
|
||||
} =
|
||||
{
|
||||
ip = "getAddressFor";
|
||||
ip4 = "getAddress4For";
|
||||
ip6 = "getAddress6For";
|
||||
}.${gatus.client.network};
|
||||
} // protocolOverrides.${gatus.protocol} or { };
|
||||
}
|
||||
.${gatus.client.network};
|
||||
}
|
||||
// protocolOverrides.${gatus.protocol} or {};
|
||||
url = access.proxyUrlFor urlConf + optionalString (gatus.http.path != "/") gatus.http.path;
|
||||
conf = {
|
||||
enabled = mkIf (gatus.protocol == "starttls") (mkAlmostOptionDefault false);
|
||||
|
|
@ -55,8 +71,10 @@
|
|||
url = mkOptionDefault url;
|
||||
client.network = mkAlmostOptionDefault gatus.client.network;
|
||||
};
|
||||
in nameValuePair name (_: {
|
||||
imports = [ alertingConfig ]
|
||||
in
|
||||
nameValuePair name (_: {
|
||||
imports =
|
||||
[alertingConfig]
|
||||
++ optional port.status.alert.enable alertingConfigAlerts
|
||||
++ optional (gatus.protocol == "http" || gatus.protocol == "https") alertingConfigHttp;
|
||||
|
||||
|
|
@ -66,20 +84,31 @@
|
|||
];
|
||||
});
|
||||
mkServiceEndpoint = system: service: let
|
||||
statusPorts = map /*lib.attrsets.getAttr*/(portName: service.ports.${portName}) service.status.ports;
|
||||
statusPorts =
|
||||
map
|
||||
(portName: service.ports.${portName})
|
||||
service.status.ports;
|
||||
gatusPorts = filter (port: port.status.gatus.enable) statusPorts;
|
||||
unique = length gatusPorts == 1;
|
||||
in map (port: mkPortEndpoint {
|
||||
in
|
||||
map (port:
|
||||
mkPortEndpoint {
|
||||
inherit system service port unique;
|
||||
}) gatusPorts;
|
||||
})
|
||||
gatusPorts;
|
||||
mkSystemEndpoint = system: let
|
||||
inherit (system.config.exports) status;
|
||||
network = "lan";
|
||||
getAddressFor = if system.config.network.networks.local.address4 or null != null then "getAddress4For" else "getAddressFor";
|
||||
getAddressFor =
|
||||
if system.config.network.networks.local.address4 or null != null
|
||||
then "getAddress4For"
|
||||
else "getAddressFor";
|
||||
addr = access.${getAddressFor} system.config.name network;
|
||||
addrIs6 = hasInfix ":" addr;
|
||||
in nameValuePair "ping-${system.config.name}" (_: {
|
||||
imports = [ alertingConfig ]
|
||||
in
|
||||
nameValuePair "ping-${system.config.name}" (_: {
|
||||
imports =
|
||||
[alertingConfig]
|
||||
++ optional status.alert.enable alertingConfigAlerts;
|
||||
config = {
|
||||
name = mkAlmostOptionDefault system.config.name;
|
||||
|
|
@ -131,7 +160,9 @@
|
|||
systems = "Systems";
|
||||
forSystem = system: let
|
||||
node = systems.${system.config.proxmox.node.name}.config;
|
||||
in if system.config.proxmox.enabled then "${groups.systems}/${node.name}"
|
||||
in
|
||||
if system.config.proxmox.enabled
|
||||
then "${groups.systems}/${node.name}"
|
||||
else groups.systems;
|
||||
};
|
||||
in {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue