1{
2 config,
3 pkgs,
4 ...
5}: let
6 # idk how to share this across files :(
7 mkNotify = {
8 message,
9 channel,
10 priority ? 1,
11 }: ''
12 LOGIN=$(cat "${config.age.secrets.ntfyAuto.path}")
13 ${pkgs.curl}/bin/curl -u $LOGIN \
14 -H "X-Priority: ${toString priority}" \
15 -d '${message}' \
16 https://${config.mySnippets.aylac-top.networkMap.ntfy.vHost}/${channel}
17 '';
18in {
19 systemd.services.disk-space-check = {
20 description = "Check for low disk space";
21 script = ''
22 #!${pkgs.bash}/bin/bash
23 THRESHOLD=80
24 USAGE=$(df --output=pcent / | tail -n 1 | tr -d ' %')
25 if [ "$USAGE" -gt "$THRESHOLD" ]; then
26 ${mkNotify {
27 message = "CRITICAL: Disk space on / is at $USAGE% on ${config.networking.hostName}";
28 channel = "network-status";
29 priority = 5;
30 }}
31 fi
32 '';
33 };
34
35 systemd.timers.disk-space-check = {
36 description = "Run disk space check every hour";
37 wantedBy = ["timers.target"];
38 timerConfig = {
39 OnCalendar = "hourly";
40 Persistent = true;
41 };
42 };
43}