Add special metric srv records

This commit is contained in:
niten 2022-01-15 06:41:50 -08:00
parent 83fda1a391
commit 6048978a33
3 changed files with 106 additions and 49 deletions

View File

@ -1,35 +1,13 @@
# NOTE: this assumes that postgres is running locally. # NOTE: this assumes that postgres is running locally.
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... } @ toplevel:
with lib; with lib;
let let
cfg = config.fudo.grafana; cfg = config.fudo.grafana;
fudo-cfg = config.fudo.common;
database-name = "grafana"; hostname = config.instance.hostname;
database-user = "grafana"; domain-name = config.fudo.hosts.${hostname}.domain;
databaseOpts = { ... }: {
options = {
name = mkOption {
type = types.str;
description = "Database name.";
};
hostname = mkOption {
type = types.str;
description = "Hostname of the database server.";
};
user = mkOption {
type = types.str;
description = "Database username.";
};
password-file = mkOption {
type = types.path;
description = "File containing the database user's password.";
};
};
};
in { in {
@ -37,45 +15,82 @@ in {
enable = mkEnableOption "Fudo Metrics Display Service"; enable = mkEnableOption "Fudo Metrics Display Service";
hostname = mkOption { hostname = mkOption {
type = types.str; type = str;
description = "Grafana site hostname."; description = "Grafana site hostname.";
example = "fancy-graphs.fudo.org"; example = "fancy-graphs.fudo.org";
}; };
smtp-username = mkOption { smtp = {
type = types.str; username = mkOption {
description = "Username with which to send email."; type = str;
description = "Username with which to send email.";
default = "metrics";
};
password-file = mkOption {
type = str;
description = "Path to a file containing the email user's password.";
};
hostname = mkOption {
type = str;
description = "Mail server hostname.";
default = "mail.${domain-name}";
};
email = mkOption {
type = str;
description = "Address from which mail will be sent (i.e. 'from' address).";
default = "${toplevel.config.fudo.grafana.smtp.username}@${domain-name}";
};
}; };
smtp-password-file = mkOption { database = {
type = types.path; name = mkOption {
description = "Path to a file containing the email user's password."; type = str;
}; description = "Database name.";
default = "grafana";
database = mkOption { };
type = (types.submodule databaseOpts); hostname = mkOption {
description = "Grafana database configuration."; type = str;
description = "Hostname of the database server.";
default = "localhost";
};
user = mkOption {
type = str;
description = "Database username.";
default = "grafana";
};
password-file = mkOption {
type = str;
description = "File containing the database user's password.";
};
}; };
admin-password-file = mkOption { admin-password-file = mkOption {
type = types.path; type = str;
description = "Path to a file containing the admin user's password."; description = "Path to a file containing the admin user's password.";
}; };
secret-key-file = mkOption { secret-key-file = mkOption {
type = types.path; type = str;
description = "Path to a file containing the server's secret key, used for signatures."; description = "Path to a file containing the server's secret key, used for signatures.";
}; };
prometheus-host = mkOption { prometheus-hosts = mkOption {
type = types.str; type = listOf str;
description = "The URL of the prometheus data source."; description = "A list of URLs to prometheus data sources.";
default = [];
};
state-directory = mkOption {
type = str;
description = "Directory at which to store Grafana state data.";
default = "/var/lib/grafana";
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
security.acme.certs.${cfg.hostname}.email = fudo-cfg.admin-email;
services.nginx = { services.nginx = {
enable = true; enable = true;
@ -105,8 +120,9 @@ in {
addr = "127.0.0.1"; addr = "127.0.0.1";
protocol = "http"; protocol = "http";
port = 3000; port = 3000;
domain = "${cfg.hostname}"; domain = cfg.hostname;
rootUrl = "https://${cfg.hostname}/"; rootUrl = "https://${cfg.hostname}/";
dataDir = cfg.state-directory;
security = { security = {
adminPasswordFile = cfg.admin-password-file; adminPasswordFile = cfg.admin-password-file;

View File

@ -60,6 +60,15 @@ let
makeSrvProtocolRecords = protocol: services: makeSrvProtocolRecords = protocol: services:
join-lines (mapAttrsToList (makeSrvRecords protocol) services); join-lines (mapAttrsToList (makeSrvRecords protocol) services);
makeMetricRecords = metric-type: records:
join-lines
(map (record:
"${metric-type}._metrics._tcp IN SRV ${
toString record.priority
} ${
toString record.weight
} ${record.host}.") records);
srvRecordOpts = with types; { srvRecordOpts = with types; {
options = { options = {
weight = mkOption { weight = mkOption {
@ -140,6 +149,8 @@ let
${join-lines (mapAttrsToList makeSrvProtocolRecords zone.srv-records)} ${join-lines (mapAttrsToList makeSrvProtocolRecords zone.srv-records)}
${join-lines (mapAttrsToList makeMetricRecords zone.metric-records)}
$TTL ${zone.host-record-ttl} $TTL ${zone.host-record-ttl}
${join-lines (mapAttrsToList hostRecords zone.hosts)} ${join-lines (mapAttrsToList hostRecords zone.hosts)}

View File

@ -62,15 +62,45 @@ let
description = "SRV records for the network."; description = "SRV records for the network.";
example = { example = {
tcp = { tcp = {
kerberos = { kerberos = [
port = 88; {
host = "krb-host.my-domain.com"; port = 88;
}; host = "krb-host.my-domain.com";
}
{
port = 88;
host = "krb-host2.my-domain.com";
}
];
}; };
}; };
default = { }; default = { };
}; };
metric-records = mkOption {
type = attrsOf (listOf (submodule srvRecordOpts));
description = "Map of metric type to list of SRV host records.";
example = {
node = [
{
host = "my-host.my-domain.com";
port = 443;
}
{
host = "my-host2.my-domain.com";
port = 443;
}
];
rspamd = [
{
host = "mail-host.my-domain.com";
port = 443;
}
];
};
default = { };
};
aliases = mkOption { aliases = mkOption {
type = attrsOf str; type = attrsOf str;
default = { }; default = { };