1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.exporters.openldap;
7in {
8 port = 9330;
9 extraOpts = {
10 ldapCredentialFile = mkOption {
11 type = types.path;
12 example = "/run/keys/ldap_pass";
13 description = ''
14 Environment file to contain the credentials to authenticate against
15 <package>openldap</package>.
16
17 The file should look like this:
18 <programlisting>
19 ---
20 ldapUser: "cn=monitoring,cn=Monitor"
21 ldapPass: "secret"
22 </programlisting>
23 '';
24 };
25 protocol = mkOption {
26 default = "tcp";
27 example = "udp";
28 type = types.str;
29 description = ''
30 Which protocol to use to connect against <package>openldap</package>.
31 '';
32 };
33 ldapAddr = mkOption {
34 default = "localhost:389";
35 type = types.str;
36 description = ''
37 Address of the <package>openldap</package>-instance.
38 '';
39 };
40 metricsPath = mkOption {
41 default = "/metrics";
42 type = types.str;
43 description = ''
44 URL path where metrics should be exposed.
45 '';
46 };
47 interval = mkOption {
48 default = "30s";
49 type = types.str;
50 example = "1m";
51 description = ''
52 Scrape interval of the exporter.
53 '';
54 };
55 };
56 serviceOpts.serviceConfig = {
57 ExecStart = ''
58 ${pkgs.prometheus-openldap-exporter}/bin/openldap_exporter \
59 --promAddr ${cfg.listenAddress}:${toString cfg.port} \
60 --metrPath ${cfg.metricsPath} \
61 --ldapNet ${cfg.protocol} \
62 --interval ${cfg.interval} \
63 --config ${cfg.ldapCredentialFile} \
64 ${concatStringsSep " \\\n " cfg.extraFlags}
65 '';
66 };
67}