My Nix Configuration
1{ config, pkgs, ... }: 2# let 3# cfg = config.mailserver; 4# in 5{ 6 mailserver.monitoring = { 7 enable = true; 8 alertAddress = "pyrox@pyrox.dev"; 9 config = '' 10 set daemon 120 with start delay 60 11 set mailserver 12 localhost 13 set alert ${config.mailserver.monitoring.alertAddress} 14 15 set httpd port 2812 and use address localhost 16 allow localhost 17 allow admin:obwjoawijerfoijsiwfj29jf2f2jd 18 19 check filesystem root with path / 20 if space usage > 80% then alert 21 if inode usage > 80% then alert 22 23 check system $HOST 24 if cpu usage > 95% for 10 cycles then alert 25 if memory usage > 75% for 5 cycles then alert 26 if swap usage > 20% for 10 cycles then alert 27 if loadavg (1min) > 90 for 15 cycles then alert 28 if loadavg (5min) > 80 for 10 cycles then alert 29 if loadavg (15min) > 70 for 8 cycles then alert 30 31 check process postfix with pidfile /var/lib/postfix/queue/pid/master.pid 32 start program = "${pkgs.systemd}/bin/systemctl start postfix" 33 stop program = "${pkgs.systemd}/bin/systemctl stop postfix" 34 if failed port 25 protocol smtp for 5 cycles then restart 35 36 check process dovecot with pidfile /var/run/dovecot2/master.pid 37 start program = "${pkgs.systemd}/bin/systemctl start dovecot2" 38 stop program = "${pkgs.systemd}/bin/systemctl stop dovecot2" 39 if failed host ${config.mailserver.fqdn} port 993 type tcpssl sslauto protocol imap for 5 cycles then restart 40 41 check process rspamd with matching "rspamd: main process" 42 start program = "${pkgs.systemd}/bin/systemctl start rspamd" 43 stop program = "${pkgs.systemd}/bin/systemctl stop rspamd" 44 ''; 45 }; 46}