Merge pull request #81854 from mmilata/prometheus-exporters-fixes

nixos/prometheus-*-exporters: minor fixes
This commit is contained in:
WilliButz 2020-03-06 10:00:13 +01:00 committed by GitHub
commit ff3c06ad9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 36 additions and 31 deletions

View File

@ -197,13 +197,17 @@ in
config = mkMerge ([{ config = mkMerge ([{
assertions = [ { assertions = [ {
assertion = (cfg.snmp.configurationPath == null) != (cfg.snmp.configuration == null); assertion = cfg.snmp.enable -> (
(cfg.snmp.configurationPath == null) != (cfg.snmp.configuration == null)
);
message = '' message = ''
Please ensure you have either `services.prometheus.exporters.snmp.configuration' Please ensure you have either `services.prometheus.exporters.snmp.configuration'
or `services.prometheus.exporters.snmp.configurationPath' set! or `services.prometheus.exporters.snmp.configurationPath' set!
''; '';
} { } {
assertion = (cfg.mail.configFile == null) != (cfg.mail.configuration == {}); assertion = cfg.mail.enable -> (
(cfg.mail.configFile == null) != (cfg.mail.configuration == null)
);
message = '' message = ''
Please specify either 'services.prometheus.exporters.mail.configuration' Please specify either 'services.prometheus.exporters.mail.configuration'
or 'services.prometheus.exporters.mail.configFile'. or 'services.prometheus.exporters.mail.configFile'.

View File

@ -61,7 +61,7 @@ in {
ExecStart = '' ExecStart = ''
${pkgs.prometheus-blackbox-exporter}/bin/blackbox_exporter \ ${pkgs.prometheus-blackbox-exporter}/bin/blackbox_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--config.file ${adjustedConfigFile} \ --config.file ${escapeShellArg adjustedConfigFile} \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}
''; '';
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";

View File

@ -66,7 +66,7 @@ in
serviceConfig = { serviceConfig = {
ExecStart = '' ExecStart = ''
${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \ ${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \
-log.format ${cfg.logFormat} \ -log.format ${escapeShellArg cfg.logFormat} \
-log.level ${cfg.logLevel} \ -log.level ${cfg.logLevel} \
-web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
${collectSettingsArgs} \ ${collectSettingsArgs} \

View File

@ -30,7 +30,7 @@ in
${pkgs.prometheus-dnsmasq-exporter}/bin/dnsmasq_exporter \ ${pkgs.prometheus-dnsmasq-exporter}/bin/dnsmasq_exporter \
--listen ${cfg.listenAddress}:${toString cfg.port} \ --listen ${cfg.listenAddress}:${toString cfg.port} \
--dnsmasq ${cfg.dnsmasqListenAddress} \ --dnsmasq ${cfg.dnsmasqListenAddress} \
--leases_path ${cfg.leasesPath} \ --leases_path ${escapeShellArg cfg.leasesPath} \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}
''; '';
}; };

View File

@ -64,7 +64,7 @@ in
${pkgs.prometheus-dovecot-exporter}/bin/dovecot_exporter \ ${pkgs.prometheus-dovecot-exporter}/bin/dovecot_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \ --web.telemetry-path ${cfg.telemetryPath} \
--dovecot.socket-path ${cfg.socketPath} \ --dovecot.socket-path ${escapeShellArg cfg.socketPath} \
--dovecot.scopes ${concatStringsSep "," cfg.scopes} \ --dovecot.scopes ${concatStringsSep "," cfg.scopes} \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}
''; '';

View File

@ -27,7 +27,7 @@ in
ExecStart = '' ExecStart = ''
${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \ ${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \
--port ${toString cfg.port} \ --port ${toString cfg.port} \
${cfg.url} ${cfg.configFile} \ ${cfg.url} ${escapeShellArg cfg.configFile} \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}
''; '';
}; };

View File

@ -90,7 +90,7 @@ let
Timeout until mails are considered "didn't make it". Timeout until mails are considered "didn't make it".
''; '';
}; };
disableFileDelition = mkOption { disableFileDeletion = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
description = '' description = ''
@ -127,8 +127,8 @@ in
''; '';
}; };
configuration = mkOption { configuration = mkOption {
type = types.submodule exporterOptions; type = types.nullOr (types.submodule exporterOptions);
default = {}; default = null;
description = '' description = ''
Specify the mailexporter configuration file to use. Specify the mailexporter configuration file to use.
''; '';
@ -147,8 +147,9 @@ in
ExecStart = '' ExecStart = ''
${pkgs.prometheus-mail-exporter}/bin/mailexporter \ ${pkgs.prometheus-mail-exporter}/bin/mailexporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \
--config.file ${ --config.file ${
if cfg.configuration != {} then configurationFile else cfg.configFile if cfg.configuration != null then configurationFile else (escapeShellArg cfg.configFile)
} \ } \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}
''; '';

View File

@ -54,8 +54,8 @@ in
${pkgs.prometheus-minio-exporter}/bin/minio-exporter \ ${pkgs.prometheus-minio-exporter}/bin/minio-exporter \
-web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
-minio.server ${cfg.minioAddress} \ -minio.server ${cfg.minioAddress} \
-minio.access-key ${cfg.minioAccessKey} \ -minio.access-key ${escapeShellArg cfg.minioAccessKey} \
-minio.access-secret ${cfg.minioAccessSecret} \ -minio.access-secret ${escapeShellArg cfg.minioAccessSecret} \
${optionalString cfg.minioBucketStats "-minio.bucket-stats"} \ ${optionalString cfg.minioBucketStats "-minio.bucket-stats"} \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}
''; '';

View File

@ -50,7 +50,7 @@ in
-u ${cfg.username} \ -u ${cfg.username} \
-t ${cfg.timeout} \ -t ${cfg.timeout} \
-l ${cfg.url} \ -l ${cfg.url} \
-p @${cfg.passwordFile} \ -p ${escapeShellArg "@${cfg.passwordFile}"} \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}
''; '';
}; };

View File

@ -67,15 +67,15 @@ in
${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \ ${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \ --web.telemetry-path ${cfg.telemetryPath} \
--postfix.showq_path ${cfg.showqPath} \ --postfix.showq_path ${escapeShellArg cfg.showqPath} \
${concatStringsSep " \\\n " (cfg.extraFlags ${concatStringsSep " \\\n " (cfg.extraFlags
++ optional cfg.systemd.enable "--systemd.enable" ++ optional cfg.systemd.enable "--systemd.enable"
++ optional cfg.systemd.enable (if cfg.systemd.slice != null ++ optional cfg.systemd.enable (if cfg.systemd.slice != null
then "--systemd.slice ${cfg.systemd.slice}" then "--systemd.slice ${cfg.systemd.slice}"
else "--systemd.unit ${cfg.systemd.unit}") else "--systemd.unit ${cfg.systemd.unit}")
++ optional (cfg.systemd.enable && (cfg.systemd.journalPath != null)) ++ optional (cfg.systemd.enable && (cfg.systemd.journalPath != null))
"--systemd.journal_path ${cfg.systemd.journalPath}" "--systemd.journal_path ${escapeShellArg cfg.systemd.journalPath}"
++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${cfg.logfilePath}")} ++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${escapeShellArg cfg.logfilePath}")}
''; '';
}; };
}; };

View File

@ -19,7 +19,7 @@ in
configuration = mkOption { configuration = mkOption {
type = types.nullOr types.attrs; type = types.nullOr types.attrs;
default = {}; default = null;
description = '' description = ''
Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option. Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option.
''; '';
@ -36,15 +36,15 @@ in
}; };
logFormat = mkOption { logFormat = mkOption {
type = types.str; type = types.enum ["logfmt" "json"];
default = "logger:stderr"; default = "logfmt";
description = '' description = ''
Set the log target and format. Output format of log messages.
''; '';
}; };
logLevel = mkOption { logLevel = mkOption {
type = types.enum ["debug" "info" "warn" "error" "fatal"]; type = types.enum ["debug" "info" "warn" "error"];
default = "info"; default = "info";
description = '' description = ''
Only log messages with the given severity or above. Only log messages with the given severity or above.
@ -54,13 +54,13 @@ in
serviceOpts = let serviceOpts = let
configFile = if cfg.configurationPath != null configFile = if cfg.configurationPath != null
then cfg.configurationPath then cfg.configurationPath
else "${pkgs.writeText "snmp-eporter-conf.yml" (builtins.toJSON cfg.configuration)}"; else "${pkgs.writeText "snmp-exporter-conf.yml" (builtins.toJSON cfg.configuration)}";
in { in {
serviceConfig = { serviceConfig = {
ExecStart = '' ExecStart = ''
${pkgs.prometheus-snmp-exporter.bin}/bin/snmp_exporter \ ${pkgs.prometheus-snmp-exporter.bin}/bin/snmp_exporter \
--config.file=${configFile} \ --config.file=${escapeShellArg configFile} \
--log.format=${cfg.logFormat} \ --log.format=${escapeShellArg cfg.logFormat} \
--log.level=${cfg.logLevel} \ --log.level=${cfg.logLevel} \
--web.listen-address=${cfg.listenAddress}:${toString cfg.port} \ --web.listen-address=${cfg.listenAddress}:${toString cfg.port} \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}

View File

@ -55,8 +55,8 @@ in
${pkgs.prometheus-unifi-exporter}/bin/unifi_exporter \ ${pkgs.prometheus-unifi-exporter}/bin/unifi_exporter \
-telemetry.addr ${cfg.listenAddress}:${toString cfg.port} \ -telemetry.addr ${cfg.listenAddress}:${toString cfg.port} \
-unifi.addr ${cfg.unifiAddress} \ -unifi.addr ${cfg.unifiAddress} \
-unifi.username ${cfg.unifiUsername} \ -unifi.username ${escapeShellArg cfg.unifiUsername} \
-unifi.password ${cfg.unifiPassword} \ -unifi.password ${escapeShellArg cfg.unifiPassword} \
-unifi.timeout ${cfg.unifiTimeout} \ -unifi.timeout ${cfg.unifiTimeout} \
${optionalString cfg.unifiInsecure "-unifi.insecure" } \ ${optionalString cfg.unifiInsecure "-unifi.insecure" } \
${concatStringsSep " \\\n " cfg.extraFlags} ${concatStringsSep " \\\n " cfg.extraFlags}

View File

@ -74,10 +74,10 @@ in
${pkgs.prometheus-varnish-exporter}/bin/prometheus_varnish_exporter \ ${pkgs.prometheus-varnish-exporter}/bin/prometheus_varnish_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \ --web.telemetry-path ${cfg.telemetryPath} \
--varnishstat-path ${cfg.varnishStatPath} \ --varnishstat-path ${escapeShellArg cfg.varnishStatPath} \
${concatStringsSep " \\\n " (cfg.extraFlags ${concatStringsSep " \\\n " (cfg.extraFlags
++ optional (cfg.healthPath != null) "--web.health-path ${cfg.healthPath}" ++ optional (cfg.healthPath != null) "--web.health-path ${cfg.healthPath}"
++ optional (cfg.instance != null) "-n ${cfg.instance}" ++ optional (cfg.instance != null) "-n ${escapeShellArg cfg.instance}"
++ optional cfg.noExit "--no-exit" ++ optional cfg.noExit "--no-exit"
++ optional cfg.withGoMetrics "--with-go-metrics" ++ optional cfg.withGoMetrics "--with-go-metrics"
++ optional cfg.verbose "--verbose" ++ optional cfg.verbose "--verbose"

View File

@ -59,7 +59,7 @@ in {
${optionalString cfg.verbose "-v"} \ ${optionalString cfg.verbose "-v"} \
${optionalString cfg.singleSubnetPerField "-s"} \ ${optionalString cfg.singleSubnetPerField "-s"} \
${optionalString cfg.withRemoteIp "-r"} \ ${optionalString cfg.withRemoteIp "-r"} \
${optionalString (cfg.wireguardConfig != null) "-n ${cfg.wireguardConfig}"} ${optionalString (cfg.wireguardConfig != null) "-n ${escapeShellArg cfg.wireguardConfig}"}
''; '';
}; };
}; };

View File

@ -224,7 +224,7 @@ let
after = [ "postfix.service" ]; after = [ "postfix.service" ];
requires = [ "postfix.service" ]; requires = [ "postfix.service" ];
preStart = '' preStart = ''
mkdir -p 0600 mail-exporter/new mkdir -p -m 0700 mail-exporter/new
''; '';
serviceConfig = { serviceConfig = {
ProtectHome = true; ProtectHome = true;