nixos/telegraf: make sure ping executable is available when trying to ping

We need ping to be in PATH of the service otherwise it can't ping. This commit
adds it, conditional on one of the inputs being a ping task.
This commit is contained in:
Echo Nolan 2024-08-31 15:13:22 -04:00
parent 487972dea2
commit 934a337a13
2 changed files with 9 additions and 1 deletions

View File

@ -61,7 +61,8 @@ in {
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
path = lib.optional (config.services.telegraf.extraConfig.inputs ? procstat) pkgs.procps;
path = lib.optional (config.services.telegraf.extraConfig.inputs ? procstat) pkgs.procps
++ lib.optional (config.services.telegraf.extraConfig.inputs ? ping) pkgs.iputils;
serviceConfig = {
EnvironmentFile = config.services.telegraf.environmentFiles;
ExecStartPre = lib.optional (config.services.telegraf.environmentFiles != [])

View File

@ -19,6 +19,12 @@ import ./make-test-python.nix ({ pkgs, ...} : {
timeout = "5s";
data_format = "influx";
};
inputs.ping = {
urls = ["127.0.0.1"];
count = 4;
interval = "10s";
timeout = 1.0;
};
outputs.file.files = ["/tmp/metrics.out"];
outputs.file.data_format = "influx";
};
@ -29,5 +35,6 @@ import ./make-test-python.nix ({ pkgs, ...} : {
machine.wait_for_unit("telegraf.service")
machine.wait_until_succeeds("grep -q example /tmp/metrics.out")
machine.wait_until_succeeds("grep -q ping /tmp/metrics.out")
'';
})