about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/prometheus/exporters/blackbox.nix
blob: ca4366121e1251a7805d6fa6ef52a01ef03699b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{ config, lib, pkgs, options }:

with lib;

let
  cfg = config.services.prometheus.exporters.blackbox;

  checkConfig = file: pkgs.runCommand "checked-blackbox-exporter.conf" {
    preferLocalBuild = true;
    buildInputs = [ pkgs.buildPackages.prometheus-blackbox-exporter ]; } ''
    ln -s ${file} $out
    blackbox_exporter --config.check --config.file $out
  '';
in
{
  port = 9115;
  extraOpts = {
    configFile = mkOption {
      type = types.path;
      description = ''
        Path to configuration file.
      '';
    };
  };
  serviceOpts = {
    serviceConfig = {
      AmbientCapabilities = [ "CAP_NET_RAW" ]; # for ping probes
      ExecStart = ''
        ${pkgs.prometheus-blackbox-exporter}/bin/blackbox_exporter \
          --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
          --config.file ${checkConfig cfg.configFile} \
          ${concatStringsSep " \\\n  " cfg.extraFlags}
      '';
      ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
    };
  };
}