services...
This commit is contained in:
parent
73d2f44d74
commit
8552656731
15 changed files with 918 additions and 490 deletions
|
|
@ -6,9 +6,18 @@ serviceName: {
|
|||
with lib; let
|
||||
cfg = config.homelab.services.${serviceName};
|
||||
homelabCfg = config.homelab;
|
||||
|
||||
shouldEnableLogging =
|
||||
cfg.logging.files
|
||||
!= []
|
||||
|| cfg.logging.extraSources != [];
|
||||
in {
|
||||
options.homelab.services.${serviceName}.logging = {
|
||||
enable = mkEnableOption "logging for ${serviceName}";
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
description = "Enable logging for ${serviceName}";
|
||||
default = shouldEnableLogging;
|
||||
};
|
||||
|
||||
files = mkOption {
|
||||
type = types.listOf types.str;
|
||||
|
|
@ -51,37 +60,33 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
config = mkIf (cfg.enable && cfg.logging.enable) {
|
||||
homelab.logging.sources =
|
||||
[
|
||||
{
|
||||
name = "${serviceName}-logs";
|
||||
type = "file";
|
||||
files = {
|
||||
paths = cfg.logging.files;
|
||||
multiline = cfg.logging.multiline;
|
||||
config = mkIf cfg.enable {
|
||||
homelab.logging.sources = mkIf cfg.logging.enable (
|
||||
# Only create file source if files are specified
|
||||
(optional (cfg.logging.files != []) {
|
||||
name = "${serviceName}-logs";
|
||||
type = "file";
|
||||
files = {
|
||||
paths = cfg.logging.files;
|
||||
multiline = cfg.logging.multiline;
|
||||
};
|
||||
labels =
|
||||
cfg.logging.extraLabels
|
||||
// {
|
||||
service = serviceName;
|
||||
node = homelabCfg.hostname;
|
||||
environment = homelabCfg.environment;
|
||||
};
|
||||
labels =
|
||||
cfg.logging.extraLabels
|
||||
// {
|
||||
service = serviceName;
|
||||
node = homelabCfg.hostname;
|
||||
environment = homelabCfg.environment;
|
||||
};
|
||||
pipelineStages =
|
||||
mkIf (cfg.logging.parsing.regex != null) [
|
||||
{
|
||||
regex.expression = cfg.logging.parsing.regex;
|
||||
}
|
||||
]
|
||||
++ [
|
||||
{
|
||||
labels = listToAttrs (map (field: nameValuePair field null) cfg.logging.parsing.extractFields);
|
||||
}
|
||||
];
|
||||
enabled = true;
|
||||
}
|
||||
]
|
||||
++ cfg.logging.extraSources;
|
||||
pipelineStages =
|
||||
(optional (cfg.logging.parsing.regex != null) {
|
||||
regex.expression = cfg.logging.parsing.regex;
|
||||
})
|
||||
++ (optional (cfg.logging.parsing.extractFields != []) {
|
||||
labels = listToAttrs (map (field: nameValuePair field null) cfg.logging.parsing.extractFields);
|
||||
});
|
||||
enabled = true;
|
||||
})
|
||||
++ cfg.logging.extraSources
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue