1{ config, lib, pkgs, options }:
2
3with lib;
4let
5 cfg = config.services.prometheus.exporters.idrac;
6
7 configFile = if cfg.configurationPath != null
8 then cfg.configurationPath
9 else pkgs.writeText "idrac.yml" (builtins.toJSON cfg.configuration);
10in
11{
12 port = 9348;
13 extraOpts = {
14 configurationPath = mkOption {
15 type = with types; nullOr path;
16 default = null;
17 example = "/etc/prometheus-idrac-exporter/idrac.yml";
18 description = lib.mdDoc ''
19 Path to the service's config file. This path can either be a computed path in /nix/store or a path in the local filesystem.
20
21 The config file should NOT be stored in /nix/store as it will contain passwords and/or keys in plain text.
22
23 Mutually exclusive with `configuration` option.
24
25 Configuration reference: https://github.com/mrlhansen/idrac_exporter/#configuration
26 '';
27 };
28 configuration = mkOption {
29 type = types.nullOr types.attrs;
30 description = lib.mdDoc ''
31 Configuration for iDRAC exporter, as a nix attribute set.
32
33 Configuration reference: https://github.com/mrlhansen/idrac_exporter/#configuration
34
35 Mutually exclusive with `configurationPath` option.
36 '';
37 default = null;
38 example = {
39 timeout = 10;
40 retries = 1;
41 hosts = {
42 default = {
43 username = "username";
44 password = "password";
45 };
46 };
47 metrics = {
48 system = true;
49 sensors = true;
50 power = true;
51 sel = true;
52 storage = true;
53 memory = true;
54 };
55 };
56 };
57 };
58
59 serviceOpts = {
60 serviceConfig = {
61 LoadCredential = "configFile:${configFile}";
62 ExecStart = "${pkgs.prometheus-idrac-exporter}/bin/idrac_exporter -config %d/configFile";
63 Environment = [
64 "IDRAC_EXPORTER_LISTEN_ADDRESS=${cfg.listenAddress}"
65 "IDRAC_EXPORTER_LISTEN_PORT=${toString cfg.port}"
66 ];
67 };
68 };
69}