-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nixos/prometheus-snmp-exporter: add config check
This is introduced and enabled by default because the config syntax for the exporter changed with release 0.23.0. This should make the breaking config change obvious before services are deployed with an incompatible old config. The check is based on the check present in the blackbox-exporter module.
- Loading branch information
Showing
2 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,25 @@ with lib; | |
|
||
let | ||
cfg = config.services.prometheus.exporters.snmp; | ||
|
||
# This ensures that we can deal with string paths, path types and | ||
# store-path strings with context. | ||
coerceConfigFile = file: | ||
if (builtins.isPath file) || (lib.isStorePath file) then | ||
file | ||
else | ||
(lib.warn '' | ||
${logPrefix}: configuration file "${file}" is being copied to the nix-store. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
WilliButz
Author
Member
|
||
If you would like to avoid that, please set enableConfigCheck to false. | ||
'' /. + file); | ||
|
||
checkConfig = file: | ||
pkgs.runCommandLocal "checked-snmp-exporter-config.yml" { | ||
nativeBuildInputs = [ pkgs.buildPackages.prometheus-snmp-exporter ]; | ||
} '' | ||
ln -s ${coerceConfigFile file} $out | ||
snmp_exporter --dry-run --config.file $out | ||
''; | ||
in | ||
{ | ||
port = 9116; | ||
|
@@ -31,6 +50,16 @@ in | |
}; | ||
}; | ||
|
||
enableConfigCheck = mkOption { | ||
type = types.bool; | ||
default = true; | ||
description = lib.mdDoc '' | ||
Whether to run a correctness check for the configuration file. This depends | ||
on the configuration file residing in the nix-store. Paths passed as string will | ||
be copied to the store. | ||
''; | ||
}; | ||
|
||
logFormat = mkOption { | ||
type = types.enum ["logfmt" "json"]; | ||
default = "logfmt"; | ||
|
@@ -48,9 +77,13 @@ in | |
}; | ||
}; | ||
serviceOpts = let | ||
configFile = if cfg.configurationPath != null | ||
then cfg.configurationPath | ||
else "${pkgs.writeText "snmp-exporter-conf.yml" (builtins.toJSON cfg.configuration)}"; | ||
uncheckedConfigFile = if cfg.configurationPath != null | ||
then cfg.configurationPath | ||
else "${pkgs.writeText "snmp-exporter-conf.yml" (builtins.toJSON cfg.configuration)}"; | ||
configFile = if cfg.enableConfigCheck then | ||
checkConfig uncheckedConfigFile | ||
else | ||
uncheckedConfigFile; | ||
in { | ||
serviceConfig = { | ||
ExecStart = '' | ||
|
@WilliButz AFAICT,
logPrefix
is not defined there, causing a build issue when this branch is taken.