1{ config, lib, pkgs }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.exporters.postfix;
7in
8{
9 port = 9154;
10 extraOpts = {
11 telemetryPath = mkOption {
12 type = types.str;
13 default = "/metrics";
14 description = ''
15 Path under which to expose metrics.
16 '';
17 };
18 logfilePath = mkOption {
19 type = types.path;
20 default = "/var/log/postfix_exporter_input.log";
21 example = "/var/log/mail.log";
22 description = ''
23 Path where Postfix writes log entries.
24 This file will be truncated by this exporter!
25 '';
26 };
27 showqPath = mkOption {
28 type = types.path;
29 default = "/var/spool/postfix/public/showq";
30 example = "/var/lib/postfix/queue/public/showq";
31 description = ''
32 Path where Postfix places it's showq socket.
33 '';
34 };
35 systemd = {
36 enable = mkEnableOption ''
37 reading metrics from the systemd-journal instead of from a logfile
38 '';
39 unit = mkOption {
40 type = types.str;
41 default = "postfix.service";
42 description = ''
43 Name of the postfix systemd unit.
44 '';
45 };
46 slice = mkOption {
47 type = types.nullOr types.str;
48 default = null;
49 description = ''
50 Name of the postfix systemd slice.
51 This overrides the <option>systemd.unit</option>.
52 '';
53 };
54 journalPath = mkOption {
55 type = types.nullOr types.path;
56 default = null;
57 description = ''
58 Path to the systemd journal.
59 '';
60 };
61 };
62 };
63 serviceOpts = {
64 serviceConfig = {
65 ExecStart = ''
66 ${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \
67 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
68 --web.telemetry-path ${cfg.telemetryPath} \
69 --postfix.showq_path ${cfg.showqPath} \
70 ${concatStringsSep " \\\n " (cfg.extraFlags
71 ++ optional cfg.systemd.enable "--systemd.enable"
72 ++ optional cfg.systemd.enable (if cfg.systemd.slice != null
73 then "--systemd.slice ${cfg.systemd.slice}"
74 else "--systemd.unit ${cfg.systemd.unit}")
75 ++ optional (cfg.systemd.enable && (cfg.systemd.journalPath != null))
76 "--systemd.jounal_path ${cfg.systemd.journalPath}"
77 ++ optional (!cfg.systemd.enable) "--postfix.logfile_path ${cfg.logfilePath}")}
78 '';
79 };
80 };
81}