48 lines
1.7 KiB
Bash
48 lines
1.7 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
### I lost the link where I copied this script from, sorry, i'll update as soon as I find it back! The btrfs raid1 check part is written by tech_at_hangar.org
|
||
|
|
||
|
## The first part of this script checks for given minimum space on a mounted volume, and contacts ntfy in case the limit is surpassed.
|
||
|
## The second part of this script checks for missing disks on btrfs raid1 devices and contacs ntfy in case of missing devices
|
||
|
|
||
|
# root volume
|
||
|
mingigs=10
|
||
|
avail=$(df | awk '$6 == "/" && $4 < '$mingigs' * 1024*1024 { print $4/1024/1024 }')
|
||
|
topicurl=https://NTFY_SERVER_IP/disk_alerts
|
||
|
|
||
|
if [ -n "$avail" ]; then
|
||
|
curl -k --retry 3 \
|
||
|
-d "Only $avail GB available on the root disk. Better clean that up." \
|
||
|
-H "Title: Low disk space alert on $(hostname)" \
|
||
|
-H "Priority: default" \
|
||
|
-H "Tags: warning,cd" \
|
||
|
$topicurl
|
||
|
fi
|
||
|
|
||
|
# OTHER VOLUME NAME
|
||
|
mingigs=500
|
||
|
avail=$(df | awk '$6 == "/mnt/OTHER_VOLUME" && $4 < '$mingigs' * 1024*1024 { print $4/1024/1024 }')
|
||
|
topicurl=https://NTFY_SERVER_IP/disk_alerts
|
||
|
|
||
|
if [ -n "$avail" ]; then
|
||
|
curl -k --retry 3 \
|
||
|
-d "Only $avail GB available on the /mnt/OTHER_VOLUME disk. Better clean that up." \
|
||
|
-H "Title: Low disk space alert on $(hostname)" \
|
||
|
-H "Priority: default" \
|
||
|
-H "Tags: warning,cd" \
|
||
|
$topicurl
|
||
|
fi
|
||
|
|
||
|
# check btrfs raid 1 status on /mnt/OTHER_VOLUME NAME
|
||
|
|
||
|
if (btrfs fi show | grep -wic "Some devices missing"); then
|
||
|
echo Bad: - Btrfs is missing devices, some disk is broken
|
||
|
echo Sending alert...
|
||
|
curl -k --retry 3 \
|
||
|
-d "Bad - Some devices are missing in btrfs: maybe a broken disk?" \
|
||
|
-H "Title: Missing disks in btrfs on $(hostname)" \
|
||
|
-H "Priority: high" \
|
||
|
-H "Tags: warning,boar" \
|
||
|
$topicurl
|
||
|
fi
|